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 = " def \#{name}=(value)\n attributes[:\#{attribute}] = value \n end\n end_src\n class_eval src, __FILE__, __LINE__\n when \"?\"\n src = <<-end_src\n def \#{name}?\n !!attributes[:\#{attribute}] \n end\n end_src\n class_eval src, __FILE__, __LINE__\n else\n src = <<-end_src\n def \#{name}\n attributes[:\#{attribute}]\n end\n end_src\n class_eval src, __FILE__, __LINE__\n end\n return self.send(method, *args)\n end\n end\n super\nend\n"
|
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
|