Class: CabbageDoc::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/cabbage_doc/authentication.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAuthentication

Returns a new instance of Authentication.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cabbage_doc/authentication.rb', line 29

def initialize
  Configuration.instance.tap do |config|
    @domain     = config.domain
    @scheme     = config.scheme
    @path       = config.path
    @user_agent = config.title
    @verbose    = config.verbose
    @visibility = config.visibility.dup
    @tag        = config.tags.first
    @json       = config.json
  end

  @subdomains = []
  @configurable = []
  @type = :basic
end

Instance Attribute Details

#configurableObject

Returns the value of attribute configurable.



13
14
15
# File 'lib/cabbage_doc/authentication.rb', line 13

def configurable
  @configurable
end

#domainObject

Returns the value of attribute domain.



13
14
15
# File 'lib/cabbage_doc/authentication.rb', line 13

def domain
  @domain
end

#jsonObject

Returns the value of attribute json.



13
14
15
# File 'lib/cabbage_doc/authentication.rb', line 13

def json
  @json
end

#passwordObject

Returns the value of attribute password.



13
14
15
# File 'lib/cabbage_doc/authentication.rb', line 13

def password
  @password
end

#pathObject

Returns the value of attribute path.



13
14
15
# File 'lib/cabbage_doc/authentication.rb', line 13

def path
  @path
end

#schemeObject

Returns the value of attribute scheme.



13
14
15
# File 'lib/cabbage_doc/authentication.rb', line 13

def scheme
  @scheme
end

#subdomainObject

Returns the value of attribute subdomain.



13
14
15
# File 'lib/cabbage_doc/authentication.rb', line 13

def subdomain
  @subdomain
end

#subdomainsObject

Returns the value of attribute subdomains.



13
14
15
# File 'lib/cabbage_doc/authentication.rb', line 13

def subdomains
  @subdomains
end

#tagObject

Returns the value of attribute tag.



13
14
15
# File 'lib/cabbage_doc/authentication.rb', line 13

def tag
  @tag
end

#tokenObject

Returns the value of attribute token.



13
14
15
# File 'lib/cabbage_doc/authentication.rb', line 13

def token
  @token
end

#typeObject

Returns the value of attribute type.



13
14
15
# File 'lib/cabbage_doc/authentication.rb', line 13

def type
  @type
end

#user_agentObject

Returns the value of attribute user_agent.



13
14
15
# File 'lib/cabbage_doc/authentication.rb', line 13

def user_agent
  @user_agent
end

#usernameObject

Returns the value of attribute username.



13
14
15
# File 'lib/cabbage_doc/authentication.rb', line 13

def username
  @username
end

#verboseObject

Returns the value of attribute verbose.



13
14
15
# File 'lib/cabbage_doc/authentication.rb', line 13

def verbose
  @verbose
end

#visibilityObject

Returns the value of attribute visibility.



13
14
15
# File 'lib/cabbage_doc/authentication.rb', line 13

def visibility
  @visibility
end

Class Method Details

.new(request = nil, tag = nil) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/cabbage_doc/authentication.rb', line 4

def new(request = nil, tag = nil)
  super().tap do |auth|
    auth.tag = tag if tag
    yield(auth) if block_given?
    Configuration.instance.authentication.call(auth, request)
  end
end

Instance Method Details

#configurable?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/cabbage_doc/authentication.rb', line 67

def configurable?
  @configurable.any?
end

#uriObject



50
51
52
53
54
55
56
# File 'lib/cabbage_doc/authentication.rb', line 50

def uri
  if path && path != '/'
    "#{root_uri}/#{path}"
  else
    root_uri
  end
end

#valid?Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
# File 'lib/cabbage_doc/authentication.rb', line 58

def valid?
  case type
  when :basic
    username && password && valid_subdomain?
  else
    !token.nil? && valid_subdomain?
  end
end