Skip to content

Instantly share code, notes, and snippets.

View flyingzumwalt's full-sized avatar

Matt Zumwalt flyingzumwalt

View GitHub Profile
describe ... do
...
it "should link back to collections" do
stub_request = stub("request", referer: "http://.../collections")
allow(view).to receive(:request).and_return(stub_request)
render
expect(page).to have_link(...)
end
...
end
@flyingzumwalt
flyingzumwalt / Blacklight Analysis.md
Last active August 29, 2015 14:09
Analysis: What Blacklight does

What Blacklight Does

Receives Queries

  • Translate Request params to a valid request for index (solr) & use index client library (rsolr) to query the index
  • Log search history (per user/session)
  • Keep track of configured query types (ie. search by title), sorting options and how to apply them

Generates Responses

  • Decide which serialization to return
  • Keep track of mappings between (solr documents) and supported serializations, perform those mappings when requested
@flyingzumwalt
flyingzumwalt / api_responses.rb
Last active August 29, 2015 14:21
Spec Matchers for API Responses
# spec/support/matchers/api_responses.rb
#
# RSpec matchers for API default JSON responses.
# Creates a matcher like respond_forbidden or respond_not_found corresponding to each of the Api::V1.default_responses
# Accepts optional overrides to the expected response body.
# @example Override the description expected in the JSON body of a :forbidden response
# expect(response).to respond_forbidden(description:"You can't create for that identity")
::Api::V1.default_responses.each_pair do |response_type,default_response_body|
RSpec::Matchers.define "respond_#{response_type.to_s}".to_sym do |expectation_options|
@flyingzumwalt
flyingzumwalt / Notes.md
Last active August 29, 2015 14:22
hydra-works update errors in sufia
@flyingzumwalt
flyingzumwalt / Proxy Resource Graph
Last active August 29, 2015 14:23
navigating LDP indirect containment relationships in ActiveFedora
<http://127.0.0.1:8983/fedora/rest/dev/df/93/78/f3/df9378f3-480a-4ad8-8ee7-7c3a100ac263> <http://www.iana.org/assignments/link-relations/first> <http://127.0.0.1:8983/fedora/rest/dev/df/93/78/f3/df9378f3-480a-4ad8-8ee7-7c3a100ac263/related_objects/c0a7d413-47a2-4ebf-aa14-3384e8af86bd>;
<http://www.iana.org/assignments/link-relations/last> <http://127.0.0.1:8983/fedora/rest/dev/df/93/78/f3/df9378f3-480a-4ad8-8ee7-7c3a100ac263/related_objects/c0a7d413-47a2-4ebf-aa14-3384e8af86bd> .
<http://127.0.0.1:8983/fedora/rest/dev/df/93/78/f3/df9378f3-480a-4ad8-8ee7-7c3a100ac263/related_objects/c0a7d413-47a2-4ebf-aa14-3384e8af86bd/fcr:export?format=jcr/xml> <http://purl.org/dc/elements/1.1/format> <http://fedora.info/definitions/v4/repository#jcr/xml> .
<http://fedora.info/definitions/v4/repository#jcr/xml> <http://www.w3.org/2000/01/rdf-schema#label> "jcr/xml" .
<http://127.0.0.1:8983/fedora/rest/dev/df/93/78/f3/df9378f3-480a-4ad8-8ee7-7c3a100ac263/related_objects/c0a7d413-47a2-4ebf-aa14-3384e8af86bd> a <http://www
@flyingzumwalt
flyingzumwalt / gist:ce003dafed36489cc6e7
Last active August 29, 2015 14:23
querying rdf graph with BGPs in ruby
container_predicate = ::RDF::URI.new("http://example.com/hasFiles")
options = {type: ::RDF::URI.new("http://example.com/primaryFile") }
# This works but is inefficient
contained_uris = query_node.resource.query(predicate: container_predicate).map { |r| r.object.to_s }
contained_objects = contained_uris.map { |object_uri| klass.find(klass.uri_to_id(object_uri)) }
filtered_objects = contained_objects.select {|o| o.metadata_node.type.include?(options[:type]) }
return filtered_objects.first
# Tried this, but it doesn't work
@flyingzumwalt
flyingzumwalt / directly_contains_one_association.rb
Last active August 29, 2015 14:23
directly_contains_one_association.rb
module ActiveFedora
module Associations
class DirectlyContainsOneAssociation < SingularAssociation #:nodoc:
# Finds objects contained by the container predicate (either the configured has_member_relation or ldp:contains)
# TODO: Refactor this to use solr. Requires indexing ActiveFedora::File objects into solr, including their RDF.type and, if possible, the id of their container
def find_target
query_node = if container_predicate = options[:has_member_relation]
owner
else
@flyingzumwalt
flyingzumwalt / 0 Explanation.md
Last active October 27, 2015 20:06
opsworks with apt

The instances

elasticsearch2
EC2 instance ID: i-03dd74fa
OpsWorks ID: 9ae9aac9-47d4-4dd2-9207-43222ab8ec01

elasticsearch3
EC2 instance ID i-63d27b9a
OpsWorks ID 4eb1e92c-19d9-442e-ae7e-52dd8b0135b7

@flyingzumwalt
flyingzumwalt / Hydra Plugin Conventions.md
Last active December 16, 2015 14:09
Conventions when writing "plugins" for Hydra Apps

Conventions

  • Implement a Rails Engine with engine_name defined
  • Expect host application to use mount if they want to inherit routes

Implement a Rails Engine with engine_name defined

Example:

module Hydra

Callback: ActiveFedora::Base.solrization_logic

Example of usage

class GenericFile
    after_solrize << :index_collection_pids

    def index_collection_pids(solr_doc={})
 collection_pids = self.collections.map {|c| c.pid}