Class: ResponseState::Response
- Inherits:
-
Object
- Object
- ResponseState::Response
- Defined in:
- lib/response_state/response.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#valid_states ⇒ Object
readonly
Returns the value of attribute valid_states.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(state, message = nil, context = nil, valid_states = nil) ⇒ Response
constructor
A new instance of Response.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(state, message = nil, context = nil, valid_states = nil) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 11 |
# File 'lib/response_state/response.rb', line 5 def initialize(state, =nil, context=nil, valid_states=nil) @valid_states = Array(valid_states || self.class.class_valid_states) raise "Invalid state of response: #{state}" unless (@valid_states.empty? || @valid_states.include?(state)) @state = state @context = context @message = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/response_state/response.rb', line 21 def method_missing(method, *args, &block) if validate_state?(method) yield if method == state else super end end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/response_state/response.rb', line 3 def context @context end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
3 4 5 |
# File 'lib/response_state/response.rb', line 3 def @message end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
3 4 5 |
# File 'lib/response_state/response.rb', line 3 def state @state end |
#valid_states ⇒ Object (readonly)
Returns the value of attribute valid_states.
3 4 5 |
# File 'lib/response_state/response.rb', line 3 def valid_states @valid_states end |
Class Method Details
.class_valid_states ⇒ Object
17 18 19 |
# File 'lib/response_state/response.rb', line 17 def self.class_valid_states @class_valid_states end |
.valid_states(*args) ⇒ Object
13 14 15 |
# File 'lib/response_state/response.rb', line 13 def self.valid_states(*args) @class_valid_states = Array(args) end |