Skip to content

Instantly share code, notes, and snippets.

View dchandekstark's full-sized avatar

David Chandek-Stark dchandekstark

  • Duke University Libraries
  • Durham, North Carolina USA
View GitHub Profile
@dchandekstark
dchandekstark / clean-resource.rb
Created August 3, 2021 14:05
Ruby script to strip out content from OKD resources for helm
#!/usr/bin/env ruby
require 'yaml'
data = YAML.load(STDIN.read)
kind = data['kind']
# status
if kind == 'Route'
<foxml:datastream ID="RELS-EXT" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
<foxml:datastreamVersion ID="RELS-EXT.0" LABEL="Fedora Object-to-Object Relationship Metadata" CREATED="2014-01-27T19:33:31.713Z" MIMETYPE="application/rdf+xml" SIZE="411">
<foxml:contentDigest TYPE="SHA-256" DIGEST="dc9dd47194e9e6796ca727b232d1b597afde15c430b0777c2a4e1defa5f4f3ea"/>
<foxml:xmlContent>
<rdf:RDF xmlns:ns0="http://projecthydra.org/ns/relations#" xmlns:ns1="info:fedora/fedora-system:def/model#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="info:fedora/duke:1556">
<ns0:isGovernedBy rdf:resource="info:fedora/duke:1555"/>
<ns1:hasModel rdf:resource="info:fedora/afmodel:Collection"/>
</rdf:Description>
</rdf:RDF>
scope :in_collection, ->(collection) {
where(Ddr::Index::Fields::IS_MEMBER_OF_COLLECTION => collection.respond_to?(:id) ? collection.id : collection)
}
scope :having_local_id, ->(local_id) {
where(Ddr::Index::Fields::LOCAL_ID => local_id)
}
def self.having_local_id!(local_id)
results = having_local_id(local_id).to_a
if results.size > 1
@dchandekstark
dchandekstark / unconcerned.rb
Last active March 10, 2016 00:59
Unconcerned
ActiveSupport::Concern.module_eval do
WARNINGS = [
"Are you sure you want to this?",
"Come on, now, really?",
"Time to refactor?",
"Read http://blog.coreyhaines.com/2012/12/why-i-dont-use-activesupportconcern.html ?",
"Please don't do this without a good reason.",
"No, chunking your mega-class is not a good reason.",
"What objects are you trying to hide?",
def get_objects_for_solr_field_values(solr_field, values, opts = {})
extra_solr_params = opts.delete(:extra_solr_params) || {}
documents = get_solr_response_for_field_values(solr_field, values, extra_solr_params)[1]
method = opts.delete(:lazy) ? :lazy_reify_solr_results : :reify_solr_results
ActiveFedora::SolrService.send(method, documents, opts)
end
@dchandekstark
dchandekstark / gist:6794732
Last active December 24, 2015 11:59
Proposal: Add backward-compatible API to Hydra rights metadata permissions using a SQL-like grant/revoke syntax

Grant

grant [permission], to: [grantees] -> result

Arguments

permission - Symbol (required) - one of [:discover|:read|:edit]

@dchandekstark
dchandekstark / virtus_model.rb
Created December 17, 2015 18:08
Virtus model example
require "virtus"
# BEFORE
class Filter
attr_accessor :clauses
def initialize(clauses = nil)
@clauses = Array(clauses)
end
end
@dchandekstark
dchandekstark / datastream.rb
Last active December 17, 2015 11:09
Extensions to Rubydora digital object and datastream APIs
ACTIVE = 'A'
INACTIVE = 'I'
DELETED = 'D'
def active?
dsState == ACTIVE
end
def inactive?
dsState == INACTIVE
@dchandekstark
dchandekstark / base_decorator.rb
Created May 15, 2013 17:16
ActiveFedora decorators
ActiveFedora::Base.class_eval do
# method_missing is defined, so adding methods
def auditable?
begin
self.is_a? ActiveFedora::Auditable
rescue
false
end
@dchandekstark
dchandekstark / autoversion.rb
Last active December 8, 2015 19:14
Auto-versioning for ActiveFedora::File
module ActiveFedora
module Autoversion
def self.included(base)
base.class_eval do
after_save :create_version
end
end
end
end