Class: GrapeApiary::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/grape-apiary/config.rb

Constant Summary collapse

SETTINGS =
%i(
  host
  name
  description
  request_headers
  response_headers
  example_id_type
  resource_exclusion
  include_root
).freeze

Class Method Summary collapse

Class Method Details

.example_id_typeObject



47
48
49
# File 'lib/grape-apiary/config.rb', line 47

def example_id_type
  @example_id_type ||= :integer
end

.example_id_type=(value) ⇒ Object

Raises:



37
38
39
40
41
42
43
44
45
# File 'lib/grape-apiary/config.rb', line 37

def example_id_type=(value)
  raise UnsupportedIDType unless supported_id_types.include?(value)

  if value.to_sym == :bson && !Object.const_defined?('BSON')
    raise BSONNotDefinied
  end

  @example_id_type = value
end

.generate_idObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/grape-apiary/config.rb', line 51

def generate_id
  case example_id_type
  when :integer
    SecureRandom.random_number(1000)
  when :uuid
    SecureRandom.uuid
  when :bson
    BSON::ObjectId.new.to_s
  end
end

.include_rootObject



29
30
31
# File 'lib/grape-apiary/config.rb', line 29

def include_root
  @include_root ||= false
end

.request_headersObject



17
18
19
# File 'lib/grape-apiary/config.rb', line 17

def request_headers
  @request_headers ||= []
end

.resource_exclusionObject



25
26
27
# File 'lib/grape-apiary/config.rb', line 25

def resource_exclusion
  @resource_exclusion ||= []
end

.response_headersObject



21
22
23
# File 'lib/grape-apiary/config.rb', line 21

def response_headers
  @response_headers ||= []
end

.supported_id_typesObject



33
34
35
# File 'lib/grape-apiary/config.rb', line 33

def supported_id_types
  %i(integer uuid bson)
end