Module: ActiveFedora::Attributes

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern, Deprecation
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



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/active_fedora/attributes.rb', line 30

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
    # The attribute is a delegate to a datastream
    array_reader(key)
  end
end

#[]=(key, value) ⇒ Object

Raises:



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

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
    # The attribute is a delegate to a datastream
    array_setter(key, value)
  end
end

#attribute_namesObject



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

def attribute_names
  self.class.attribute_names
end

#attributesObject



26
27
28
# File 'lib/active_fedora/attributes.rb', line 26

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

#local_attributesObject



67
68
69
# File 'lib/active_fedora/attributes.rb', line 67

def local_attributes
  self.class.local_attributes
end

#mark_as_changed(field) ⇒ Object



63
64
65
# File 'lib/active_fedora/attributes.rb', line 63

def mark_as_changed(field)
  send("#{field}_will_change!")
end

#value_has_changed?(field, new_value) ⇒ Boolean

value different from the new_value.

Returns:

  • (Boolean)

    true if there is an reader method and it returns a



59
60
61
# File 'lib/active_fedora/attributes.rb', line 59

def value_has_changed?(field, new_value)
  new_value != array_reader(field)
end