Class: Thorderbolt::ParamsExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/thorderbolt/params_extractor.rb

Overview

Recursively search through the hash to find the last elements:

  1. The name of the table we want to condition on

  2. The attribute name

  3. The attribute values for ordering by.

Class Method Summary collapse

Class Method Details

.call(hash, table_name) ⇒ Object

Raises:



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/thorderbolt/params_extractor.rb', line 9

def self.call(hash, table_name)
  raise ParamsParsingError, 'Could not parse params' unless hash.size == 1

  key, value = hash.first
  return call(hash[key], key) if value.is_a? Hash

  {
    table_name: table_name,
    attribute: key,
    values: value
  }
end