Module: ActiveHouse::Modeling
- Extended by:
- ActiveSupport::Concern
- Included in:
- Model
- Defined in:
- lib/active_house/modeling.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
89
90
91
92
93
94
95
96
|
# File 'lib/active_house/modeling.rb', line 89
def method_missing(method_name, *args, &block)
name, is_setter = parse_attribute_method_name(method_name)
if attribute_method?(name, is_setter, *args)
is_setter ? set_attribute(name, args.first) : get_attribute(name)
else
super
end
end
|
Instance Method Details
#[](key) ⇒ Object
70
71
72
|
# File 'lib/active_house/modeling.rb', line 70
def [](key)
@_attributes[key.to_sym]
end
|
#[]=(key, value) ⇒ Object
74
75
76
|
# File 'lib/active_house/modeling.rb', line 74
def []=(key, value)
@_attributes[key.to_sym] = value
end
|
#as_json(*_args) ⇒ Object
62
63
64
|
# File 'lib/active_house/modeling.rb', line 62
def as_json(*_args)
to_h
end
|
#assign_attributes(params) ⇒ Object
78
79
80
81
82
|
# File 'lib/active_house/modeling.rb', line 78
def assign_attributes(params)
params.each do |key, val|
public_send("#{key}=", val)
end
end
|
#initialize(params = {}) ⇒ Object
57
58
59
60
|
# File 'lib/active_house/modeling.rb', line 57
def initialize(params = {})
@_attributes = {}
assign_attributes(params) unless params.nil?
end
|
#respond_to_missing?(method_name, *args) ⇒ Boolean
84
85
86
87
|
# File 'lib/active_house/modeling.rb', line 84
def respond_to_missing?(method_name, *args)
name, is_setter = parse_attribute_method_name(method_name)
attribute_method?(name, is_setter, *args)
end
|
#to_h ⇒ Object
66
67
68
|
# File 'lib/active_house/modeling.rb', line 66
def to_h
@_attributes.dup
end
|