easy_config 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ script: rspec
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - jruby-18mode
8
+ - jruby-19mode
9
+ - rbx-18mode
10
+ - rbx-19mode
11
+ - ruby-head
12
+ - jruby-head
13
+ - ree
data/Gemfile.lock CHANGED
@@ -1,14 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- easy_config (0.0.1)
4
+ easy_config (0.0.2)
5
5
  methodize (~> 0.2.1)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
10
  diff-lcs (1.1.3)
11
- fakefs (0.4.0)
12
11
  methodize (0.2.1)
13
12
  rake (0.9.2.2)
14
13
  rspec (2.9.0)
@@ -26,6 +25,5 @@ PLATFORMS
26
25
  DEPENDENCIES
27
26
  bundler (>= 1.0.0)
28
27
  easy_config!
29
- fakefs
30
28
  rake
31
29
  rspec (~> 2.9.0)
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Easy config
2
2
  Rails and Rack applications configuration made easy.
3
3
 
4
+ [![Build Status](https://secure.travis-ci.org/felipecvo/easy_config.png?branch=master)](http://travis-ci.org/felipecvo/easy_config)
5
+
4
6
  # Installation
5
7
 
6
8
  `gem install easy-config`
data/lib/easy_config.rb CHANGED
@@ -1,7 +1,40 @@
1
1
  module EasyConfig
2
+ class ConfigurationNotFound < NoMethodError; end
3
+ class UnknownConfigPath < ArgumentError; end
4
+
2
5
  def self.method_missing(name)
3
- file = nil
4
- file.configuration if file = EasyConfig::ConfigFile.all.find { |f| f.name == name }
6
+ unless @loaded
7
+ setup_config
8
+ self.send name
9
+ else
10
+ raise ConfigurationNotFound.new("Configuration for '#{name}' was not found.")
11
+ end
12
+ end
13
+
14
+ def self.setup_config
15
+ EasyConfig::ConfigFile.all.each do |f|
16
+ add_config_method(f)
17
+ end
18
+ @loaded = true
19
+ end
20
+
21
+ def self.add_config_method(config)
22
+ (class << self; self; end).instance_eval do
23
+ define_method config.name do
24
+ config.configuration
25
+ end
26
+ end
27
+ end
28
+
29
+ def self.config_path=(path)
30
+ EasyConfig::PathResolver.config_path = path
31
+ self.reset!
32
+ end
33
+
34
+ def self.reset!
35
+ EasyConfig::ConfigFile.reset!
36
+ @loaded = false
37
+ setup_config
5
38
  end
6
39
  end
7
40
 
@@ -23,4 +23,8 @@ class EasyConfig::ConfigFile
23
23
  EasyConfig::ConfigFile.new path
24
24
  end
25
25
  end
26
+
27
+ def self.reset!
28
+ @all = nil
29
+ end
26
30
  end
@@ -10,6 +10,8 @@ module EasyConfig::PathResolver
10
10
  File.join(Rails.root, 'config', '*.yml')
11
11
  elsif defined?(Sinatra)
12
12
  File.join(Sinatra::Application.root, 'config', '*.yml')
13
+ else
14
+ raise EasyConfig::UnknownConfigPath.new
13
15
  end
14
16
  end
15
17
  end
@@ -1,3 +1,3 @@
1
1
  module EasyConfig
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -11,7 +11,7 @@ describe EasyConfig::ConfigFile do
11
11
  end
12
12
 
13
13
  context "specific file" do
14
- subject { EasyConfig::ConfigFile.all.first }
14
+ subject { EasyConfig::ConfigFile.all.find { |c| c.name == :facebook } }
15
15
  it { should_not be_nil }
16
16
  its(:name) { should eq :facebook }
17
17
  its(:configuration) { should_not be_nil }
@@ -32,5 +32,11 @@ describe EasyConfig::PathResolver do
32
32
  after { Object.send(:remove_const, :Rails) }
33
33
  it { should eq "./config/*.yml" }
34
34
  end
35
+
36
+ context "unknow config path" do
37
+ it "should throw exception" do
38
+ lambda { EasyConfig::PathResolver.config_path }.should raise_error(EasyConfig::UnknownConfigPath)
39
+ end
40
+ end
35
41
  end
36
42
  end
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe EasyConfig do
4
+ before { EasyConfig.config_path = File.expand_path('./spec/fixtures') }
5
+
4
6
  context "mising methods" do
5
7
  it 'should treat it' do
6
8
  lambda { EasyConfig.facebook }.should_not raise_error
@@ -9,17 +11,20 @@ describe EasyConfig do
9
11
 
10
12
  context "access per env config file" do
11
13
  subject { EasyConfig.redis }
14
+ it { should be_a EasyConfig::Configuration }
12
15
  its(:host) { should eq 'localhost' }
13
16
  its(:port) { should eq 4567 }
14
17
  end
15
18
 
16
19
  context "access simle config file" do
17
20
  subject { EasyConfig.github }
21
+ it { should be_a EasyConfig::Configuration }
18
22
  its(:user) { should eq 'felipecvo' }
19
23
  end
20
24
 
21
25
  context "inexistent files" do
22
- subject { EasyConfig.no_exist }
23
- it { should be_nil }
26
+ it 'should throw exception' do
27
+ lambda { EasyConfig.no_exist }.should raise_error(EasyConfig::ConfigurationNotFound)
28
+ end
24
29
  end
25
30
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'bundler/setup'
2
2
  require 'easy_config'
3
- require 'fakefs/spec_helpers'
3
+
4
+ ENV['RACK_ENV'] = nil
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_config
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Felipe Oliveira
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-17 00:00:00 -03:00
19
- default_executable:
18
+ date: 2012-03-17 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: methodize
@@ -90,6 +89,7 @@ extra_rdoc_files: []
90
89
 
91
90
  files:
92
91
  - .gitignore
92
+ - .travis.yml
93
93
  - Gemfile
94
94
  - Gemfile.lock
95
95
  - README.md
@@ -110,7 +110,6 @@ files:
110
110
  - spec/fixtures/github.yml
111
111
  - spec/fixtures/redis.yml
112
112
  - spec/spec_helper.rb
113
- has_rdoc: true
114
113
  homepage: http://rubygems.org/gems/easy_config
115
114
  licenses: []
116
115
 
@@ -142,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
141
  requirements: []
143
142
 
144
143
  rubyforge_project:
145
- rubygems_version: 1.4.2
144
+ rubygems_version: 1.8.19
146
145
  signing_key:
147
146
  specification_version: 3
148
147
  summary: Easy config, Rails and Rack application's configuration made easy.