Module: Reaction::HasParams
- Defined in:
- lib/reaction/has_params.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #param(name) ⇒ Object
- #param_provided?(name) ⇒ Boolean
- #params ⇒ Object
- #process_params ⇒ Object
- #raw_param(name) ⇒ Object
- #raw_params ⇒ Object
- #rm_param(name) ⇒ Object
- #set_param(name, value, meta = {}) ⇒ Object
- #set_params(params = {}, meta = {}) ⇒ Object
- #typed_params ⇒ Object
- #validate_params ⇒ Object
Class Method Details
.included(base) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/reaction/has_params.rb', line 20 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
46 47 48 49 50 51 |
# File 'lib/reaction/has_params.rb', line 46 def param(name) typed_params[name.to_sym] ||= begin type = self.class.types[name.to_sym] type.convert(self, name, raw_param(name)) end end |
#param_provided?(name) ⇒ Boolean
42 43 44 |
# File 'lib/reaction/has_params.rb', line 42 def param_provided?(name) raw_params.has_key?(name.to_sym) end |
#params ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/reaction/has_params.rb', line 53 def params ret = {} raw_params.keys.each do |name| ret[name.to_sym] = param(name) end ret end |
#process_params ⇒ Object
11 12 13 14 15 |
# File 'lib/reaction/has_params.rb', line 11 def process_params params.each do |param| return false unless param.process end end |
#raw_param(name) ⇒ Object
84 85 86 |
# File 'lib/reaction/has_params.rb', line 84 def raw_param(name) raw_params[name.to_sym] end |
#raw_params ⇒ Object
88 89 90 |
# File 'lib/reaction/has_params.rb', line 88 def raw_params @raw_params ||= {} end |
#rm_param(name) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/reaction/has_params.rb', line 65 def rm_param(name) ret = param(name) (name) raw_params.delete(name.to_sym) ret end |
#set_param(name, value, meta = {}) ⇒ Object
72 73 74 75 76 |
# File 'lib/reaction/has_params.rb', line 72 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
4 5 6 7 8 9 |
# File 'lib/reaction/has_params.rb', line 4 def set_params(param_values) param_values.each do |name, raw_value| builder = self.class.param_builder(name) builder.build(self, name, raw_value) end end |
#typed_params ⇒ Object
61 62 63 |
# File 'lib/reaction/has_params.rb', line 61 def typed_params @typed_params ||= {} end |
#validate_params ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/reaction/has_params.rb', line 92 def validate_params raw_params.each do |name, value| self.class.type(name).validate_each(self, name, value) end return if errors.any? raw_params.each do |name, value| converted = param(name) self.class.validators(name).each do |validator| validator.validate_each(self, name, converted) end end end |