Sha256: 663445e29c73c8e7922d0d4c61f2028f520a98779d634861269c5c05e950d8c0

Contents?: true

Size: 1.67 KB

Versions: 20

Compression:

Stored size: 1.67 KB

Contents

# Stanford SolrHelper is a controller layer mixin. It is in the controller scope: request params, session etc.
# 
# NOTE: Be careful when creating variables here as they may be overriding something that already exists.
# The ActionController docs: http://api.rubyonrails.org/classes/ActionController/Base.html
#
# Override these methods in your own controller for customizations:
# 
# class HomeController < ActionController::Base
#   
#   include Stanford::SolrHelper
#   
#   def solr_search_params
#     super.merge :per_page=>10
#   end
#   
# end
#
require 'active_fedora/version'
module MediaShelf
  module ActiveFedoraHelper

    def retrieve_af_model(class_name, opts={})
      if !class_name.nil?
        klass = Module.const_get(class_name.camelcase)
      else
        klass = nil
      end
      #klass.included_modules.include?(ActiveFedora::Model)  
      if klass.is_a?(Class) && klass.superclass == ActiveFedora::Base
        return klass
      else
        return opts.fetch(:default, false)
      end
      rescue NameError
        return false
    end

    def load_af_instance_from_solr(doc)
      pid = doc[:id] ? doc[:id] : doc[:id.to_s]
      pid ? ActiveFedora::Base.load_instance_from_solr(pid,doc) : nil
    end

    private
  
    def require_solr
      ActiveFedora::SolrService.register(ActiveFedora.solr_config[:url])
    end
    
    #underscores are escaped w/ + signs, which are unescaped by rails to spaces
    def unescape_keys(attrs)
      h=Hash.new
      attrs.each do |k,v|
        h[k.gsub(/ /, '_')]=v

      end
      h
    end
    def escape_keys(attrs)
      h=Hash.new
      attrs.each do |k,v|
        h[k.gsub(/_/, '+')]=v

      end
      h
    end
    
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
hydra-head-3.3.0 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.2.2 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.2.1 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.2.0 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.2.0.pre3 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.2.0.pre2 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.2.0.pre1 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.1.5 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.1.4 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.1.3 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.1.2 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.1.1 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.1.0 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.1.0.rc2 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.1.0.rc1 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.1.0.pre5 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.1.0.pre4 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.1.0.pre3 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.1.0.pre2 lib/mediashelf/active_fedora_helper.rb
hydra-head-3.1.0.pre1 lib/mediashelf/active_fedora_helper.rb