Class: ActiveFedora::ContentModel

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

Constant Summary

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, #attributes=, connection_for_pid, create, #create_date, datastream_class_for_name, #fields, #get_values_from_datastream, #id, #init_with, #inner_object, #inspect, #internal_uri, #label, #label=, load_instance_from_solr, #method_missing, #modified_date, #new_object=, #new_object?, #new_record?, #owner_id, #owner_id=, #persisted?, #pid, pids_from_uris, #reify, #reify!, shard_index, #solrize_profile, #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

- (ContentModel) initialize(attrs = {})

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

- (Object) namespace

Returns the value of attribute namespace



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

def namespace
  @namespace
end

- (Object) pid_suffix

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

+ (Object) default_model(obj)

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

+ (Object) known_models_for(obj)

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

+ (Object) models_asserted_by(obj)

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

+ (Object) sanitized_class_name(klass)

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

+ (Object) uri_to_model_class(uri)

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