Class: ActiveFedora::ContentModel
- Defined in:
- lib/active_fedora/content_model.rb
Constant Summary collapse
- CMODEL_NAMESPACE =
"afmodel"
- CMODEL_PID_SUFFIX =
""
Constants included from AutosaveAssociation
AutosaveAssociation::ASSOCIATION_TYPES
Constants included from Callbacks
ActiveFedora::Callbacks::CALLBACKS
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 ReloadOnSave
Attributes included from Core
Attributes included from Associations
Attributes included from SemanticNode
#load_from_solr, #relationships_loaded, #subject
Class Method Summary collapse
- .best_model_for(obj) ⇒ Object
-
.default_model(obj) ⇒ Object
Returns a ruby class to use if no other class could be find to instantiate Override this method if you need something other than the default strategy.
-
.known_models_for(obj) ⇒ Object
returns an array of the model classes that are defined in the current application that the given object asserts (ie. if the object asserts a StreamingVideo model but the application doesn’t define a StreamingVideo model, it will be excluded from this list..
-
.models_asserted_by(obj) ⇒ Object
list all of the models asserted by the provided object.
-
.sanitized_class_name(klass) ⇒ Object
Override this, if you prefer your class names serialized some other way.
-
.uri_to_model_class(uri) ⇒ Object
Returns an ActiveFedora Model 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 included from Querying
#default_sort_params, extended, #quote_for_solr
Methods included from Rdf::Identifiable
Methods included from ReloadOnSave
Methods included from FedoraAttributes
#create_date, #id, #label, #modified_date, #owner_id, #owner_id=, #pid, #state
Methods included from Core
#==, #adapt_to, #adapt_to_cmodel, #clone, #clone_into, #freeze, #frozen?, #init_with, #pretty_pid, #reify, #reify!, #reload
Methods included from Serialization
Methods included from Attributes
#[], #[]=, #attributes, #attributes=, #inspect, #mark_as_changed, #value_has_changed?
Methods included from NestedAttributes
Methods included from AutosaveAssociation
#changed_for_autosave?, #mark_for_destruction, #marked_for_destruction?, #reload
Methods included from Associations
#association, #clear_association_cache
Methods included from Datastreams
#add_datastream, #add_disseminator_location_to_datastreams, #add_file_datastream, #configure_datastream, #create_datastream, #datastream_from_spec, #datastreams, #ds_specs, #load_datastreams, #metadata_streams, #rels_ext, #serialize_datastreams
Methods included from Callbacks
Methods included from Validations
#required?, #save, #save!, #valid?
Methods included from Indexing
#solr_name, #solrize_profile, #solrize_relationships, #to_solr, #update_index
Methods included from Persistence
#assert_content_model, #delete, #destroy, #destroyed?, #new?, #new_object?, #new_record?, #persisted?, #refresh, #save, #save!, #update
Methods included from SemanticNode
#add_relationship, #assert_kind_of, #clear_relationship, #clear_relationships, #conforms_to?, #ids_for_outbound, #internal_uri, #load_relationships, #object_relations, #relationships, #relationships=, #relationships_are_dirty?, #relationships_are_not_dirty!, #remove_relationship
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
.best_model_for(obj) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/active_fedora/content_model.rb', line 24 def self.best_model_for(obj) best_model_match = obj.class unless obj.instance_of? ActiveFedora::Base known_models_for(obj).each do |model_value| # If this is of type ActiveFedora::Base, then set to the first found :has_model. best_model_match ||= model_value # If there is an inheritance structure, use the most specific case. if best_model_match > model_value best_model_match = model_value end end best_model_match end |
.default_model(obj) ⇒ Object
Returns a ruby class to use if no other class could be find to instantiate Override this method if you need something other than the default strategy
62 63 64 |
# File 'lib/active_fedora/content_model.rb', line 62 def self.default_model(obj) ActiveFedora::Base end |
.known_models_for(obj) ⇒ Object
returns an array of the model classes that are defined in the current application that the given object asserts (ie. if the object asserts a StreamingVideo model but the application doesn’t define a StreamingVideo model, it will be excluded from this list.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/active_fedora/content_model.rb', line 44 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 = [default_model(obj)] end return models_array end |
.models_asserted_by(obj) ⇒ Object
list all of the models asserted by the provided object
20 21 22 |
# File 'lib/active_fedora/content_model.rb', line 20 def self.models_asserted_by(obj) obj.relationships(:has_model) end |
.sanitized_class_name(klass) ⇒ Object
Override this, if you prefer your class names serialized some other way
15 16 17 |
# File 'lib/active_fedora/content_model.rb', line 15 def self.sanitized_class_name(klass) klass.name.gsub(/(::)/, '_') 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.
69 70 71 72 73 74 75 76 |
# File 'lib/active_fedora/content_model.rb', line 69 def self.uri_to_model_class( uri ) rc = Model.from_class_uri(uri) if rc && (rc.superclass == ActiveFedora::Base || rc.ancestors.include?(ActiveFedora::Base)) rc else false end end |