Class: ActiveFedora::ContentModel
- Defined in:
- lib/active_fedora/content_model.rb
Constant Summary collapse
- CMODEL_NAMESPACE =
"afmodel"
- CMODEL_PID_SUFFIX =
""
Constants included from SemanticNode
SemanticNode::PREDICATE_MAPPINGS
Instance Attribute Summary collapse
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#pid_suffix ⇒ Object
Returns the value of attribute pid_suffix.
Attributes included from SemanticNode
Attributes included from Model
Class Method Summary collapse
- .known_models_for(obj) ⇒ Object
- .models_asserted_by(obj) ⇒ Object
- .pid_from_ruby_class(klass, attrs = {}) ⇒ Object
-
.uri_to_model_class(uri) ⇒ Object
Returns an ActiveFedora Model class corresponding to the given uri if one can be found.
-
.uri_to_ruby_class(uri) ⇒ Object
Returns a ruby class corresponding to the given uri if one can be found.
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ ContentModel
constructor
A new instance of ContentModel.
Methods inherited from Base
#add, #add_datastream, #add_file_datastream, #add_relationship, #collection_members_append, #collection_members_remove, #create_date, #datastreams, #datastreams_in_fedora, #datastreams_in_memory, #datastreams_xml, #dc, #delete, deserialize, #errors, #fields, #file_objects, #file_objects_append, #file_streams, #generate_dsid, has_metadata, #inner_object, #internal_uri, #label, #label=, #metadata_streams, #modified_date, #new_object=, #new_object?, #owner_id, #owner_id=, #pid, pids_from_uris, #refresh, #relationships, #rels_ext, #save, #state, #to_param, #to_solr, #to_xml, #update_attributes, #update_index, #update_indexed_attributes
Methods included from SolrMapper
Methods included from SemanticNode
#add_relationship, #assert_kind_of, included, #outbound_relationships, #register_predicate, #register_subject, #register_triple, #relationships_from_class, #to_rels_ext
Methods included from MediaShelfClassLevelInheritableAttributes
Methods included from Model
#add_metadata, #create_property_getter, #create_property_setter, #datastream, included
Methods included from FedoraObject
#add_datastream, #datastreams, #datastreams_xml, #dc, #delete, #errors, #inner_object, #owner_id, #pid, #rels_ext, #save, #state
Constructor Details
#initialize(attrs = {}) ⇒ ContentModel
Returns a new instance of ContentModel.
8 9 10 11 12 |
# File 'lib/active_fedora/content_model.rb', line 8 def initialize(attrs={}) @pid_suffix = attrs.has_key?(:pid_suffix) ? attrs[:pid_suffix] : CMODEL_PID_SUFFIX @namespace = attrs.has_key?(:namespace) ? attrs[:namespace] : CMODEL_NAMESPACE super end |
Instance Attribute Details
#namespace ⇒ Object
Returns the value of attribute namespace.
6 7 8 |
# File 'lib/active_fedora/content_model.rb', line 6 def namespace @namespace end |
#pid_suffix ⇒ Object
Returns the value of attribute pid_suffix.
6 7 8 |
# File 'lib/active_fedora/content_model.rb', line 6 def pid_suffix @pid_suffix end |
Class Method Details
.known_models_for(obj) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/active_fedora/content_model.rb', line 25 def self.known_models_for(obj) models_array = [] models_asserted_by( obj ).each do |model_uri| m = uri_to_model_class(model_uri) if m models_array << m end end if models_array.empty? models_array = [ActiveFedora::Base] end return models_array end |
.models_asserted_by(obj) ⇒ Object
21 22 23 |
# File 'lib/active_fedora/content_model.rb', line 21 def self.models_asserted_by(obj) Array obj.relationships[:self][:has_model] end |
.pid_from_ruby_class(klass, attrs = {}) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/active_fedora/content_model.rb', line 14 def self.pid_from_ruby_class(klass,attrs={}) sanitized_class_name = klass.name.gsub(/(::)/, '_') pid_suffix = attrs.has_key?(:pid_suffix) ? attrs[:pid_suffix] : CMODEL_PID_SUFFIX namespace = attrs.has_key?(:namespace) ? attrs[:namespace] : CMODEL_NAMESPACE return "#{namespace}:#{sanitized_class_name}#{pid_suffix}" end |
.uri_to_model_class(uri) ⇒ Object
Returns an ActiveFedora Model class corresponding to the given uri if one can be found. Returns false if no corresponding model can be found.
55 56 57 58 59 60 61 62 |
# File 'lib/active_fedora/content_model.rb', line 55 def self.uri_to_model_class( uri ) rc = uri_to_ruby_class(uri) if rc && rc.superclass == ActiveFedora::Base rc else false end end |
.uri_to_ruby_class(uri) ⇒ Object
Returns a ruby class corresponding to the given uri if one can be found. Returns false if no corresponding class can be found.
43 44 45 46 47 48 49 50 51 |
# File 'lib/active_fedora/content_model.rb', line 43 def self.uri_to_ruby_class( uri ) classname = uri.gsub("info:fedora/afmodel:", "") if class_exists?(classname) Kernel.const_get(classname) else false end end |