Sha256: 492dfe58848d0b08c8a22c62856ea76bfd3753a53cfe7430453e8a48e7605a43

Contents?: true

Size: 1.23 KB

Versions: 11

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Grape
  class Entity
    module Exposure
      class RepresentExposure < Base
        attr_reader :using_class_name, :subexposure

        def setup(using_class_name, subexposure)
          @using_class = nil
          @using_class_name = using_class_name
          @subexposure = subexposure
        end

        def dup_args
          [*super, using_class_name, subexposure]
        end

        def ==(other)
          super &&
            @using_class_name == other.using_class_name &&
            @subexposure == other.subexposure
        end

        def value(entity, options)
          new_options = options.for_nesting(key(entity))
          using_class.represent(@subexposure.value(entity, options), new_options)
        end

        def valid?(entity)
          @subexposure.valid? entity
        end

        def using_class
          @using_class ||= if @using_class_name.respond_to? :constantize
                             @using_class_name.constantize
                           else
                             @using_class_name
                           end
        end

        private

        def using_options_for(options)
          options.for_nesting(key)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
grape-entity-1.0.1 lib/grape_entity/exposure/represent_exposure.rb
grape-entity-1.0.0 lib/grape_entity/exposure/represent_exposure.rb
grape-entity-0.10.2 lib/grape_entity/exposure/represent_exposure.rb
grape-entity-0.10.1 lib/grape_entity/exposure/represent_exposure.rb
grape-entity-0.10.0 lib/grape_entity/exposure/represent_exposure.rb
grape-entity-0.9.0 lib/grape_entity/exposure/represent_exposure.rb
grape-entity-0.8.2 lib/grape_entity/exposure/represent_exposure.rb
grape-entity-0.8.1 lib/grape_entity/exposure/represent_exposure.rb
grape-entity-0.8.0 lib/grape_entity/exposure/represent_exposure.rb
grape-entity-0.7.1 lib/grape_entity/exposure/represent_exposure.rb
grape-entity-0.7.0 lib/grape_entity/exposure/represent_exposure.rb