Class: Holoserve::Request::Selector

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, request_subsets) ⇒ Selector

Returns a new instance of Selector.



6
7
8
# File 'lib/holoserve/request/selector.rb', line 6

def initialize(request, request_subsets)
  @request, @request_subsets = request, request_subsets
end

Instance Attribute Details

#requestObject

Returns the value of attribute request.



4
5
6
# File 'lib/holoserve/request/selector.rb', line 4

def request
  @request
end

Instance Method Details

#selectionObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/holoserve/request/selector.rb', line 10

def selection
  if Holoserve::Tool::Hash::Matcher.new(@request, @request_subsets[:default]).match?
    @request_subsets.each do |variant, subset|
      next if variant == :default
      return variant if Holoserve::Tool::Hash::Matcher.new(@request, subset).match?
    end
    return :default
  end
  nil
end