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.
72
73
74
75
|
# File 'app/concerns/houston/props.rb', line 72
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
107
108
109
110
111
112
|
# File 'app/concerns/houston/props.rb', line 107
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
79
80
81
|
# File 'app/concerns/houston/props.rb', line 79
def []=(prop_name, value)
merge!(prop_name => value)
end
|
#as_json(options = {}) ⇒ Object
96
97
98
|
# File 'app/concerns/houston/props.rb', line 96
def as_json(options={})
to_h
end
|
#delete!(key) ⇒ Object
88
89
90
|
# File 'app/concerns/houston/props.rb', line 88
def delete!(key)
@record.props = @hash = @hash.except(key)
end
|
#merge!(new_props) ⇒ Object
83
84
85
86
|
# File 'app/concerns/houston/props.rb', line 83
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
100
101
102
103
104
105
|
# File 'app/concerns/houston/props.rb', line 100
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
92
93
94
|
# File 'app/concerns/houston/props.rb', line 92
def to_h
@hash.dup
end
|