Skip to content

Instantly share code, notes, and snippets.

View jeremyf's full-sized avatar

Jeremy Friesen jeremyf

View GitHub Profile
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/hydramata/institution/engine', __FILE__)
require 'rails/all'
require 'rails/engine/commands'
@jeremyf
jeremyf / gist:8957350
Created February 12, 2014 15:16
Group Membership spit-balling
class GroupMembershipForm
include Virtus.model
include ActiveModel::Validations
extend ActiveModel::Naming
attributes :group_id, String
attributes :members, Array[MembershipRole]
validates :group_id, presence: true
def save
@jeremyf
jeremyf / gist:8959710
Created February 12, 2014 16:59
Thinking about how to model connecting a Group to a User
class Hydramata::Connection
include Virtus.model
include ActiveModel::Validations
extend ActiveModel::Naming
attribute :current_user, User
attribute :group_id, String
attribute :user_id, String
attribute :role, Sting
@jeremyf
jeremyf / group_membership_spec.rb
Created February 18, 2014 16:08
A set of specs for defining how the amend group membership form will behave
describe GroupMembershipForm do
let(:group) { Group.new }
let(:group_id) { 'abc:123'}
let(:person) { Person.new }
let(:member_id) { 'abc:456'}
let(:params) {
{
# These are the parameters that are generated in the existing form.
"group_id" => group_id
@jeremyf
jeremyf / soft_delete.rb
Created February 18, 2014 16:18
Possible solution to Soft Delete in Rubydora 1.7.x
require 'rubydora/repository'
require 'rubydora/rest_api_client'
require 'active_fedora/digital_object'
require 'active_fedora/base'
module Rubydora
class PerformedSoftDelete < RuntimeError
attr_reader :options
def initialize(method_name, pid, options)
Feature: Do not create profile pages for new contributors when works are submitted
# https://jira.duraspace.org/browse/HYDRASIR-275
Scenario Outline: Associate with contributor to a person
Given I am an authenticated user
And I am on the <action_name> work page
When I fill out the type ahead search for a contributor
And select a person
And submit a valid form
@jeremyf
jeremyf / gist:10743933
Created April 15, 2014 16:01
Work around
def datastream_to_show
super
rescue Exception => e
if params[:datastream_id] == 'thumbnail'
redirect_to 'path/to/default thumbnail'
return false
else
raise e
end
end
@jeremyf
jeremyf / spec_support.rb
Created April 25, 2014 17:20
Spitballing some spec_support for mixed in behaviors
# a-gem/lib/hydra_permlink/spec_support.rb
require 'rspec'
shared_examples 'a permalinked object' do |options|
let(:model) { described_class.new }
included_services = options.fetch(:services)
if included_services.include?(:doi)
it 'should permalink to a DOI'
end
@jeremyf
jeremyf / gist:c5fb5d9367a568b2b4b1
Created May 15, 2014 15:09
Spitballing an adjustment to UC's virus detection
class CurationConcern::GenericWorksController < CurationConcern::BaseController
before_filter :rip_out_viral_files, only: [:create, :update]
def rip_out_viral_files
files = attributes_for_actor(:files)
good_files = []
viral_files = []
files.each do |file|
if viral?(file)
viral_files << file
@jeremyf
jeremyf / columns_to_markdown
Created August 27, 2014 23:22
Apply pretty padding to markdown table
#!/usr/bin/env ruby -wU
content = `pbpaste`.strip
def columnize(line)
line.sub(/\A\|(.*)\|\s*\Z/, '\1').split("|")
end
lines = content.split("\n")
column_count = columnize(lines.first).size