Class: SparkApi::Configuration::YamlConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/spark_api/configuration/yaml.rb

Constant Summary collapse

KEY_CONFIGURATIONS =
VALID_OPTION_KEYS  + [:oauth2] + OAUTH2_KEYS
DEFAULT_OAUTH2_PROVIDER =
"SparkApi::Authentication::OAuth2Impl::CLIProvider"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = nil) ⇒ YamlConfig

Returns a new instance of YamlConfig.



12
13
14
15
# File 'lib/spark_api/configuration/yaml.rb', line 12

def initialize(filename=nil)
  @oauth2 = false
  load_file(filename) unless filename.nil?()
end

Instance Attribute Details

#client_keysObject (readonly)

Returns the value of attribute client_keys.



10
11
12
# File 'lib/spark_api/configuration/yaml.rb', line 10

def client_keys
  @client_keys
end

#oauth2_keysObject (readonly)

Returns the value of attribute oauth2_keys.



10
11
12
# File 'lib/spark_api/configuration/yaml.rb', line 10

def oauth2_keys
  @oauth2_keys
end

#providerObject (readonly)

Returns the value of attribute provider.



10
11
12
# File 'lib/spark_api/configuration/yaml.rb', line 10

def provider
  @provider
end

Class Method Details

.build(name) ⇒ Object



66
67
68
# File 'lib/spark_api/configuration/yaml.rb', line 66

def self.build(name)
  yaml = YamlConfig.new("#{config_path}/#{name}.yml")
end

.config_keysObject



57
58
59
60
# File 'lib/spark_api/configuration/yaml.rb', line 57

def self.config_keys()
  files = Dir["#{config_path}/*.yml"]
  files.map {|f| File.basename(f,".yml") }
end

.config_pathObject

Used to specify the root of where to look for SparkApi config files



53
54
55
# File 'lib/spark_api/configuration/yaml.rb', line 53

def self.config_path
  path_prefix + "config/spark_api"
end

.exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/spark_api/configuration/yaml.rb', line 62

def self.exists?(name)
  File.exists? "#{config_path}/#{name}.yml"
end

Instance Method Details

#api_envObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/spark_api/configuration/yaml.rb', line 40

def api_env
  if env.include? "SPARK_API_ENV"
    env["SPARK_API_ENV"]
  elsif env.include? "RAILS_ENV"
    env["RAILS_ENV"]
  elsif env.include? "RACK_ENV"
    env["RACK_ENV"]
  else
    "development"
  end
end

#load_file(file) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/spark_api/configuration/yaml.rb', line 16

def load_file(file)
  @file = file
  @name = File.basename(file, ".yml")

  erb_file = ERB.new(File.read(file)).result
  config = (YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(erb_file) : YAML.load(erb_file))[api_env]
  config["oauth2"] == true  ? load_oauth2(config) : load_api_auth(config)
rescue => e
  SparkApi.logger().error("Unable to load config file #{file}[#{api_env}]")
  raise e
end

#nameObject



36
37
38
# File 'lib/spark_api/configuration/yaml.rb', line 36

def name
  @name
end

#oauth2?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/spark_api/configuration/yaml.rb', line 28

def oauth2?
  return oauth2 == true
end

#ssl_verify?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/spark_api/configuration/yaml.rb', line 32

def ssl_verify?
  return ssl_verify == true
end