easy_config 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +13 -0
- data/Gemfile.lock +1 -3
- data/README.md +2 -0
- data/lib/easy_config.rb +35 -2
- data/lib/easy_config/config_file.rb +4 -0
- data/lib/easy_config/path_resolver.rb +2 -0
- data/lib/easy_config/version.rb +1 -1
- data/spec/easy_config/config_file_spec.rb +1 -1
- data/spec/easy_config/path_resolver_spec.rb +6 -0
- data/spec/easy_config_spec.rb +7 -2
- data/spec/spec_helper.rb +2 -1
- metadata +6 -7
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
easy_config (0.0.
|
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
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
|
-
|
4
|
-
|
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
|
|
data/lib/easy_config/version.rb
CHANGED
@@ -11,7 +11,7 @@ describe EasyConfig::ConfigFile do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
context "specific file" do
|
14
|
-
subject { EasyConfig::ConfigFile.all.
|
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
|
data/spec/easy_config_spec.rb
CHANGED
@@ -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
|
-
|
23
|
-
|
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
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:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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
|
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.
|
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.
|