Module: OrientDB::AR::Attributes

Included in:
Base, Embedded
Defined in:
lib/model/attributes.rb

Instance Method Summary collapse

Instance Method Details

#[](attr) ⇒ Object



15
16
17
18
# File 'lib/model/attributes.rb', line 15

def [](attr)
  res = @odocument[attr]
  res.respond_to?(:jruby_value) ? res.jruby_value : res
end

#[]=(attr, value) ⇒ Object



20
21
22
23
24
25
# File 'lib/model/attributes.rb', line 20

def []=(attr, 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
# File 'lib/model/attributes.rb', line 6

def attribute_names
  schema_names = self.class.fields.keys.map { |x| x.to_s }
  (schema_names + @odocument.field_names.map).uniq
end

#attributesObject



11
12
13
# File 'lib/model/attributes.rb', line 11

def attributes
  attribute_names.inject({}) { |h, attr| h[attr.to_s] = self[attr]; h }
end

#changedObject



31
32
33
# File 'lib/model/attributes.rb', line 31

def changed
  changed_attributes.keys
end

#changed?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/model/attributes.rb', line 27

def changed?
  !changed_attributes.empty?
end

#changed_attributesObject



43
44
45
# File 'lib/model/attributes.rb', line 43

def changed_attributes
  @changed_attributes ||= HashWithIndifferentAccess.new
end

#changesObject



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

def changes
  changed.inject(HashWithIndifferentAccess.new) { |h, attr| h[attr] = attribute_change(attr); h }
end

#previous_changesObject



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

def previous_changes
  @previously_changed
end