Class: Terrestrial::Record
- Inherits:
-
Object
- Object
- Terrestrial::Record
show all
- Extended by:
- Forwardable
- Defined in:
- lib/terrestrial/record.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(mapping, attributes) ⇒ Record
8
9
10
11
|
# File 'lib/terrestrial/record.rb', line 8
def initialize(mapping, attributes)
@mapping = mapping
@attributes = attributes
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
13
14
15
|
# File 'lib/terrestrial/record.rb', line 13
def attributes
@attributes
end
|
#mapping ⇒ Object
Returns the value of attribute mapping.
13
14
15
|
# File 'lib/terrestrial/record.rb', line 13
def mapping
@mapping
end
|
Instance Method Details
#==(other) ⇒ Object
81
82
83
84
|
# File 'lib/terrestrial/record.rb', line 81
def ==(other)
other.is_a?(self.class) &&
[other.mapping, other.attributes] == [mapping, attributes]
end
|
#deep_clone ⇒ Object
77
78
79
|
# File 'lib/terrestrial/record.rb', line 77
def deep_clone
new_with_attributes(Marshal.load(Marshal.dump(attributes)))
end
|
#empty? ⇒ Boolean
68
69
70
|
# File 'lib/terrestrial/record.rb', line 68
def empty?
updatable_attributes.empty?
end
|
#identity ⇒ Object
44
45
46
|
# File 'lib/terrestrial/record.rb', line 44
def identity
attributes.select { |k,_v| identity_fields.include?(k) }
end
|
#identity_fields ⇒ Object
48
49
50
|
# File 'lib/terrestrial/record.rb', line 48
def identity_fields
mapping.primary_key
end
|
#identity_values ⇒ Object
40
41
42
|
# File 'lib/terrestrial/record.rb', line 40
def identity_values
identity.values
end
|
#if_delete(&block) ⇒ Object
24
25
26
|
# File 'lib/terrestrial/record.rb', line 24
def if_delete(&block)
self
end
|
#if_upsert(&block) ⇒ Object
20
21
22
|
# File 'lib/terrestrial/record.rb', line 20
def if_upsert(&block)
self
end
|
#keys ⇒ Object
36
37
38
|
# File 'lib/terrestrial/record.rb', line 36
def keys
attributes.keys
end
|
#merge(more_attributes) ⇒ Object
52
53
54
|
# File 'lib/terrestrial/record.rb', line 52
def merge(more_attributes)
new_with_attributes(attributes.merge(more_attributes))
end
|
#merge!(more_attributes) ⇒ Object
56
57
58
|
# File 'lib/terrestrial/record.rb', line 56
def merge!(more_attributes)
attributes.merge!(more_attributes)
end
|
#namespace ⇒ Object
16
17
18
|
# File 'lib/terrestrial/record.rb', line 16
def namespace
mapping.namespace
end
|
#reject(&block) ⇒ Object
60
61
62
|
# File 'lib/terrestrial/record.rb', line 60
def reject(&block)
new_with_attributes(updatable_attributes.reject(&block).merge(identity))
end
|
#subset?(other_record) ⇒ Boolean
72
73
74
75
|
# File 'lib/terrestrial/record.rb', line 72
def subset?(other_record)
mapping == other_record.mapping &&
to_set.subset?(other_record.to_set)
end
|
#to_h ⇒ Object
64
65
66
|
# File 'lib/terrestrial/record.rb', line 64
def to_h
attributes.to_h
end
|
#updatable? ⇒ Boolean
28
29
30
|
# File 'lib/terrestrial/record.rb', line 28
def updatable?
updatable_attributes.any?
end
|
#updatable_attributes ⇒ Object
32
33
34
|
# File 'lib/terrestrial/record.rb', line 32
def updatable_attributes
attributes.reject { |k, _v| non_updatable_fields.include?(k) }
end
|