Class: RWF::Result
- Inherits:
-
Object
- Object
- RWF::Result
- Defined in:
- lib/rwf/result.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #failure!(error = nil) ⇒ Object
- #failure? ⇒ Boolean
- #initial? ⇒ Boolean
-
#initialize(params) ⇒ Result
constructor
A new instance of Result.
- #okish? ⇒ Boolean
- #recover! ⇒ Object
- #state!(value) ⇒ Object
- #success! ⇒ Object
- #success? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(params) ⇒ Result
Returns a new instance of Result.
7 8 9 10 11 |
# File 'lib/rwf/result.rb', line 7 def initialize(params) @params = params @state = :initial @error = nil end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
5 6 7 |
# File 'lib/rwf/result.rb', line 5 def error @error end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
5 6 7 |
# File 'lib/rwf/result.rb', line 5 def state @state end |
Instance Method Details
#[](key) ⇒ Object
49 50 51 |
# File 'lib/rwf/result.rb', line 49 def [](key) @params[key] end |
#failure!(error = nil) ⇒ Object
30 31 32 33 34 |
# File 'lib/rwf/result.rb', line 30 def failure!(error = nil) @error = error if error @state = :failure self end |
#failure? ⇒ Boolean
36 37 38 |
# File 'lib/rwf/result.rb', line 36 def failure? !success? end |
#initial? ⇒ Boolean
13 14 15 |
# File 'lib/rwf/result.rb', line 13 def initial? state == :initial end |
#okish? ⇒ Boolean
26 27 28 |
# File 'lib/rwf/result.rb', line 26 def okish? initial? || success? end |
#recover! ⇒ Object
44 45 46 47 |
# File 'lib/rwf/result.rb', line 44 def recover! @error = nil success! end |
#state!(value) ⇒ Object
40 41 42 |
# File 'lib/rwf/result.rb', line 40 def state!(value) value ? success! : failure! end |
#success! ⇒ Object
17 18 19 20 |
# File 'lib/rwf/result.rb', line 17 def success! @state = :success self end |
#success? ⇒ Boolean
22 23 24 |
# File 'lib/rwf/result.rb', line 22 def success? state == :success && error.nil? end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/rwf/result.rb', line 53 def to_s state.to_s.capitalize end |