class Swagger::Grape::EntityExposure

Public Class Methods

new(exposure) click to toggle source
# File lib/ruby-swagger/grape/entity_exposure.rb, line 3
def initialize(exposure)
  raise ArgumentError.new("Expecting a Grape::Entity::Exposure - Can't translate #{exposure}!") unless exposure.is_a? Grape::Entity::Exposure::Base

  @exposure = exposure
  @swagger_type = { attribute => {} }
end

Public Instance Methods

array?() click to toggle source
# File lib/ruby-swagger/grape/entity_exposure.rb, line 22
def array?
  type == 'array'
end
attribute() click to toggle source
# File lib/ruby-swagger/grape/entity_exposure.rb, line 42
def attribute
  options[:as].present? ? options[:as].to_s : @exposure.attribute.to_s
end
description() click to toggle source
# File lib/ruby-swagger/grape/entity_exposure.rb, line 58
def description
  @exposure.documentation[:desc] if @exposure.documentation[:desc].present?
end
documentation() click to toggle source
# File lib/ruby-swagger/grape/entity_exposure.rb, line 52
def documentation
  @exposure.documentation || {}
rescue
  {}
end
nested?() click to toggle source
# File lib/ruby-swagger/grape/entity_exposure.rb, line 18
def nested?
  options[:nesting] || false
end
nested_exposures() click to toggle source
# File lib/ruby-swagger/grape/entity_exposure.rb, line 34
def nested_exposures
  nested? ? @exposure.nested_exposures : nil
end
options() click to toggle source
# File lib/ruby-swagger/grape/entity_exposure.rb, line 46
def options
  @exposure.send(:options)
rescue
  {}
end
representer?() click to toggle source
# File lib/ruby-swagger/grape/entity_exposure.rb, line 26
def representer?
  @exposure.is_a? Grape::Entity::Exposure::RepresentExposure
end
sub_type() click to toggle source
# File lib/ruby-swagger/grape/entity_exposure.rb, line 14
def sub_type
  options[:using] if representer?
end
to_swagger() click to toggle source
# File lib/ruby-swagger/grape/entity_exposure.rb, line 10
def to_swagger
  translate
end
type() click to toggle source
# File lib/ruby-swagger/grape/entity_exposure.rb, line 38
def type
  documentation[:type].to_s.downcase if documentation[:type].present?
end
type?() click to toggle source
# File lib/ruby-swagger/grape/entity_exposure.rb, line 30
def type?
  type.present?
end

Private Instance Methods

to_swagger_type(property) click to toggle source
# File lib/ruby-swagger/grape/entity_exposure.rb, line 68
def to_swagger_type(property)
  @swagger_type[attribute].merge!(property)
  @swagger_type
end
translate() click to toggle source
# File lib/ruby-swagger/grape/entity_exposure.rb, line 64
def translate
  nested? ? translate_nesting_exposure : translate_exposure
end
translate_exposure() click to toggle source
# File lib/ruby-swagger/grape/entity_exposure.rb, line 77
def translate_exposure
  to_swagger_type(Type.new(type).to_swagger(true)) if type?

  if representer?
    # it's either an object or an array of object
    using = Type.new(options[:using].to_s).to_swagger(true)

    if array?
      to_swagger_type('items' => using)
    else
      to_swagger_type(using)
    end
  end

  @swagger_type[attribute]['description'] = documentation[:desc] if documentation[:desc].present?
  @swagger_type[attribute]['type'] ||= 'string' # no type defined, assuming it's a string
  @swagger_type
end
translate_nesting_exposure() click to toggle source
# File lib/ruby-swagger/grape/entity_exposure.rb, line 73
def translate_nesting_exposure
  to_swagger_type(Swagger::Grape::EntityNestingExposure.new(@exposure).to_swagger)
end