Class: EmbeddedRecord
Constant Summary
AbstractRecord::CALLBACKS, AbstractRecord::FIELD_CALLBACKS, AbstractRecord::ORDERS
Instance Attribute Summary collapse
#changed, #errors, #stash, #typecast, #values
Instance Method Summary
collapse
#changed?, #clear_key, #destroy, #destroyed?, #eql?, #errors?, #field, #field?, #field_was, #from_json, #get, #get_meta, #get_raw, #hash, #increment!, inherited, #inspect, #inspect_hash, #inspect_value, #method_missing, #new?, #prepare_reload_params, #present?, #reload, #save, #save_without_validation, #search_terms, #set_meta, #to_json, #to_str, #trigger_field_callback, #update, #valid?
Constructor Details
#initialize(embedded_field, parent_record, values = {}, new_record = true) ⇒ EmbeddedRecord
Returns a new instance of EmbeddedRecord.
6
7
8
9
10
|
# File 'lib/yodel/models/core/record/embedded_record.rb', line 6
def initialize(embedded_field, parent_record, values={}, new_record=true)
@embedded_field = embedded_field
@parent_record = parent_record
super(values, new_record)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class AbstractRecord
Instance Attribute Details
#embedded_field ⇒ Object
Returns the value of attribute embedded_field.
4
5
6
|
# File 'lib/yodel/models/core/record/embedded_record.rb', line 4
def embedded_field
@embedded_field
end
|
#parent_record ⇒ Object
Returns the value of attribute parent_record.
4
5
6
|
# File 'lib/yodel/models/core/record/embedded_record.rb', line 4
def parent_record
@parent_record
end
|
Instance Method Details
#changed!(name) ⇒ Object
38
39
40
41
|
# File 'lib/yodel/models/core/record/embedded_record.rb', line 38
def changed!(name)
super
parent_record.changed!(embedded_field.name)
end
|
#default_values ⇒ Object
20
21
22
|
# File 'lib/yodel/models/core/record/embedded_record.rb', line 20
def default_values
super.merge({'_id' => PrimaryKeyFactory.pk})
end
|
#field_sections ⇒ Object
47
48
49
|
# File 'lib/yodel/models/core/record/embedded_record.rb', line 47
def field_sections
@sections ||= {nil => Section.new(nil, fields.values)}
end
|
#fields ⇒ Object
43
44
45
|
# File 'lib/yodel/models/core/record/embedded_record.rb', line 43
def fields
embedded_field.fields
end
|
#id ⇒ Object
12
13
14
|
# File 'lib/yodel/models/core/record/embedded_record.rb', line 12
def id
@values['_id']
end
|
55
56
57
|
# File 'lib/yodel/models/core/record/embedded_record.rb', line 55
def perform_destroy
embedded_field.destroy(self, parent_record)
end
|
59
60
61
62
|
# File 'lib/yodel/models/core/record/embedded_record.rb', line 59
def perform_reload(id)
self
end
|
51
52
53
|
# File 'lib/yodel/models/core/record/embedded_record.rb', line 51
def perform_save
embedded_field.save(self, parent_record)
end
|
#set(name, value) ⇒ Object
28
29
30
31
|
# File 'lib/yodel/models/core/record/embedded_record.rb', line 28
def set(name, value)
super
parent_record.changed!(embedded_field.name)
end
|
#set_id(new_id) ⇒ Object
16
17
18
|
# File 'lib/yodel/models/core/record/embedded_record.rb', line 16
def set_id(new_id)
@values['_id'] = new_id
end
|
#set_raw(name, value) ⇒ Object
33
34
35
36
|
# File 'lib/yodel/models/core/record/embedded_record.rb', line 33
def set_raw(name, value)
super
parent_record.changed!(embedded_field.name)
end
|
#site ⇒ Object
24
25
26
|
# File 'lib/yodel/models/core/record/embedded_record.rb', line 24
def site
parent_record.site
end
|