Class: ResponseState::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/response_state/response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, 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.empty? || @valid_states.include?(state))
  @state = state
  @context = context
  @message = 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

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/response_state/response.rb', line 3

def context
  @context
end

#messageObject (readonly)

Returns the value of attribute message.



3
4
5
# File 'lib/response_state/response.rb', line 3

def message
  @message
end

#stateObject (readonly)

Returns the value of attribute state.



3
4
5
# File 'lib/response_state/response.rb', line 3

def state
  @state
end

#valid_statesObject (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_statesObject



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