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.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cabbage_doc/authentication.rb', line 26

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
  end

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

Instance Attribute Details

#configurableObject

Returns the value of attribute configurable.



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

def configurable
  @configurable
end

#domainObject

Returns the value of attribute domain.



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

def domain
  @domain
end

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

#schemeObject

Returns the value of attribute scheme.



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

def scheme
  @scheme
end

#subdomainObject

Returns the value of attribute subdomain.



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

def subdomain
  @subdomain
end

#subdomainsObject

Returns the value of attribute subdomains.



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

def subdomains
  @subdomains
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

#user_agentObject

Returns the value of attribute user_agent.



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

def user_agent
  @user_agent
end

#usernameObject

Returns the value of attribute username.



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

def username
  @username
end

#verboseObject

Returns the value of attribute verbose.



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

def verbose
  @verbose
end

#visibilityObject

Returns the value of attribute visibility.



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

def visibility
  @visibility
end

Class Method Details

.new(request = nil) ⇒ Object



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

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

Instance Method Details

#configurable?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/cabbage_doc/authentication.rb', line 62

def configurable?
  @configurable.any?
end

#uriObject



45
46
47
48
49
50
51
# File 'lib/cabbage_doc/authentication.rb', line 45

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

#valid?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
# File 'lib/cabbage_doc/authentication.rb', line 53

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