Class: RedSnow::Parameter

Inherits:
NamedBlueprintNode show all
Defined in:
lib/redsnow/blueprint.rb

Overview

URI parameter Blueprint AST node

represents one 'parameters section' parameter

Instance Attribute Summary collapse

Attributes inherited from NamedBlueprintNode

#description, #name

Instance Method Summary collapse

Methods inherited from NamedBlueprintNode

#ensure_description_newlines

Constructor Details

#initialize(parameter) ⇒ Parameter

Returns a new instance of Parameter.

Parameters:

  • parameter (json)


143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/redsnow/blueprint.rb', line 143

def initialize(parameter)
  @name = parameter.fetch('name', '')
  @description = parameter.fetch('description', '')
  @type = parameter.fetch('type', '')

  case parameter['required']
  when true
    @use = :required
  when false
    @use = :optional
  else
    @use = :undefined
  end

  @default_value = parameter.fetch('default', nil)
  @example_value = parameter.fetch('example', nil)

  @values = []
  parameter.key?('values') && parameter['values'].each do |value|
    @values << value['value']
  end
end

Instance Attribute Details

#default_valueString

default value of the parameter or nil This is a value used when the parameter is ommited in the request.

Returns:

  • (String)

    the current value of default_value



135
136
137
# File 'lib/redsnow/blueprint.rb', line 135

def default_value
  @default_value
end

#example_valueString

example value of the parameter or nil

Returns:

  • (String)

    the current value of example_value



135
136
137
# File 'lib/redsnow/blueprint.rb', line 135

def example_value
  @example_value
end

#typeString

an arbitrary type of the parameter or nil

Returns:

  • (String)

    the current value of type



135
136
137
# File 'lib/redsnow/blueprint.rb', line 135

def type
  @type
end

#useSymbol

parameter necessity flag, ‘:required`, `:optional` or :undefined Where `:undefined` implies `:required` according to the API Blueprint Specification

Returns:

  • (Symbol)

    the current value of use



135
136
137
# File 'lib/redsnow/blueprint.rb', line 135

def use
  @use
end

#valuesArray<String>

an enumeration of possible parameter values

Returns:

  • (Array<String>)

    the current value of values



135
136
137
# File 'lib/redsnow/blueprint.rb', line 135

def values
  @values
end