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 inherited from Base

#named_datastreams_desc

Attributes included from SemanticNode

#internal_uri, #load_from_solr, #named_relationship_desc, #relationships_are_dirty

Class Method Summary collapse

Instance Method Summary collapse

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, #metadata_streams, #method_missing, #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

included

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.



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

.known_models_for(obj) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/active_fedora/content_model.rb', line 34

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



30
31
32
# File 'lib/active_fedora/content_model.rb', line 30

def self.models_asserted_by(obj)
  Array obj.relationships[:self][:has_model]
end

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/active_fedora/content_model.rb', line 15

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.



64
65
66
67
68
69
70
71
# File 'lib/active_fedora/content_model.rb', line 64

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.



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

def self.uri_to_ruby_class( uri )
  classname = uri.split(':')[-1].titlecase.gsub(' ','')
  
  if class_exists?(classname)
    Kernel.const_get(classname)
  else
    false
  end
end