Class: Hyperdrive::Param

Inherits:
Object
  • Object
show all
Defined in:
lib/hyperdrive/param.rb

Direct Known Subclasses

Filter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description, options = {}) ⇒ Param

Returns a new instance of Param.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/hyperdrive/param.rb', line 7

def initialize(name, description, options = {})
  @name = name.to_s
  @description = description
  options = default_options.merge(options)
  @required = if options[:required] == true
                %w(POST PUT PATCH)
              elsif options[:required] == false
                []
              else
                Array(options[:required])
              end
  @type = options[:type]
  @constraints = "#{required_constraint} #{options[:constraints]}"
end

Instance Attribute Details

#constraintsObject (readonly)

Returns the value of attribute constraints.



5
6
7
# File 'lib/hyperdrive/param.rb', line 5

def constraints
  @constraints
end

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/hyperdrive/param.rb', line 5

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/hyperdrive/param.rb', line 5

def name
  @name
end

#requiredObject (readonly)

Returns the value of attribute required.



5
6
7
# File 'lib/hyperdrive/param.rb', line 5

def required
  @required
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/hyperdrive/param.rb', line 5

def type
  @type
end

Instance Method Details

#required?(http_request_method) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/hyperdrive/param.rb', line 22

def required?(http_request_method)
  @required.include? http_request_method
end

#to_hashObject



26
27
28
# File 'lib/hyperdrive/param.rb', line 26

def to_hash
  { name: @name, description: @description, type: @type, constraints: @constraints }
end