Class: BlazerJsonAPI::ResultToNestedJson

Inherits:
Object
  • Object
show all
Defined in:
lib/blazer_json_api/result_to_nested_json.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(statement, blazer_result) ⇒ ResultToNestedJson

Returns a new instance of ResultToNestedJson.



12
13
14
15
# File 'lib/blazer_json_api/result_to_nested_json.rb', line 12

def initialize(statement, blazer_result)
  @statement = statement
  @blazer_result = blazer_result
end

Instance Attribute Details

#blazer_resultObject (readonly)

Returns the value of attribute blazer_result.



10
11
12
# File 'lib/blazer_json_api/result_to_nested_json.rb', line 10

def blazer_result
  @blazer_result
end

#statementObject (readonly)

Returns the value of attribute statement.



10
11
12
# File 'lib/blazer_json_api/result_to_nested_json.rb', line 10

def statement
  @statement
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/blazer_json_api/result_to_nested_json.rb', line 17

def call
  transformed_result =
    blazer_result_to_json(blazer_result).each do |hash|
      hash.keys.select { |key| key =~ /#{nesting_column_separator}/ }.each do |namespaced_key|
        nested_keys = namespaced_key.to_s.split(nesting_column_separator)
        hash.deep_merge!(deep_hash_set(*nested_keys[0..nested_keys.size], hash[namespaced_key]))
        hash.delete(namespaced_key)
      end
    end
  collection_or_single_record(transformed_result)
end