easy_config 0.9.3 → 1.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d9ca7bdb6f00286ec2c0e94b20f328657abff9e4
4
- data.tar.gz: ac58aa314fb98c77a062f460ccc7f2d86108cf00
3
+ metadata.gz: 20fedbc0060ed810f28d626477c33302a3ad8e15
4
+ data.tar.gz: 7f6a686def31fb1829a7897c15239a2bdd635185
5
5
  SHA512:
6
- metadata.gz: d7a4f8ba08123d2a683db72f435d4186c1929111dfafb4f057f5c97604513af2c8e64301a9ac36aad0b9096856361300bb71176c5d09f48a25f14bd68874e7c7
7
- data.tar.gz: f5c1f454d1b52d14f4b01ecd4ac1a9b2b28c948d1ac054d2ef375c9b21d43d107f45c9639e1d4cc704e06c2f551b5d8d3fcd5b7d6c286512f16b6865242aa882
6
+ metadata.gz: e047d96892658d40ab68843acea9206e30aa75eb5628faefac11ea789eb0230ae9fa55696fd3a7ec9f5b50040e50da24217538c8f820a46d7b7822267d10aa37
7
+ data.tar.gz: 232e16c7e2ddfaa4c72c33ff115cc9345917068e9307ce0469eaa1ca9ce574ba4dfb3a3c70ae04f2466fd1ba71a67c4615ac44619b2c60974257eb278de02c1e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.0.0 - 2014-10-27
2
+
3
+ * Add support for env vars (#4).
4
+ * Add easy support to multiple config paths
5
+
1
6
  ## 0.9.3 - 2014-10-26
2
7
 
3
8
  * Remove methodize dependency.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- easy_config (0.9.2)
4
+ easy_config (1.0.0)
5
5
  erubis
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # Easy config
2
- Rails and Rack applications configuration made easy.
3
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/easy_config.svg)](http://badge.fury.io/rb/easy_config)
4
4
  [![Build Status](https://secure.travis-ci.org/felipecvo/easy_config.png?branch=master)](http://travis-ci.org/felipecvo/easy\_config)
5
5
  [![Code Climate](https://codeclimate.com/github/felipecvo/easy_config/badges/gpa.svg)](https://codeclimate.com/github/felipecvo/easy_config)
6
6
  [![Test Coverage](https://codeclimate.com/github/felipecvo/easy_config/badges/coverage.svg)](https://codeclimate.com/github/felipecvo/easy_config)
7
7
  [![Dependency Status](https://gemnasium.com/felipecvo/easy_config.svg)](https://gemnasium.com/felipecvo/easy_config)
8
8
 
9
- ## Installation
9
+ Rails and Rack applications configuration made easy.
10
10
 
11
- [![Gem Version](https://badge.fury.io/rb/easy_config.svg)](http://badge.fury.io/rb/easy_config)
11
+ ## Install
12
12
 
13
13
  `gem install easy_config`
14
14
 
@@ -16,7 +16,51 @@ or in your Gemfile
16
16
 
17
17
  `gem "easy_config"`
18
18
 
19
- See [Changelog](CHANGELOG.md).
19
+ ## Usage
20
+
21
+ ### Rails/Sinatra
22
+ Inside config dir, create a file redis.yml:
23
+ ```
24
+ development:
25
+ host: 127.0.0.1
26
+ port: 6379
27
+ password:
28
+ production:
29
+ host: 172.0.0.1
30
+ port: 6379
31
+ password: "alpha"
32
+ ```
33
+
34
+ In your ruby code, you do:
35
+ ```ruby
36
+ Redis.current = Redis.new({
37
+ host: EasyConfig.redis.host,
38
+ port: EasyConfig.redis.port,
39
+ password: EasyConfig.redis.password
40
+ })
41
+ ```
42
+
43
+ ### Custom config paths
44
+
45
+ You can provide additional custom config paths.
46
+
47
+ Config file at `vendor/config/sample.yml`:
48
+ ```
49
+ development:
50
+ property: "value"
51
+ ```
52
+ Code:
53
+ ```
54
+ EasyConfig.append_config_path Rails.root.join('vendor/config')
55
+ puts EasyConfig.sample.property
56
+ ```
57
+ Output will be: "value"
58
+
59
+ ### Environment Variables
60
+ ```
61
+ # ENV['APP_API_KEY'] = '1234567890'
62
+ puts EasyConfig.app.api_key
63
+ ```
20
64
 
21
65
  ## How it works
22
66
 
@@ -26,22 +70,12 @@ to put your files in config dir and be a valid YAML file (with .yml as extension
26
70
  If you desire you can split your configurations by environment. Easy config treats it
27
71
  automatically.
28
72
 
29
- ### Example
30
-
31
- We can access database.yml file as:
32
-
33
- `EasyConfig.database.adapter`
34
-
35
- And if you have your our custom config file named my\_customs.yml:
36
-
37
- `EasyConfig.my_customs.custom_var`
38
-
39
73
  ## Supported rubies
40
74
 
41
75
  * 2.1
42
76
  * 2.0
43
77
  * 1.9.3
44
- * ree
78
+ * ree (will be dropped after 1.0)
45
79
 
46
80
  ## License
47
81
 
@@ -0,0 +1,32 @@
1
+ module EasyConfig::EnvVar
2
+ class << self
3
+ def extended(base)
4
+ setup(base)
5
+ end
6
+
7
+ def setup(base)
8
+ env_vars.each do |key, configs|
9
+ create_method(base, key, EasyConfig::Configuration.new(configs))
10
+ end
11
+ end
12
+
13
+ def env_vars
14
+ configs = {}
15
+ ENV.each do |key, value|
16
+ if key.downcase =~ /^([a-zA-Z][^_]+)_(\w+)/
17
+ configs[$1] = configs.fetch($1, {})
18
+ configs[$1][$2] = value
19
+ end
20
+ end
21
+ configs
22
+ end
23
+
24
+ def create_method(base, name, value)
25
+ base.class_eval do
26
+ (class << self; self; end).instance_eval do
27
+ define_method(name.to_sym) { value }
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -30,9 +30,18 @@ module EasyConfig
30
30
  self.reset!
31
31
  end
32
32
 
33
- def reset!
33
+ def append_config_path(path)
34
+ reset if @loaded
35
+ EasyConfig::PathResolver.config_paths << path
36
+ end
37
+
38
+ def reset
34
39
  EasyConfig::ConfigFile.reset!
35
40
  @loaded = false
41
+ end
42
+
43
+ def reset!
44
+ reset
36
45
  setup_config
37
46
  end
38
47
 
@@ -1,3 +1,3 @@
1
1
  module EasyConfig
2
- VERSION = "0.9.3"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/easy_config.rb CHANGED
@@ -3,10 +3,12 @@ require 'easy_config/setup'
3
3
  require 'easy_config/config_file'
4
4
  require 'easy_config/configuration'
5
5
  require 'easy_config/env'
6
+ require 'easy_config/env_var'
6
7
  require 'easy_config/path_resolver'
7
8
 
8
9
  module EasyConfig
9
10
  class ConfigurationNotFound < NoMethodError; end
10
11
 
12
+ extend EnvVar
11
13
  extend Setup
12
14
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe EasyConfig::ConfigFile do
4
- before { EasyConfig::PathResolver.config_paths << './spec/fixtures' }
4
+ before { EasyConfig::PathResolver.config_paths << './spec/fixtures/config' }
5
5
  after { EasyConfig::PathResolver.clear! }
6
6
 
7
7
  context "all files" do
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe EasyConfig::EnvVar do
4
+ class TestEnvVar
5
+ end
6
+
7
+ before do
8
+ ENV['CLOUDAMQP_URL'] = 'amqp://user:pass@ec2.clustername.cloudamqp.com/vhost'
9
+ end
10
+
11
+ it 'has methods to retrieve values' do
12
+ EasyConfig::EnvVar.setup(TestEnvVar)
13
+ TestEnvVar.cloudamqp.url.should eq 'amqp://user:pass@ec2.clustername.cloudamqp.com/vhost'
14
+ end
15
+ end
@@ -1,7 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe EasyConfig do
4
- before { EasyConfig.config_path = File.expand_path('./spec/fixtures') }
4
+ before do
5
+ EasyConfig.reset!
6
+ EasyConfig.append_config_path File.expand_path('./spec/fixtures/config')
7
+ end
5
8
 
6
9
  context "mising methods" do
7
10
  it 'should treat it' do
@@ -42,4 +45,22 @@ describe EasyConfig do
42
45
  subject { EasyConfig.environment }
43
46
  it { should eq "test" }
44
47
  end
48
+
49
+ context "multiple config paths" do
50
+ before do
51
+ EasyConfig.append_config_path File.expand_path('./spec/fixtures/vendor')
52
+ end
53
+
54
+ it "reads from default config path" do
55
+ EasyConfig.redis.host.should eq "localhost"
56
+ end
57
+
58
+ it "reads from additional config path" do
59
+ EasyConfig.twitter.consumer_key.should eq "YOUR_CONSUMER_KEY"
60
+ end
61
+ end
62
+
63
+ it "returns value from environment variables" do
64
+ EasyConfig.app.env.should eq 'dev'
65
+ end
45
66
  end
File without changes
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ development:
2
+ consumer_key: "YOUR_CONSUMER_KEY"
3
+ consumer_secret: "YOUR_CONSUMER_SECRET"
4
+ oauth_token: "YOUR_OAUTH_TOKEN"
5
+ oauth_token_secret: "YOUR_OAUTH_TOKEN_SECRET"
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,8 @@ if RUBY_VERSION > "1.8.7"
4
4
  CodeClimate::TestReporter.start
5
5
  end
6
6
 
7
+ ENV['APP_ENV'] = 'dev'
8
+
7
9
  require 'easy_config'
8
10
 
9
11
  ENV['RACK_ENV'] = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Oliveira
@@ -86,17 +86,20 @@ files:
86
86
  - lib/easy_config/config_file.rb
87
87
  - lib/easy_config/configuration.rb
88
88
  - lib/easy_config/env.rb
89
+ - lib/easy_config/env_var.rb
89
90
  - lib/easy_config/path_resolver.rb
90
91
  - lib/easy_config/setup.rb
91
92
  - lib/easy_config/version.rb
92
93
  - spec/easy_config/config_file_spec.rb
93
94
  - spec/easy_config/configuration_spec.rb
94
95
  - spec/easy_config/env_spec.rb
96
+ - spec/easy_config/env_var_spec.rb
95
97
  - spec/easy_config/path_resolver_spec.rb
96
98
  - spec/easy_config_spec.rb
97
- - spec/fixtures/facebook.yml
98
- - spec/fixtures/github.yml
99
- - spec/fixtures/redis.yml
99
+ - spec/fixtures/config/facebook.yml
100
+ - spec/fixtures/config/github.yml
101
+ - spec/fixtures/config/redis.yml
102
+ - spec/fixtures/vendor/twitter.yml
100
103
  - spec/spec_helper.rb
101
104
  homepage: http://rubygems.org/gems/easy_config
102
105
  licenses: