Class: BlazerJsonAPI::ResultToNestedJson
- Inherits:
-
Object
- Object
- BlazerJsonAPI::ResultToNestedJson
- Defined in:
- lib/blazer_json_api/result_to_nested_json.rb
Instance Attribute Summary collapse
-
#blazer_result ⇒ Object
readonly
Returns the value of attribute blazer_result.
-
#statement ⇒ Object
readonly
Returns the value of attribute statement.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(statement, blazer_result) ⇒ ResultToNestedJson
constructor
A new instance of ResultToNestedJson.
Constructor Details
#initialize(statement, blazer_result) ⇒ 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_result ⇒ Object (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 |
#statement ⇒ Object (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
#call ⇒ Object
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 |