Created
May 29, 2011 02:19
-
-
Save liammclennan/997399 to your computer and use it in GitHub Desktop.
settings service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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