Module: ActiveFedora::Attributes

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

Defined Under Namespace

Modules: ClassMethods, Serializers

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



35
36
37
# File 'lib/active_fedora/attributes.rb', line 35

def [](key)
  array_reader(key)
end

#[]=(key, value) ⇒ Object



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

def []=(key, value)
  array_setter(key, value)
end

#attributesObject



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

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

#attributes=(properties) ⇒ Object



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

def attributes=(properties)
  properties.each do |k, v|
    respond_to?(:"#{k}=") ? send(:"#{k}=", v) : raise(UnknownAttributeError, "#{self.class} does not have an attribute `#{k}'")
  end
end

#inspectObject

Calling inspect may trigger a bunch of loads, but it’s mainly for debugging, so no worries.



29
30
31
32
33
# File 'lib/active_fedora/attributes.rb', line 29

def inspect
  values = ["pid: #{pretty_pid.inspect}"]
  values << self.class.defined_attributes.keys.map {|r| "#{r}: #{send(r).inspect}"}
  "#<#{self.class} #{values.flatten.join(', ')}>"
end

#mark_as_changed(field) ⇒ Object



49
50
51
# File 'lib/active_fedora/attributes.rb', line 49

def mark_as_changed(field)
  self.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



45
46
47
# File 'lib/active_fedora/attributes.rb', line 45

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