Class: Esse::Index::RequestConfigurable::RequestParams

Inherits:
Object
  • Object
show all
Defined in:
lib/esse/index/request_configurable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation, hash = {}, &block) ⇒ RequestParams

Returns a new instance of RequestParams.



21
22
23
24
25
# File 'lib/esse/index/request_configurable.rb', line 21

def initialize(operation, hash = {}, &block)
  @operation = operation
  @hash = hash.transform_keys(&:to_sym)
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



19
20
21
# File 'lib/esse/index/request_configurable.rb', line 19

def block
  @block
end

#hashObject (readonly)

Returns the value of attribute hash.



19
20
21
# File 'lib/esse/index/request_configurable.rb', line 19

def hash
  @hash
end

#operationObject (readonly)

Returns the value of attribute operation.



19
20
21
# File 'lib/esse/index/request_configurable.rb', line 19

def operation
  @operation
end

Instance Method Details

#call(doc) ⇒ Hash

Returns the request parameters for the operation.

Parameters:

  • doc (Esse::Document)

    the document to apply the request parameters to

Returns:

  • (Hash)

    the request parameters for the operation

Raises:

  • (ArgumentError)

    if the result of the block is not a Hash



30
31
32
33
34
35
36
37
# File 'lib/esse/index/request_configurable.rb', line 30

def call(doc)
  return hash unless block

  result = block.call(doc) || {}
  raise ArgumentError, "Expected a Hash, got #{result.class}" unless result.is_a?(Hash)

  hash.merge(result.transform_keys(&:to_sym))
end