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



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/active_fedora/attributes.rb', line 46

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:



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/active_fedora/attributes.rb', line 58

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



38
39
40
# File 'lib/active_fedora/attributes.rb', line 38

def attribute_names
  self.class.attribute_names
end

#attributesObject



42
43
44
# File 'lib/active_fedora/attributes.rb', line 42

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

#local_attributesObject



71
72
73
# File 'lib/active_fedora/attributes.rb', line 71

def local_attributes
  self.class.local_attributes
end