Module: Reaction::HasParams
- Included in:
- Action
- Defined in:
- lib/reaction/has_params.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #param(name) ⇒ Object
- #params ⇒ Object
- #raw_param(name) ⇒ Object
- #raw_params ⇒ Object
- #set_param(name, value, meta = {}) ⇒ Object
- #set_params(params = {}, meta = {}) ⇒ Object
- #typed_params ⇒ Object
- #validate_params ⇒ Object
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/reaction/has_params.rb', line 3 def self.included(base) base.include HasDocs base.include HasMetas base.include HasTypes base.include HasValidators base.extend ClassMethods end |
Instance Method Details
#param(name) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/reaction/has_params.rb', line 22 def param(name) typed_params[name.to_sym] ||= begin type = self.class.types[name.to_sym] type.convert(raw_param(name)) end end |
#params ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/reaction/has_params.rb', line 29 def params ret = {} raw_params.keys.each do |name| ret[name.to_sym] = param(name) end ret end |
#raw_param(name) ⇒ Object
53 54 55 |
# File 'lib/reaction/has_params.rb', line 53 def raw_param(name) raw_params[name.to_sym] end |
#raw_params ⇒ Object
57 58 59 |
# File 'lib/reaction/has_params.rb', line 57 def raw_params @raw_params ||= {} end |
#set_param(name, value, meta = {}) ⇒ Object
41 42 43 44 45 |
# File 'lib/reaction/has_params.rb', line 41 def set_param(name, value, = {}) return unless self.class.param_settable?(name) (name, ) raw_params[name.to_sym] = value end |
#set_params(params = {}, meta = {}) ⇒ Object
47 48 49 50 51 |
# File 'lib/reaction/has_params.rb', line 47 def set_params(params = {}, = {}) params.each do |name, value| set_param(name, value, ) end end |
#typed_params ⇒ Object
37 38 39 |
# File 'lib/reaction/has_params.rb', line 37 def typed_params @typed_params ||= {} end |
#validate_params ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/reaction/has_params.rb', line 61 def validate_params raw_params.each do |name, value| self.class.type(name).validate_each(self, name, value) converted = param(name) self.class.validators(name).each do |validator| validator.validate_each(self, name, converted) end end end |