Skip to content

Instantly share code, notes, and snippets.

View rails
#!/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 / gist:8957350
Created Feb 12, 2014
Group Membership spit-balling
View gist:8957350
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 / gist:8959710
Created Feb 12, 2014
Thinking about how to model connecting a Group to a User
View gist:8959710
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 / group_membership_spec.rb
Created Feb 18, 2014
A set of specs for defining how the amend group membership form will behave
View group_membership_spec.rb
describe GroupMembershipForm do
let(:group) { }
let(:group_id) { 'abc:123'}
let(:person) { }
let(:member_id) { 'abc:456'}
let(:params) {
# These are the parameters that are generated in the existing form.
"group_id" => group_id
jeremyf / soft_delete.rb
Created Feb 18, 2014
Possible solution to Soft Delete in Rubydora 1.7.x
View soft_delete.rb
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)
View HYDRASIR-275.feature
Feature: Do not create profile pages for new contributors when works are submitted
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
View gist:10743933
def datastream_to_show
rescue Exception => e
if params[:datastream_id] == 'thumbnail'
redirect_to 'path/to/default thumbnail'
return false
raise e
jeremyf / spec_support.rb
Created Apr 25, 2014
Spitballing some spec_support for mixed in behaviors
View spec_support.rb
# a-gem/lib/hydra_permlink/spec_support.rb
require 'rspec'
shared_examples 'a permalinked object' do |options|
let(:model) { }
included_services = options.fetch(:services)
if included_services.include?(:doi)
it 'should permalink to a DOI'
jeremyf / gist:c5fb5d9367a568b2b4b1
Created May 15, 2014
Spitballing an adjustment to UC's virus detection
View gist:c5fb5d9367a568b2b4b1
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 / columns_to_markdown
Created Aug 27, 2014
Apply pretty padding to markdown table
View columns_to_markdown
#!/usr/bin/env ruby -wU
content = `pbpaste`.strip
def columnize(line)
line.sub(/\A\|(.*)\|\s*\Z/, '\1').split("|")
lines = content.split("\n")
column_count = columnize(lines.first).size