Sha256: 3b8b0efe7274e444a7c13d4e0bd7dda4a2a24eabfa679d07a14b6fb53b312a43

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module GrapeSwagger
  module Entity
    # Helper methods for DRY
    class Helper
      class << self
        def model_name(entity_model, endpoint)
          if endpoint.nil?
            entity_model.to_s.demodulize
          else
            endpoint.send(:expose_params_from_model, entity_model)
          end
        end

        def discriminator(entity_model)
          entity_model.superclass.root_exposures.detect do |value|
            value.documentation&.dig(:is_discriminator)
          end
        end

        def root_exposures_without_parent(entity_model)
          entity_model.root_exposures.select do |value|
            entity_model.superclass.root_exposures.find_by(value.attribute).nil?
          end
        end

        def root_exposure_with_discriminator(entity_model)
          if discriminator(entity_model)
            root_exposures_without_parent(entity_model)
          else
            entity_model.root_exposures
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
grape-swagger-entity-0.5.5 lib/grape-swagger/entity/helper.rb
grape-swagger-entity-0.5.4 lib/grape-swagger/entity/helper.rb
grape-swagger-entity-0.5.3 lib/grape-swagger/entity/helper.rb
grape-swagger-entity-0.5.2 lib/grape-swagger/entity/helper.rb
grape-swagger-entity-0.5.1 lib/grape-swagger/entity/helper.rb