Class: Rambo::RamlModels::SecurityScheme

Inherits:
Object
  • Object
show all
Defined in:
lib/rambo/raml_models/security_scheme.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raml, options = {}) ⇒ SecurityScheme

Returns a new instance of SecurityScheme.



7
8
9
10
11
# File 'lib/rambo/raml_models/security_scheme.rb', line 7

def initialize(raml, options={})
  @options        = options
  @schema, @title = raml.last.fetch("describedBy", {}), raml.first
  use_token!
end

Instance Attribute Details

#schema=(value) ⇒ Object

Sets the attribute schema

Parameters:

  • the value to set the attribute schema to.



4
5
6
# File 'lib/rambo/raml_models/security_scheme.rb', line 4

def schema=(value)
  @schema = value
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/rambo/raml_models/security_scheme.rb', line 4

def title
  @title
end

Instance Method Details

#api_token_headerObject



19
20
21
22
23
# File 'lib/rambo/raml_models/security_scheme.rb', line 19

def api_token_header
  return unless h = schema.fetch("headers", nil)

  h.find {|key, value| key.match(/(token|key)/i) }.first
end

#headersObject



25
26
27
# File 'lib/rambo/raml_models/security_scheme.rb', line 25

def headers
  @headers ||= Rambo::RamlModels::Headers.new(schema.fetch("headers") || {})
end

#use_token!Object



13
14
15
16
17
# File 'lib/rambo/raml_models/security_scheme.rb', line 13

def use_token!
  if schema.fetch("headers", nil)
    schema.fetch("headers")[api_token_header] = @options[:token]
  end
end