Skip to content

Instantly share code, notes, and snippets.

@liammclennan
Created May 29, 2011 02:19
Show Gist options
  • Select an option

  • Save liammclennan/997399 to your computer and use it in GitHub Desktop.

Select an option

Save liammclennan/997399 to your computer and use it in GitHub Desktop.
settings service
# settings file
development:
gateway: test
test:
gateway: jira
production:
gateway: jira
# rspec specifications file
require_relative '../lib/services/settings'
describe Settings do
describe 'Development Environment' do
let(:settings) { Settings.new("development") }
it "should return 'test' gateway" do
settings.get('gateway').should == 'test'
end
end
describe 'Test Environment' do
let(:settings) { Settings.new("test") }
it "should return 'test' gateway" do
settings.get('gateway').should == 'jira'
end
end
describe 'Production Environment' do
let(:settings) { Settings.new("production") }
it "should return 'jira' gateway" do
settings.get('gateway').should == 'jira'
end
end
end
# implementation file
require 'yaml'
class Settings
def initialize(environment)
@yaml = YAML.load_file(path_to_settings_file)[environment]
end
def get(key)
@yaml[key]
end
private
def path_to_settings_file
File.join(File.dirname(__FILE__), "../../config/settings.yml")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment