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 inherited from Base
Attributes included from SemanticNode
#internal_uri, #load_from_solr, #named_relationship_desc, #relationships_are_dirty
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_named_datastream, #add_named_file_datastream, #add_relationship, #assert_kind_of, #collection_members_append, #collection_members_remove, #create_datastream, #create_date, create_named_datastream_finders, create_named_datastream_update_methods, #datastream_names, #datastreams, #datastreams_attributes, #datastreams_in_fedora, #datastreams_in_memory, #datastreams_xml, #dc, #delete, deserialize, #errors, #fields, #file_objects, #file_objects_append, #file_streams, #generate_dsid, #get_values_from_datastream, has_datastream, has_metadata, #inner_object, #internal_uri, #is_named_datastream?, #label, #label=, load_instance_from_solr, #logger, #metadata_streams, #modified_date, #named_datastreams, #named_datastreams_attributes, named_datastreams_desc, #named_datastreams_desc_from_class, #named_datastreams_ids, #new_object=, #new_object?, #owner_id, #owner_id=, #pid, pids_from_uris, #refresh, #relationships, #rels_ext, #remove_relationship, #save, #state, #to_param, #to_solr, #to_xml, #update_attributes, #update_datastream_attributes, #update_index, #update_indexed_attributes, #update_named_datastream
Methods included from SemanticNode
#add_named_relationship, #add_relationship, #assert_kind_of, #assert_kind_of_model, #class_from_name, #inbound_named_relationship_predicates, #inbound_relationship_names, #inbound_relationships, included, #is_named_relationship?, #kind_of_model?, #named_inbound_relationships, #named_outbound_relationships, #named_relationship, #named_relationship_predicates, #named_relationship_predicates_from_class, #named_relationship_type, #named_relationships, #named_relationships_desc, #named_relationships_desc_from_class, #named_relationships_from_class, #outbound_named_relationship_predicates, #outbound_relationship_names, #outbound_relationships, #register_named_relationship, #register_named_subject, #register_predicate, #register_subject, #register_triple, #relationship_exists?, #relationship_names, #relationships, #relationships_from_class, #remove_named_relationship, #remove_relationship, #to_rels_ext, #unregister_triple
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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/active_fedora/content_model.rb', line 33 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
29 30 31 |
# File 'lib/active_fedora/content_model.rb', line 29 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 20 21 22 23 24 25 26 27 |
# File 'lib/active_fedora/content_model.rb', line 14 def self.pid_from_ruby_class(klass,attrs={}) sanitized_class_name = klass.name.gsub(/(::)/, '_') unless klass.respond_to? :pid_suffix pid_suffix = attrs.has_key?(:pid_suffix) ? attrs[:pid_suffix] : CMODEL_PID_SUFFIX else pid_suffix = klass.pid_suffix end unless klass.respond_to? :pid_namespace namespace = attrs.has_key?(:namespace) ? attrs[:namespace] : CMODEL_NAMESPACE else namespace = klass.pid_namespace end 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.
63 64 65 66 67 68 69 70 |
# File 'lib/active_fedora/content_model.rb', line 63 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.
51 52 53 54 55 56 57 58 59 |
# File 'lib/active_fedora/content_model.rb', line 51 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 |