Module: ActiveHouse::Modeling::Attributes
- Extended by:
- ActiveSupport::Concern
- Included in:
- ActiveHouse::Model
- Defined in:
- lib/active_house/modeling/attributes.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
92
93
94
95
96
97
98
99
|
# File 'lib/active_house/modeling/attributes.rb', line 92
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
73
74
75
|
# File 'lib/active_house/modeling/attributes.rb', line 73
def [](key)
get_attribute(key.to_sym)
end
|
#[]=(key, value) ⇒ Object
77
78
79
|
# File 'lib/active_house/modeling/attributes.rb', line 77
def []=(key, value)
set_attribute(key.to_sym, value)
end
|
#as_json(*_args) ⇒ Object
65
66
67
|
# File 'lib/active_house/modeling/attributes.rb', line 65
def as_json(*_args)
to_h
end
|
#assign_attributes(params) ⇒ Object
81
82
83
84
85
|
# File 'lib/active_house/modeling/attributes.rb', line 81
def assign_attributes(params)
params.each do |key, val|
public_send("#{key}=", val)
end
end
|
#initialize(params = {}) ⇒ Object
60
61
62
63
|
# File 'lib/active_house/modeling/attributes.rb', line 60
def initialize(params = {})
@_attributes = {}
assign_attributes(params) unless params.nil?
end
|
#respond_to_missing?(method_name, *args) ⇒ Boolean
87
88
89
90
|
# File 'lib/active_house/modeling/attributes.rb', line 87
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
69
70
71
|
# File 'lib/active_house/modeling/attributes.rb', line 69
def to_h
@_attributes.dup
end
|