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, #adapt_to_cmodel, assign_pid, #clone, #clone_into, connection_for_pid, #create_date, datastream_class_for_name, #id, #init_with, #inner_object, #internal_uri, #label, #mark_for_destruction, #marked_for_destruction?, #method_missing, #modified_date, #new?, #new_object?, #new_record?, #owner_id, #owner_id=, #persisted?, #pid, pids_from_uris, #pretty_pid, #reify, #reify!, #reload, shard_index, #state, #to_key, #to_param

Methods included from SemanticNode

#add_relationship, #assert_kind_of, #clear_relationship, #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.



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

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.



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

def namespace
  @namespace
end

#pid_suffixObject

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

.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



46
47
48
# File 'lib/active_fedora/content_model.rb', line 46

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.



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

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.



53
54
55
56
57
58
59
60
# File 'lib/active_fedora/content_model.rb', line 53

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