Class: ActiveFedora::ContentModel

Inherits:
Base
  • Object
show all
Defined in:
lib/active_fedora/content_model.rb

Constant Summary collapse

CMODEL_NAMESPACE =
"afmodel"
CMODEL_PID_SUFFIX =
""

Instance Attribute Summary collapse

Attributes included from SemanticNode

#load_from_solr, #relationships_loaded, #subject

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, #adapt_to, #attributes=, create, #create_date, datastream_class_for_name, #fields, #get_values_from_datastream, has_metadata, #id, #init_with, #inner_object, #inspect, #internal_uri, #label, #label=, load_instance_from_solr, #method_missing, method_missing, #modified_date, #new_object=, #new_object?, #new_record?, #owner_id, #owner_id=, #persisted?, #pid, pids_from_uris, #solrize_relationships, #state, #to_key, #to_solr, #to_xml, #update_datastream_attributes, #update_indexed_attributes

Methods included from SemanticNode

#add_relationship, #assert_kind_of, #build_statement, #conforms_to?, #ids_for_outbound, #inbound_relationship_predicates, #inbound_relationships, #load_relationships, #object_relations, #outbound_relationship_predicates, #outbound_relationships, #relationship_predicates, #relationships, #relationships_are_dirty, #relationships_are_dirty=, #relationships_desc, #remove_relationship

Constructor Details

#initialize(attrs = {}) ⇒ ContentModel

Returns a new instance of ContentModel.



9
10
11
12
13
# File 'lib/active_fedora/content_model.rb', line 9

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveFedora::Base

Instance Attribute Details

#namespaceObject

Returns the value of attribute namespace.



7
8
9
# File 'lib/active_fedora/content_model.rb', line 7

def namespace
  @namespace
end

#pid_suffixObject

Returns the value of attribute pid_suffix.



7
8
9
# File 'lib/active_fedora/content_model.rb', line 7

def pid_suffix
  @pid_suffix
end

Class Method Details

.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



48
49
50
# File 'lib/active_fedora/content_model.rb', line 48

def self.default_model(obj)
  ActiveFedora::Base
end

.known_models_for(obj) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/active_fedora/content_model.rb', line 30

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



26
27
28
# File 'lib/active_fedora/content_model.rb', line 26

def self.models_asserted_by(obj)
  obj.relationships(:has_model)
end

.pid_from_ruby_class(klass, attrs = {}) ⇒ Object

Deprecated.

Please use to_class_uri instead



16
17
18
19
# File 'lib/active_fedora/content_model.rb', line 16

def self.pid_from_ruby_class(klass,attrs={})
  ActiveSupport::Deprecation.warn("pid_from_ruby_class is deprecated.  Use klass.to_class_uri instead")
  klass.to_class_uri(attrs)
end

.sanitized_class_name(klass) ⇒ Object

Override this, if you prefer your class names serialized some other way



22
23
24
# File 'lib/active_fedora/content_model.rb', line 22

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.



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 = Model.from_class_uri(uri)
  if rc && rc.superclass == ActiveFedora::Base
    rc
  else
    false
  end
end