Class: Grape::Entity::Exposure::NestingExposure::NestedExposures

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb

Instance Method Summary collapse

Constructor Details

#initialize(exposures) ⇒ NestedExposures

Returns a new instance of NestedExposures.



8
9
10
# File 'lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb', line 8

def initialize(exposures)
  @exposures = exposures
end

Instance Method Details

#<<(exposure) ⇒ Object



16
17
18
19
# File 'lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb', line 16

def <<(exposure)
  reset_memoization!
  @exposures << exposure
end

#clearObject



26
27
28
29
# File 'lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb', line 26

def clear
  reset_memoization!
  @exposures.clear
end

#deep_complex_nesting?Boolean

Determine if we have any nesting exposures with the same name.

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
# File 'lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb', line 52

def deep_complex_nesting?
  if @deep_complex_nesting.nil?
    all_nesting = select(&:nesting?)
    @deep_complex_nesting = all_nesting.group_by(&:key).any? { |_key, exposures| exposures.length > 1 }
  else
    @deep_complex_nesting
  end
end

#delete_by(*attributes) ⇒ Object



21
22
23
24
# File 'lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb', line 21

def delete_by(*attributes)
  reset_memoization!
  @exposures.reject! { |e| attributes.include? e.attribute }
end

#find_by(attribute) ⇒ Object



12
13
14
# File 'lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb', line 12

def find_by(attribute)
  @exposures.find { |e| e.attribute == attribute }
end