Module: OrientDB::AR::Attributes

Defined in:
lib/orientdb-ar/attributes.rb

Instance Method Summary collapse

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_namesObject



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

#attributesObject



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

#changedObject



36
37
38
# File 'lib/orientdb-ar/attributes.rb', line 36

def changed
  changed_attributes.keys
end

#changed?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/orientdb-ar/attributes.rb', line 32

def changed?
  !changed_attributes.empty?
end

#changed_attributesObject



48
49
50
# File 'lib/orientdb-ar/attributes.rb', line 48

def changed_attributes
  @changed_attributes ||= HashWithIndifferentAccess.new
end

#changesObject



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_changesObject



44
45
46
# File 'lib/orientdb-ar/attributes.rb', line 44

def previous_changes
  @previously_changed
end

#to_orientdbObject



16
17
18
# File 'lib/orientdb-ar/attributes.rb', line 16

def to_orientdb
  @odocument
end