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”



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

def [](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



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

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

.environment=(env_value) ⇒ Object

Set the current environment



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

def environment=(env_value)
  @environment = env_value
end

.file_path=(path) ⇒ Object

Explictly defines where the configuration file is



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

def 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



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

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

.reloadObject

Reload the configuration file



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

def reload
  load_yaml
end

.url_with_church_code(church_code) ⇒ Object

Replace the “church_code” string with a custom string Meant for 1st party implementations



53
54
55
56
57
58
59
# File 'lib/f1api/configuration.rb', line 53

def url_with_church_code(church_code)
  val = @config_yaml[self.environment]["url"]
  # 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}", church_code) 
  end
end