Class: Reaction::Param
- Inherits:
-
Object
- Object
- Reaction::Param
- Defined in:
- lib/reaction/param.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#error ⇒ Object
Returns the value of attribute error.
-
#name ⇒ Object
Returns the value of attribute name.
-
#raw_value ⇒ Object
Returns the value of attribute raw_value.
-
#result ⇒ Object
Returns the value of attribute result.
-
#successful ⇒ Object
Returns the value of attribute successful.
-
#type ⇒ Object
Returns the value of attribute type.
-
#validators ⇒ Object
Returns the value of attribute validators.
Instance Method Summary collapse
- #failure(error) ⇒ Object
-
#initialize(action, type, validators, name, raw_value, provided = true) ⇒ Param
constructor
A new instance of Param.
- #process ⇒ Object
- #provided? ⇒ Boolean
- #success(result) ⇒ Object
Constructor Details
#initialize(action, type, validators, name, raw_value, provided = true) ⇒ Param
Returns a new instance of Param.
13 14 15 16 17 18 19 20 |
# File 'lib/reaction/param.rb', line 13 def initialize(action, type, validators, name, raw_value, provided = true) @action = action @type = type @validators = validators @name = name @raw_value = raw_value @provided = provided end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
3 4 5 |
# File 'lib/reaction/param.rb', line 3 def action @action end |
#error ⇒ Object
Returns the value of attribute error.
11 12 13 |
# File 'lib/reaction/param.rb', line 11 def error @error end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/reaction/param.rb', line 6 def name @name end |
#raw_value ⇒ Object
Returns the value of attribute raw_value.
7 8 9 |
# File 'lib/reaction/param.rb', line 7 def raw_value @raw_value end |
#result ⇒ Object
Returns the value of attribute result.
10 11 12 |
# File 'lib/reaction/param.rb', line 10 def result @result end |
#successful ⇒ Object
Returns the value of attribute successful.
9 10 11 |
# File 'lib/reaction/param.rb', line 9 def successful @successful end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/reaction/param.rb', line 4 def type @type end |
#validators ⇒ Object
Returns the value of attribute validators.
5 6 7 |
# File 'lib/reaction/param.rb', line 5 def validators @validators end |
Instance Method Details
#failure(error) ⇒ Object
43 44 45 46 |
# File 'lib/reaction/param.rb', line 43 def failure(error) @error = ParamError.new(name, error) @successful = false end |
#process ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/reaction/param.rb', line 22 def process if type.process(raw_value) validators.each do |validator| unless validator.process(type.result) failure(validator.error) return false end end else failure(type.error) return false end success(type.result) true end |
#provided? ⇒ Boolean
48 49 50 |
# File 'lib/reaction/param.rb', line 48 def provided? !!@provided end |
#success(result) ⇒ Object
38 39 40 41 |
# File 'lib/reaction/param.rb', line 38 def success(result) @result = result @successful = true end |