Module: ActiveFedora::Attributes

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern
Includes:
ActiveModel::Dirty, ActiveModel::ForbiddenAttributesProtection
Included in:
Base
Defined in:
lib/active_fedora.rb,
lib/active_fedora/attributes.rb,
lib/active_fedora/attributes/node_config.rb,
lib/active_fedora/attributes/primary_key.rb,
lib/active_fedora/attributes/serializers.rb,
lib/active_fedora/attributes/property_builder.rb

Defined Under Namespace

Modules: ClassMethods, PrimaryKey, Serializers Classes: NodeConfig, PropertyBuilder

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/active_fedora/attributes.rb', line 27

def [](key)
  if assoc = association(key.to_sym)
    # This is for id attributes stored in the rdf graph.
    assoc.reader
  elsif self.class.properties.key?(key.to_s) || self.class.attributes_with_defaults.include?(key.to_s)
    # Use the generated method so that single value assetions are single
    send(key)
  else
    raise ArgumentError, "Unknown attribute #{key}"
  end
end

#[]=(key, value) ⇒ Object

Raises:



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/active_fedora/attributes.rb', line 39

def []=(key, value)
  raise ReadOnlyRecord if readonly?
  if assoc = association(key.to_sym)
    # This is for id attributes stored in the rdf graph.
    assoc.replace(value)
  elsif self.class.properties.key?(key.to_s)
    # The attribute is stored in the RDF graph for this object
    send(key.to_s + "=", value)
  else
    raise ArgumentError, "Unknown attribute #{key}"
  end
end

#attribute_namesObject



19
20
21
# File 'lib/active_fedora/attributes.rb', line 19

def attribute_names
  self.class.attribute_names
end

#attributesObject



23
24
25
# File 'lib/active_fedora/attributes.rb', line 23

def attributes
  attribute_names.each_with_object("id" => id) { |key, hash| hash[key] = self[key] }
end

#local_attributesObject



52
53
54
# File 'lib/active_fedora/attributes.rb', line 52

def local_attributes
  self.class.local_attributes
end