Created
April 24, 2009 04:45
-
-
Save mwmitchell/100950 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# part of the BL core lib... | |
module Blacklight | |
module SolrDoc | |
def self.decorators | |
@decorators ||= {} | |
end | |
def self.decorate(name = :default, &blk) | |
decorators[name] = blk | |
end | |
def self.create(hash) | |
decorators.each { |k,d| d.call(hash) } | |
hash | |
end | |
end | |
end | |
################################ | |
# uva specific lib code... | |
module UVA | |
module DocExt | |
# module for handling gis aware docs | |
module GIS | |
end | |
# module for handling marc based docs | |
module Marc | |
# the actual marc object | |
class Base | |
def to_s | |
"MARC!" | |
end | |
end | |
# marc object accessor, memoized | |
def marc | |
@marc ||= ( | |
Base.new | |
) | |
end | |
end | |
# common "flag" methods | |
module Common | |
def marc? | |
key? 'marc_display' | |
end | |
def fedora? | |
key? 'fedora_pid' | |
end | |
def mappable? | |
key? 'lat' and key? 'lon' | |
end | |
end | |
end | |
end | |
# in the initializer etc.. | |
Blacklight::SolrDoc.decorate do |doc| | |
doc.extend UVA::DocExt::Common | |
doc.extend UVA::DocExt::GIS if doc.mappable? | |
doc.extend UVA::DocExt::Marc if doc.marc? | |
end | |
# create some test docs... (the "controller") | |
docs = [] | |
10.times do |i| | |
doc = {'id' => i} | |
# "randomize" a bit... | |
doc['fedora_pid'] = true if (i % 2 != 0) | |
doc['marc_display'] = 'asdf' if i % 3 == 0 | |
docs << Blacklight::SolrDoc.create(doc) | |
end | |
# now go through each doc in the (the "view") | |
docs.each do |doc| | |
# create a doc (decorates the doc) | |
puts 'mappable!' if doc.mappable? | |
puts 'fedora object!' if doc.fedora? | |
puts doc.marc if doc.marc? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment