Class: FlexmlsApi::Configuration::YamlConfig

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

Constant Summary collapse

KEY_CONFIGURATIONS =
VALID_OPTION_KEYS  + [:oauth2] + OAUTH2_KEYS
DEFAULT_OAUTH2_PROVIDER =
"FlexmlsApi::Authentication::OAuth2Impl::PasswordProvider"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = nil) ⇒ YamlConfig

Returns a new instance of YamlConfig.



11
12
13
14
# File 'lib/flexmls_api/configuration/yaml.rb', line 11

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.



9
10
11
# File 'lib/flexmls_api/configuration/yaml.rb', line 9

def client_keys
  @client_keys
end

#oauth2_keysObject (readonly)

Returns the value of attribute oauth2_keys.



9
10
11
# File 'lib/flexmls_api/configuration/yaml.rb', line 9

def oauth2_keys
  @oauth2_keys
end

#providerObject (readonly)

Returns the value of attribute provider.



9
10
11
# File 'lib/flexmls_api/configuration/yaml.rb', line 9

def provider
  @provider
end

Class Method Details

.build(name) ⇒ Object



56
57
58
# File 'lib/flexmls_api/configuration/yaml.rb', line 56

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

.config_keysObject



47
48
49
50
# File 'lib/flexmls_api/configuration/yaml.rb', line 47

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 flexmlsApi config files



43
44
45
# File 'lib/flexmls_api/configuration/yaml.rb', line 43

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

.exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/flexmls_api/configuration/yaml.rb', line 52

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

Instance Method Details

#api_envObject



32
33
34
35
36
37
38
39
40
# File 'lib/flexmls_api/configuration/yaml.rb', line 32

def api_env
  current_env = "development"
  if env.include?("FLEXMLS_API_ENV")
    current_env = env["FLEXMLS_API_ENV"]
  elsif env.include?("RAILS_ENV")
    current_env = env["RAILS_ENV"]
  end
  return current_env
end

#load_file(file) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/flexmls_api/configuration/yaml.rb', line 15

def load_file(file)
  @file = file
  @name = File.basename(file, ".yml")
  config = YAML.load(ERB.new(File.read(file)).result)[api_env]
  config["oauth2"] == true  ? load_oauth2(config) : load_api_auth(config)
rescue => e
  FlexmlsApi.logger().error("Unable to load config file #{file}[#{api_env}]")
  raise e
end

#nameObject



29
30
31
# File 'lib/flexmls_api/configuration/yaml.rb', line 29

def name
  @name
end

#oauth2?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/flexmls_api/configuration/yaml.rb', line 25

def oauth2?
  return oauth2 == true
end