Module: ActiveFedora::Attributes
- Extended by:
- ActiveSupport::Autoload, ActiveSupport::Concern, Deprecation
- 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
36
37
38
|
# File 'lib/active_fedora/attributes.rb', line 36
def [](key)
array_reader(key)
end
|
#[]=(key, value) ⇒ Object
40
41
42
|
# File 'lib/active_fedora/attributes.rb', line 40
def []=(key, value)
array_setter(key, value)
end
|
#attributes ⇒ Object
25
26
27
|
# File 'lib/active_fedora/attributes.rb', line 25
def attributes
self.class.defined_attributes.keys.each_with_object({"id" => id}) {|key, hash| hash[key] = self[key]}
end
|
#attributes=(properties) ⇒ Object
19
20
21
22
23
|
# File 'lib/active_fedora/attributes.rb', line 19
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
|
#inspect ⇒ Object
Calling inspect may trigger a bunch of loads, but it’s mainly for debugging, so no worries.
30
31
32
33
34
|
# File 'lib/active_fedora/attributes.rb', line 30
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
50
51
52
|
# File 'lib/active_fedora/attributes.rb', line 50
def mark_as_changed(field)
self.send("#{field}_will_change!")
end
|
#value_has_changed?(field, new_value) ⇒ Boolean
value different from the new_value.
46
47
48
|
# File 'lib/active_fedora/attributes.rb', line 46
def value_has_changed?(field, new_value)
new_value != array_reader(field)
end
|