class ResponseState::Response

Attributes

called_states[R]
context[R]
message[R]
state[R]
valid_states[R]

Public Class Methods

class_valid_states() click to toggle source
# File lib/response_state/response.rb, line 18
def self.class_valid_states
  @class_valid_states
end
new(state, message=nil, context=nil, valid_states=nil) click to toggle source
# File lib/response_state/response.rb, line 5
def initialize(state, message=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.include? state
  @state = state
  @context = context
  @message = message
  @called_states = []
end
valid_states(*args) click to toggle source
# File lib/response_state/response.rb, line 14
def self.valid_states(*args)
  @class_valid_states = Array(args)
end

Public Instance Methods

method_missing(method, *args) { || ... } click to toggle source
Calls superclass method
# File lib/response_state/response.rb, line 31
def method_missing(method, *args, &block)
  return super unless valid_state? method
  called_states << method unless called_states.include? method
  yield if method == state
  nil
end
uncalled_states() click to toggle source
# File lib/response_state/response.rb, line 27
def uncalled_states
  valid_states - called_states
end
unhandled_states() { |uncalled_states| ... } click to toggle source
# File lib/response_state/response.rb, line 22
def unhandled_states
  yield uncalled_states unless uncalled_states.empty?
  nil
end

Private Instance Methods

valid_state?(call_state) click to toggle source
# File lib/response_state/response.rb, line 40
def valid_state?(call_state)
  return true if valid_states.include? call_state
  raise "Invalid state: #{call_state}"
end