Class: Brita::ScopeHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/brita/scope_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(param) ⇒ ScopeHandler

Returns a new instance of ScopeHandler.



3
4
5
# File 'lib/brita/scope_handler.rb', line 3

def initialize(param)
  @param = param
end

Instance Method Details

#call(collection, value, params, scope_params) ⇒ Object



7
8
9
# File 'lib/brita/scope_handler.rb', line 7

def call(collection, value, params, scope_params)
  collection.public_send(@param.internal_name, *scope_parameters(value, params, scope_params))
end

#mapped_scope_params(params, scope_params) ⇒ Object



19
20
21
22
23
# File 'lib/brita/scope_handler.rb', line 19

def mapped_scope_params(params, scope_params)
  scope_params.each_with_object({}) do |scope_param, hash|
    hash[scope_param] = params.fetch(scope_param)
  end
end

#scope_parameters(value, params, scope_params) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/brita/scope_handler.rb', line 11

def scope_parameters(value, params, scope_params)
  if scope_params.empty?
    [value]
  else
    [value, mapped_scope_params(params, scope_params)]
  end
end