Class: Swagger::Grape::EntityExposure

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-swagger/grape/entity_exposure.rb

Direct Known Subclasses

EntityNestingExposure

Instance Method Summary collapse

Constructor Details

#initialize(exposure) ⇒ EntityExposure

Returns a new instance of EntityExposure.

Raises:

  • (ArgumentError)


3
4
5
6
7
8
# 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

Instance Method Details

#array?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/ruby-swagger/grape/entity_exposure.rb', line 22

def array?
  type == 'array'
end

#attributeObject



42
43
44
# File 'lib/ruby-swagger/grape/entity_exposure.rb', line 42

def attribute
  options[:as].present? ? options[:as].to_s : @exposure.attribute.to_s
end

#descriptionObject



58
59
60
# File 'lib/ruby-swagger/grape/entity_exposure.rb', line 58

def description
  @exposure.documentation[:desc] if @exposure.documentation[:desc].present?
end

#documentationObject



52
53
54
55
56
# File 'lib/ruby-swagger/grape/entity_exposure.rb', line 52

def documentation
  @exposure.documentation || {}
rescue
  {}
end

#nested?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/ruby-swagger/grape/entity_exposure.rb', line 18

def nested?
  options[:nesting] || false
end

#nested_exposuresObject



34
35
36
# File 'lib/ruby-swagger/grape/entity_exposure.rb', line 34

def nested_exposures
  nested? ? @exposure.nested_exposures : nil
end

#optionsObject



46
47
48
49
50
# File 'lib/ruby-swagger/grape/entity_exposure.rb', line 46

def options
  @exposure.send(:options)
rescue
  {}
end

#representer?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ruby-swagger/grape/entity_exposure.rb', line 26

def representer?
  @exposure.is_a? Grape::Entity::Exposure::RepresentExposure
end

#sub_typeObject



14
15
16
# File 'lib/ruby-swagger/grape/entity_exposure.rb', line 14

def sub_type
  options[:using] if representer?
end

#to_swaggerObject



10
11
12
# File 'lib/ruby-swagger/grape/entity_exposure.rb', line 10

def to_swagger
  translate
end

#typeObject



38
39
40
# File 'lib/ruby-swagger/grape/entity_exposure.rb', line 38

def type
  documentation[:type].to_s.downcase if documentation[:type].present?
end

#type?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ruby-swagger/grape/entity_exposure.rb', line 30

def type?
  type.present?
end