Module: Firecord::Record
- Defined in:
- lib/firecord/record.rb,
lib/firecord/record/serializer.rb,
lib/firecord/record/deserializer.rb
Defined Under Namespace
Classes: Deserializer, Serializer
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/firecord/record.rb', line 55
def method_missing(method, *args, &block)
return super unless available_names.include?(method)
return set_value(method, args[0]) if method.to_s.end_with?('=')
get_value(method)
end
|
Class Method Details
.included(model) ⇒ Object
3
4
5
6
|
# File 'lib/firecord/record.rb', line 3
def self.included(model)
model.extend(Model)
super
end
|
Instance Method Details
30
31
32
|
# File 'lib/firecord/record.rb', line 30
def delete
repository.delete(id)
end
|
66
67
68
|
# File 'lib/firecord/record.rb', line 66
def fields
model.fields
end
|
#initialize(params = {}) ⇒ Object
10
11
12
13
14
|
# File 'lib/firecord/record.rb', line 10
def initialize(params = {})
fields.each do |field|
initialize_accessor(field, params)
end
end
|
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/firecord/record.rb', line 34
def inspect
attrs = fields.map { |field|
value = get_value(field.name)
formatted = value.is_a?(String) ? "\"#{value}\"" : value
"#{field.name}=#{formatted || 'nil'}"
}
"#<#{model.name} #{attrs.join(' ')}>"
end
|
#new? ⇒ Boolean
45
46
47
|
# File 'lib/firecord/record.rb', line 45
def new?
persistence_state == :transient
end
|
49
50
51
52
53
|
# File 'lib/firecord/record.rb', line 49
def persist
@persistence_state = :persisted
self
end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
62
63
64
|
# File 'lib/firecord/record.rb', line 62
def respond_to_missing?(method, include_private = false)
available_names.include?(method) || super
end
|
16
17
18
19
20
|
# File 'lib/firecord/record.rb', line 16
def save
return _create if new?
_update
end
|
#update(attributes = {}) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/firecord/record.rb', line 22
def update(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
tap { |record| repository.patch(record) }
end
|