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
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/active_fedora/attributes.rb', line 43
def [](key)
if assoc = association(key.to_sym)
assoc.reader
elsif self.class.properties.key?(key.to_s) || self.class.attributes_with_defaults.include?(key.to_s)
send(key)
else
array_reader(key)
end
end
|
#[]=(key, value) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/active_fedora/attributes.rb', line 56
def []=(key, value)
raise ReadOnlyRecord if readonly?
if assoc = association(key.to_sym)
assoc.replace(value)
elsif self.class.properties.key?(key.to_s)
send(key.to_s + "=", value)
else
array_setter(key, value)
end
end
|
#attribute_names ⇒ Object
28
29
30
|
# File 'lib/active_fedora/attributes.rb', line 28
def attribute_names
self.class.attribute_names
end
|
#attributes ⇒ Object
32
33
34
|
# File 'lib/active_fedora/attributes.rb', line 32
def attributes
attribute_names.each_with_object("id" => id) { |key, hash| hash[key] = self[key] }
end
|
#attributes=(properties) ⇒ Object
22
23
24
25
26
|
# File 'lib/active_fedora/attributes.rb', line 22
def attributes=(properties)
sanitize_for_mass_assignment(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 datastream loads, but it’s mainly for debugging, so no worries.
37
38
39
40
41
|
# File 'lib/active_fedora/attributes.rb', line 37
def inspect
values = ["id: #{id.inspect}"]
values << self.class.attribute_names.map { |attr| "#{attr}: #{self[attr].inspect}" }
"#<#{self.class} #{values.flatten.join(', ')}>"
end
|
#local_attributes ⇒ Object
80
81
82
|
# File 'lib/active_fedora/attributes.rb', line 80
def local_attributes
self.class.local_attributes
end
|
#mark_as_changed(field) ⇒ Object
76
77
78
|
# File 'lib/active_fedora/attributes.rb', line 76
def mark_as_changed(field)
send("#{field}_will_change!")
end
|
#value_has_changed?(field, new_value) ⇒ Boolean
value different from the new_value.
72
73
74
|
# File 'lib/active_fedora/attributes.rb', line 72
def value_has_changed?(field, new_value)
new_value != array_reader(field)
end
|