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 / duketerms.rdf.xml
Created April 8, 2015 14:07
duketerms.rdf.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rdf:RDF [
<!ENTITY rdfns 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<!ENTITY rdfsns 'http://www.w3.org/2000/01/rdf-schema#'>
<!ENTITY dcns 'http://purl.org/dc/elements/1.1/'>
<!ENTITY dctermsns 'http://purl.org/dc/terms/'>
<!ENTITY dctypens 'http://purl.org/dc/dcmitype/'>
<!ENTITY dcamns 'http://purl.org/dc/dcam/'>
<!ENTITY skosns 'http://www.w3.org/2004/02/skos/core#'>
]>
@dchandekstark
dchandekstark / roles.rb
Created March 16, 2015 20:57
Roles Vocab
module Ddr
module Vocab
class Roles < RDF::StrictVocabulary("http://repository.lib.duke.edu/vocab/roles/")
term :Role,
label: "Role",
comment: "A role granted to an agent."
# type: "rdfs:Class"
# subClassOf: "http://www.w3.org/ns/auth/acl#Authorization"
class DsCallbackTest < ActiveFedora::Datastream
after_save :do_after_save
after_create :do_after_create
def do_after_save
puts "DS after_save"
end
def do_after_create
puts "DS after_create"
@dchandekstark
dchandekstark / sessions_controller.rb
Last active August 29, 2015 14:15
SessionsController - Devise + Ominauth + Shibboleth
class Users::SessionsController < Devise::SessionsController
def new
store_location_for(:user, request.referrer) # return to previous page after authn
if Ddr::Auth.require_shib_user_authn
# don't want the "sign in or sign up" flash in this case
flash.discard(:alert)
redirect_to user_omniauth_authorize_path(:shibboleth)
else
super
@dchandekstark
dchandekstark / model.rb
Created February 6, 2015 00:26
Validation
class Model
attr_accessor :title
# has-a validator
def validator
@validator ||= ModelValidator.new(self)
end
end
# Represents a validation attempt
class Validation
@dchandekstark
dchandekstark / README.md
Last active August 29, 2015 14:13
Indexing API

ActiveFedora Indexing API

TL;DR: This Gist sketches out an API for providing a means of managing inheritable indexing configurations in ActiveFedora. Primary motivations are (1) to avoid (for most purposes) putting indexing logic in an overriden #to_solr method, and (2) to make it possible to introspect a model's or instance’s indexing.

An earlier version of this idea was kicked around on IRC, and I've refined it significantly since then, mainly to accommodate the current property indexing API (from ActiveTriples). Originally, I just aimed to deal with indexing calculated values (basically model methods, as opposed to attributes or properties which already support indexing), for which one currently has to override #to_solr.

Essentially, I wanted to be able to do this type of thing on a model:

# Stupid example
@dchandekstark
dchandekstark / at_resource.rb
Created December 17, 2014 19:50
ActiveFedore attribute w/multiple: false setting to ActiveTriples::Resource
require "rdf-vocab"
module Ddr
module Metadata
class Identifier < ActiveTriples::Resource
PREMIS = Ddr::Vocab::PREMIS
ARK_RE = /^ark:/
DOI_RE = /^doi:/
require 'forwardable'
module Hydra
module Validations
class EnumerableValidator < ActiveModel::EachValidator
extend Forwardable
def_delegator :@member_validator, :validate_each, :validate_member
def_delegator :@member_validator, :kind
describe "inheritance" do
before do
class PrincipalResource < ActiveTriples::Resource
configure type: RDF::FOAF.Agent
property :name, predicate: RDF::FOAF.name
end
class UserResource < PrincipalResource
configure type: RDF::FOAF.Person
end
class DummyResource < ActiveTriples::Resource
2.1.2 :001 > roles = RoleAssertionsResource.new
=> #<RoleAssertionsResource:0x3fdf099b3110(default)>
2.1.2 :002 > user = UserResource.new.tap {|u| u.name = "bob"}
=> #<UserResource: @name=["bob"]>
2.1.2 :003 > user2 = UserResource.new.tap { |u| u.name = "sally" }
=> #<UserResource: @name=["sally"]>
2.1.2 :004 > roles[:owner] = user
=> #<UserResource: @name=["bob"]>
2.1.2 :005 > roles[:owner]
=> [#<UserResource: @name=["bob"]>]