Class: Code42::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/code42/settings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Settings

Returns a new instance of Settings.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/code42/settings.rb', line 5

def initialize(options = {})
  options.symbolize_keys!
  self.host     = options[:host]
  self.port     = options[:port]
  self.https    = !options[:https].nil? ? options[:https] : true
  self.verify_https = !options[:verify_https].nil? ? options[:verify_https] : true
  self.api_root = options[:api_root] || '/api'
  self.username = options[:username]
  self.password = options[:password]
  self.token    = options[:token]
  self.debug    = options[:debug]
end

Instance Attribute Details

#api_rootObject

Returns the value of attribute api_root.



3
4
5
# File 'lib/code42/settings.rb', line 3

def api_root
  @api_root
end

#debugObject

Returns the value of attribute debug.



3
4
5
# File 'lib/code42/settings.rb', line 3

def debug
  @debug
end

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/code42/settings.rb', line 3

def host
  @host
end

#httpsObject

Returns the value of attribute https.



3
4
5
# File 'lib/code42/settings.rb', line 3

def https
  @https
end

#mlkObject

Returns the value of attribute mlk.



3
4
5
# File 'lib/code42/settings.rb', line 3

def mlk
  @mlk
end

#passwordObject

Returns the value of attribute password.



3
4
5
# File 'lib/code42/settings.rb', line 3

def password
  @password
end

#portObject

Returns the value of attribute port.



3
4
5
# File 'lib/code42/settings.rb', line 3

def port
  @port
end

#tokenObject

Returns the value of attribute token.



3
4
5
# File 'lib/code42/settings.rb', line 3

def token
  @token
end

#usernameObject

Returns the value of attribute username.



3
4
5
# File 'lib/code42/settings.rb', line 3

def username
  @username
end

#verify_httpsObject

Returns the value of attribute verify_https.



3
4
5
# File 'lib/code42/settings.rb', line 3

def verify_https
  @verify_https
end

Instance Method Details

#allObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/code42/settings.rb', line 18

def all
  settings = {}
  settings[:host]     = host
  settings[:port]     = port
  settings[:https]    = https
  settings[:api_root] = api_root
  settings[:username] = username
  settings[:password] = password
  settings
end

#base_urlObject

Raises:



33
34
35
36
# File 'lib/code42/settings.rb', line 33

def base_url
  raise Error unless valid?
  "#{scheme}://#{host}:#{port}#{api_root}"
end

#schemeObject



29
30
31
# File 'lib/code42/settings.rb', line 29

def scheme
  https ? 'https' : 'http'
end

#valid?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/code42/settings.rb', line 38

def valid?
  host && port && api_root
end