Module: ActiveFedora::FedoraAttributes

Extended by:
ActiveSupport::Concern
Includes:
InheritableAccessors
Included in:
Base
Defined in:
lib/active_fedora/fedora_attributes.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#idObject



32
33
34
35
36
37
38
# File 'lib/active_fedora/fedora_attributes.rb', line 32

def id
  if uri.kind_of?(::RDF::URI) && uri.value.blank?
    nil
  elsif uri.present?
    self.class.uri_to_id(URI.parse(uri))
  end
end

#id=(id) ⇒ Object



40
41
42
43
# File 'lib/active_fedora/fedora_attributes.rb', line 40

def id=(id)
  raise "ID has already been set to #{self.id}" if self.id
  @ldp_source = build_ldp_resource(id.to_s)
end

#pidObject

TODO: Remove after we no longer support #pid.



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

def pid
  Deprecation.warn FedoraAttributes, "#{self.class}#pid is deprecated and will be removed in active-fedora 10.0. Use #{self.class}#id instead."
  id
end

#rdf_labelObject

You can set the URI to use for the rdf_label on ClassMethods.rdf_label, then on the instance, calling rdf_label returns the value of that configured property



70
71
72
# File 'lib/active_fedora/fedora_attributes.rb', line 70

def rdf_label
  resource.rdf_label
end

#resourceObject

The resource is the RdfResource object that stores the graph for the datastream and is the central point for its relationship to other nodes.

set_value, get_value, and property accessors are delegated to this object.



64
65
66
# File 'lib/active_fedora/fedora_attributes.rb', line 64

def resource
  @resource ||= self.class.resource_class.new(@ldp_source.graph.rdf_subject, @ldp_source.graph)
end

#set_value(*args) ⇒ Object

Override ActiveTriples method for setting properties

Raises:



27
28
29
30
# File 'lib/active_fedora/fedora_attributes.rb', line 27

def set_value(*args)
  raise ReadOnlyRecord if readonly?
  resource.set_value(*args)
end

#uriObject



52
53
54
55
56
# File 'lib/active_fedora/fedora_attributes.rb', line 52

def uri
  # TODO could we return a RDF::URI instead?
  uri = @ldp_source.try(:subject_uri)
  uri.value == '' ? uri : uri.to_s
end