Sha256: bae7c1c9f3b0d79d78c08f2b94666a5a15ce33dd3ac8b9ea0f860143cbcc85dd

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

module ScoobySnacks::WorkModelBehavior
  # A model mixin to define metadata 
  # properties and options based on
  # the schema configuration files
  extend ActiveSupport::Concern

  included do

    id_blank = proc { |attributes| attributes[:id].blank? }
    schema = ScoobySnacks::METADATA_SCHEMA
    schema.fields.values.each do |field|
      # Define the property and its indexing
      # unless it is already defined (e.g. in hyrax core)
      unless respond_to? field.name.to_sym
        property field.name.to_sym, {predicate: field.predicate, multiple: field.multiple?}  do |index| 
          index.as *field.solr_descriptors
          index.type field.solr_data_type
        end
      end
    end #end fields loop

    schema.controlled_field_names.each do |field_name|
      accepts_nested_attributes_for field_name.to_sym, reject_if: id_blank, allow_destroy: true
    end

    # used by Hyrax, I think
    # (taken from Hyrax::BasicMetadata)
    # I'm not sure whether/how the scholarsphere stuff is used
    property :label, predicate: ActiveFedora::RDF::Fcrepo::Model.downloadFilename, multiple: false
    property :relative_path, predicate: ::RDF::URI.new('http://scholarsphere.psu.edu/ns#relativePath'), multiple: false
    property :import_url, predicate: ::RDF::URI.new('http://scholarsphere.psu.edu/ns#importUrl'), multiple: false
    
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
scooby_snacks-0.3.8 lib/scooby_snacks/work_model_behavior.rb
scooby_snacks-0.3.7 lib/scooby_snacks/work_model_behavior.rb
scooby_snacks-0.3.6 lib/scooby_snacks/work_model_behavior.rb
scooby_snacks-0.3.5 lib/scooby_snacks/work_model_behavior.rb
scooby_snacks-0.3.4 lib/scooby_snacks/work_model_behavior.rb
scooby_snacks-0.3.3 lib/scooby_snacks/work_model_behavior.rb