Class: FellowshipOneAPI::Configuration

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

Overview

This accesses the YAML-based F1 API config file

This class was written to take rails environment variables like RAILS_ENV and Rails.root into account

Class Method Summary collapse

Class Method Details

.[](value) ⇒ Object

Gets the specified key from the configuration file

Example

FellowshipTechAPIClient.Configuration # “2”

FellowshipTechAPIClient.Configuration # “12345678-9abc-def0-1234-567890abcdef”



21
22
23
24
25
26
27
28
29
# File 'lib/f1api/configuration.rb', line 21

def self.[](value)
  load_yaml if @config_yaml.nil?
  val = @config_yaml[self.environment][value]
  # if we have the string has "{church_code}" then we'll substitute it
  if val =~ /\{church_code\}/ and value != "church_code"
    return val.gsub("{church_code}", self["church_code"]) 
  end
  return val
end

.environmentObject

Gets the current environment



32
33
34
35
36
# File 'lib/f1api/configuration.rb', line 32

def self.environment
  @environment ||= "development" 
  @environment ||= ::Rails.env if defined? ::Rails
  @environment
end

.environment=(env_value) ⇒ Object

Set the current environment



39
40
41
# File 'lib/f1api/configuration.rb', line 39

def self.environment=(env_value)
  @environment = env_value
end

.file_path=(path) ⇒ Object

Explictly defines where the configuration file is



7
8
9
10
# File 'lib/f1api/configuration.rb', line 7

def self.file_path=(path)
  @config_yaml = nil
  @file_path = path
end

.method_missing(name, *args, &block) ⇒ Object

Overridden method_missing to facilitate a more pleasing ruby-like syntax for accessing configuration values



45
46
47
48
# File 'lib/f1api/configuration.rb', line 45

def self.method_missing(name, *args, &block)
  return self[name.to_s] unless self[name.to_s].nil?
  super
end

.reloadObject

Reload the configuration file



13
14
15
# File 'lib/f1api/configuration.rb', line 13

def self.reload
  load_yaml
end