Class: Panda::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/panda/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_hash(auth_params) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/panda/config.rb', line 18

def self.from_hash(auth_params)
  config = new
  auth_params.each_key do |key|
    config.send("#{key}=", auth_params[key])
  end
  config
end

.from_panda_url(panda_url) ⇒ Object



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

def self.from_panda_url(panda_url)
  panda_uri = URI.parse(panda_url)

  config = new
  config.access_key = panda_uri.user
  config.secret_key = panda_uri.password
  config.cloud_id   = panda_uri.path[1..-1]
  config.api_host   = panda_uri.host
  config.api_port   = panda_uri.port
  config
end

Instance Method Details

#adapter(adapter_name) ⇒ Object



46
47
48
# File 'lib/panda/config.rb', line 46

def adapter(adapter_name)
  Panda.adapter = adapter_name
end

#adapter=(adapter_name) ⇒ Object



50
51
52
# File 'lib/panda/config.rb', line 50

def adapter=(adapter_name)
  Panda.adapter = adapter_name
end

#configObject



26
27
28
# File 'lib/panda/config.rb', line 26

def config
  @config ||= {}
end

#region(region) ⇒ Object

Set the correct api_host for US/EU



55
56
57
58
59
60
61
62
63
# File 'lib/panda/config.rb', line 55

def region(region)
  if(region.to_s == 'us')
    config['api_host'] = US_API_HOST
  elsif(region.to_s == 'eu')
    config['api_host'] = EU_API_HOST
  else
    raise "Region Unknown"
  end
end

#to_hashObject



42
43
44
# File 'lib/panda/config.rb', line 42

def to_hash
  config
end

#valid?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/panda/config.rb', line 71

def valid?
  validation_errors.empty?
end

#validate!Object



65
66
67
68
69
# File 'lib/panda/config.rb', line 65

def validate!
  errs = validation_errors
  raise Panda::ConfigurationError, errs.join(', ') if errs.any?
  true
end

#validation_errorsObject



75
76
77
78
79
80
81
82
83
84
# File 'lib/panda/config.rb', line 75

def validation_errors
  err = []
  if config["access_key"].to_s.empty?
    err << "access_key is missing"
  end
  if config["secret_key"].to_s.empty?
    err << "secret_key is missing"
  end
  err
end