class Grape::Entity::Exposure::NestingExposure::NestedExposures

Public Class Methods

new(exposures) click to toggle source
# File lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb, line 9
def initialize(exposures)
  @exposures = exposures
  @deep_complex_nesting = nil
end

Public Instance Methods

<<(exposure) click to toggle source
# File lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb, line 22
def <<(exposure)
  reset_memoization!
  @exposures << exposure
end
clear() click to toggle source
# File lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb, line 33
def clear
  reset_memoization!
  @exposures.clear
end
deep_complex_nesting?(entity) click to toggle source

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

# File lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb, line 59
def deep_complex_nesting?(entity)
  if @deep_complex_nesting.nil?
    all_nesting = select(&:nesting?)
    @deep_complex_nesting =
      all_nesting
      .group_by { |exposure| exposure.key(entity) }
      .any? { |_key, exposures| exposures.length > 1 }
  else
    @deep_complex_nesting
  end
end
delete_by(*attributes) click to toggle source
# File lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb, line 27
def delete_by(*attributes)
  reset_memoization!
  @exposures.reject! { |e| attributes.include? e.attribute }
  @exposures
end
find_by(attribute) click to toggle source
# File lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb, line 14
def find_by(attribute)
  @exposures.find { |e| e.attribute == attribute }
end
select_by(attribute) click to toggle source
# File lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb, line 18
def select_by(attribute)
  @exposures.select { |e| e.attribute == attribute }
end

Private Instance Methods

reset_memoization!() click to toggle source
# File lib/grape_entity/exposure/nesting_exposure/nested_exposures.rb, line 73
def reset_memoization!
  @deep_complex_nesting = nil
end