Module: FoundationApi::Model::AttributeMethods
- Extended by:
- ActiveSupport::Concern
- Included in:
- Service, Table::Record
- Defined in:
- lib/foundation_api/model/attribute_methods.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/foundation_api/model/attribute_methods.rb', line 37
def method_missing(method, *args)
if method =~ /([_a-zA-Z]\w*)([=?]*)/
name, call = $1, $2
if attribute = matching_attribute(name)
case call
when "="
src = <<-end_src
def #{name}=(value)
attributes[:#{attribute}] = value
end
end_src
class_eval src, __FILE__, __LINE__
when "?"
src = <<-end_src
def #{name}?
!!attributes[:#{attribute}]
end
end_src
class_eval src, __FILE__, __LINE__
else
src = <<-end_src
def #{name}
attributes[:#{attribute}]
end
end_src
class_eval src, __FILE__, __LINE__
end
return self.send(method, *args)
end
end
super
end
|
Instance Method Details
#[](attribute) ⇒ Object
70
71
72
|
# File 'lib/foundation_api/model/attribute_methods.rb', line 70
def [](attribute)
attributes[map_attribute(attribute)]
end
|
#[]=(attribute, value) ⇒ Object
74
75
76
|
# File 'lib/foundation_api/model/attribute_methods.rb', line 74
def []=(attribute, value)
attributes[map_attribute(attribute)] = value
end
|