Class: Houston::Props::PropsIndexer
- Inherits:
-
Object
- Object
- Houston::Props::PropsIndexer
show all
- Defined in:
- app/concerns/houston/props.rb
Instance Method Summary
collapse
Constructor Details
#initialize(record, hash) ⇒ PropsIndexer
Returns a new instance of PropsIndexer.
71
72
73
74
|
# File 'app/concerns/houston/props.rb', line 71
def initialize(record, hash)
@record = record
@hash = hash
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
106
107
108
109
110
111
|
# File 'app/concerns/houston/props.rb', line 106
def method_missing(method_name, *args, &block)
prop_name = method_name.to_s.gsub(/_before_type_cast$/, "")
return self[prop_name] if key?(prop_name)
return nil if Houston::Props.valid_prop_name?(prop_name)
super
end
|
Instance Method Details
#[]=(prop_name, value) ⇒ Object
78
79
80
|
# File 'app/concerns/houston/props.rb', line 78
def []=(prop_name, value)
merge!(prop_name => value)
end
|
#as_json(options = {}) ⇒ Object
95
96
97
|
# File 'app/concerns/houston/props.rb', line 95
def as_json(options={})
to_h
end
|
#delete!(key) ⇒ Object
87
88
89
|
# File 'app/concerns/houston/props.rb', line 87
def delete!(key)
@record.props = @hash = @hash.except(key)
end
|
#merge!(new_props) ⇒ Object
82
83
84
85
|
# File 'app/concerns/houston/props.rb', line 82
def merge!(new_props)
new_props.each_key(&Houston::Props.method(:valid_prop_name!))
@record.props = @hash = @hash.merge(new_props)
end
|
#respond_to_missing?(method_name, *args) ⇒ Boolean
99
100
101
102
103
104
|
# File 'app/concerns/houston/props.rb', line 99
def respond_to_missing?(method_name, *args)
prop_name = method_name.to_s.gsub(/_before_type_cast$/, "")
return true if key?(prop_name)
return true if Houston::Props.valid_prop_name?(prop_name)
super
end
|
#to_h ⇒ Object
91
92
93
|
# File 'app/concerns/houston/props.rb', line 91
def to_h
@hash.dup
end
|