Module: OrientDB::AR::Attributes
- Defined in:
- lib/orientdb-ar/attributes.rb
Instance Method Summary collapse
- #[](attr) ⇒ Object
- #[]=(attr, value) ⇒ Object
- #attribute_names ⇒ Object
- #attributes ⇒ Object
- #changed ⇒ Object
- #changed? ⇒ Boolean
- #changed_attributes ⇒ Object
- #changes ⇒ Object
- #previous_changes ⇒ Object
- #to_orientdb ⇒ Object
Instance Method Details
#[](attr) ⇒ Object
20 21 22 |
# File 'lib/orientdb-ar/attributes.rb', line 20 def [](attr) self.class.from_orientdb @odocument[attr] end |
#[]=(attr, value) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/orientdb-ar/attributes.rb', line 24 def []=(attr, value) value = self.class.to_orientdb value old_value = self[attr] return old_value if value == old_value attribute_will_change!(attr) @odocument[attr] = value end |
#attribute_names ⇒ Object
6 7 8 9 10 |
# File 'lib/orientdb-ar/attributes.rb', line 6 def attribute_names schema_names = self.class.fields.keys.map { |x| x.to_s } field_names = @odocument.field_names.map { |x| x.to_s } (schema_names + field_names).uniq end |
#attributes ⇒ Object
12 13 14 |
# File 'lib/orientdb-ar/attributes.rb', line 12 def attributes attribute_names.inject({}) { |h, attr| h[attr.to_s] = self[attr]; h } end |
#changed ⇒ Object
36 37 38 |
# File 'lib/orientdb-ar/attributes.rb', line 36 def changed changed_attributes.keys end |
#changed? ⇒ Boolean
32 33 34 |
# File 'lib/orientdb-ar/attributes.rb', line 32 def changed? !changed_attributes.empty? end |
#changed_attributes ⇒ Object
48 49 50 |
# File 'lib/orientdb-ar/attributes.rb', line 48 def changed_attributes @changed_attributes ||= HashWithIndifferentAccess.new end |
#changes ⇒ Object
40 41 42 |
# File 'lib/orientdb-ar/attributes.rb', line 40 def changes changed.inject(HashWithIndifferentAccess.new) { |h, attr| h[attr] = attribute_change(attr); h } end |
#previous_changes ⇒ Object
44 45 46 |
# File 'lib/orientdb-ar/attributes.rb', line 44 def previous_changes @previously_changed end |
#to_orientdb ⇒ Object
16 17 18 |
# File 'lib/orientdb-ar/attributes.rb', line 16 def to_orientdb @odocument end |