Class: Holoserve::Response::Selector

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

Defined Under Namespace

Classes: Sandbox

Instance Method Summary collapse

Constructor Details

#initialize(responses, state, logger) ⇒ Selector

Returns a new instance of Selector.



22
23
24
25
# File 'lib/holoserve/response/selector.rb', line 22

def initialize(responses, state, logger)
  @responses, @logger = responses, logger
  @sandbox = Sandbox.new state, logger
end

Instance Method Details

#selectionObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/holoserve/response/selector.rb', line 27

def selection
  @responses.each do |key, response|
    next if key.to_sym == :default || !response.has_key?(:condition)
    begin
      match = @sandbox.instance_eval do
        eval response[:condition]
      end
      return key.to_sym if match
    rescue Object => error
      @logger.error "error evaluating condition: [#{response[:condition]}] #{error.inspect}"
    end
  end
  @responses.has_key?(:default) ? :default : nil
end