Class: Grape::Entity::Exposure::NestingExposure::OutputBuilder
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Grape::Entity::Exposure::NestingExposure::OutputBuilder
- Defined in:
- lib/grape_entity/exposure/nesting_exposure/output_builder.rb
Instance Method Summary collapse
- #__getobj__ ⇒ Object
- #add(exposure, result) ⇒ Object
-
#initialize ⇒ OutputBuilder
constructor
A new instance of OutputBuilder.
- #kind_of?(klass) ⇒ Boolean (also: #is_a?)
Constructor Details
#initialize ⇒ OutputBuilder
Returns a new instance of OutputBuilder.
6 7 8 9 |
# File 'lib/grape_entity/exposure/nesting_exposure/output_builder.rb', line 6 def initialize @output_hash = {} @output_collection = [] end |
Instance Method Details
#__getobj__ ⇒ Object
30 31 32 |
# File 'lib/grape_entity/exposure/nesting_exposure/output_builder.rb', line 30 def __getobj__ output end |
#add(exposure, result) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/grape_entity/exposure/nesting_exposure/output_builder.rb', line 11 def add(exposure, result) # Save a result array in collections' array if it should be merged if result.is_a?(Array) && exposure.for_merge @output_collection << result elsif exposure.for_merge # If we have an array which should not be merged - save it with a key as a hash # If we have hash which should be merged - save it without a key (merge) return unless result @output_hash.merge! result, &merge_strategy(exposure.for_merge) else @output_hash[exposure.key] = result end end |
#kind_of?(klass) ⇒ Boolean Also known as: is_a?
25 26 27 |
# File 'lib/grape_entity/exposure/nesting_exposure/output_builder.rb', line 25 def kind_of?(klass) klass == output.class || super end |