Class: Mountapi::Route::Parameter

Inherits:
Object
  • Object
show all
Defined in:
lib/mountapi/route/parameter.rb

Overview

Route parameter model used to carry schema definition

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, location, options = OpenStruct.new) ⇒ Parameter



10
11
12
13
14
# File 'lib/mountapi/route/parameter.rb', line 10

def initialize(name, location, options = OpenStruct.new)
  @name = name
  @location = location
  @options = options
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



8
9
10
# File 'lib/mountapi/route/parameter.rb', line 8

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/mountapi/route/parameter.rb', line 8

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/mountapi/route/parameter.rb', line 8

def options
  @options
end

Class Method Details

.build(*args) ⇒ Object



37
38
39
# File 'lib/mountapi/route/parameter.rb', line 37

def self.build(*args)
  new(*args)
end

Instance Method Details

#cast(value) ⇒ Object



29
30
31
# File 'lib/mountapi/route/parameter.rb', line 29

def cast(value)
  json_schema["nullable"] && value.nil? ? value : schema.cast(value)
end

#defaultObject



33
34
35
# File 'lib/mountapi/route/parameter.rb', line 33

def default
  schema.default
end

#json_schemaObject



25
26
27
# File 'lib/mountapi/route/parameter.rb', line 25

def json_schema
  @json_schema ||= schema.to_json_schema
end

#requiredObject



16
17
18
# File 'lib/mountapi/route/parameter.rb', line 16

def required
  options.required?
end

#schemaMountapi::Schema



21
22
23
# File 'lib/mountapi/route/parameter.rb', line 21

def schema
  @schema ||= Mountapi::Schema.build(options.schema)
end