ez_config 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -38,7 +38,7 @@ ruby project, and it is not rails specific.
38
38
  })
39
39
  ```
40
40
 
41
- To configure a new service called 'new_service', you will create a YML file in
41
+ To configure a new service called `new_service`, you will create a YML file in
42
42
  your config direcotry. The file has to have an extension of `.yml`. The name of
43
43
  the file will become the config key. This file has to contain at least two
44
44
  environments, `production` and `non_production`:
@@ -67,7 +67,9 @@ file, it will load the default `production` env. This simplifies configuration f
67
67
  projects that may have many a dozen different environments.
68
68
 
69
69
  Lastly, if your cretiria in recognizing `production` and `production` environments differs
70
- from the default, you can pass in `:production_regex` to specify your own cretieria
70
+ from the default, you can pass in `:production_regex` to specify your own cretieria.
71
+ The example below determins whether to use `production` or `non_production` configurations
72
+ by checking if current environment ends with `-prod`
71
73
 
72
74
  ```ruby
73
75
  @config = EzConfig.new({
@@ -75,8 +77,10 @@ from the default, you can pass in `:production_regex` to specify your own cretie
75
77
  :path => "#{Rais.root}/config",
76
78
  :production_regex => /-prod$/
77
79
  })
80
+ ```
78
81
 
79
- == Contributing to ez_config
82
+ Contributing to ez_config
83
+ -------------------------
80
84
 
81
85
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
82
86
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
@@ -86,7 +90,8 @@ from the default, you can pass in `:production_regex` to specify your own cretie
86
90
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
87
91
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
88
92
 
89
- == Copyright
93
+ Copyright
94
+ ---------
90
95
 
91
96
  Copyright (c) 2012 Aaron Qian. See LICENSE.txt for
92
97
  further details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ez_config"
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Qian"]
12
- s.date = "2012-02-06"
12
+ s.date = "2012-02-10"
13
13
  s.description = "ez_config loads yml files from specified path and allows you to easily access your config data."
14
14
  s.email = "aq1018@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -3,14 +3,25 @@ class EzConfig
3
3
 
4
4
  PRODUCTION_REGEX = /^production/
5
5
 
6
- def initialize(opt)
7
- @env = opt[:env].to_s
8
- @path = opt[:path]
6
+ class << self
7
+ def configure(opt={})
8
+ @instance = new(opt)
9
+ end
10
+
11
+ def [](k)
12
+ @instance ||= new
13
+ @instance[k]
14
+ end
15
+ end
16
+
17
+ def initialize(opt={})
18
+ @env = opt[:env].to_s || ENV['RACK_ENV'] || ENV['RAILS_ENV']
19
+ @path = opt[:path] || "#{Dir.pwd}/config/app_config"
9
20
  @production_regex = opt[:production_regex] || PRODUCTION_REGEX
10
21
  end
11
22
 
12
23
  def [](k)
13
- config[k]
24
+ to_hash[k]
14
25
  end
15
26
 
16
27
  def files
@@ -31,6 +42,8 @@ class EzConfig
31
42
 
32
43
  config[key] = val
33
44
  config
34
- end
45
+ end.freeze
35
46
  end
47
+
48
+ alias :to_hash :config
36
49
  end
@@ -28,4 +28,9 @@ describe EzConfig do
28
28
  config = ez_config(:production_west_coast)
29
29
  config['foo']['foo_path'].should == '/path/to/prod_west'
30
30
  end
31
+
32
+ it "should have singleton configure options" do
33
+ EzConfig.configure :env => :test, :path => File.join(File.dirname(__FILE__), 'config')
34
+ EzConfig['foo']['foo_path'].should == '/path/to/dev'
35
+ end
31
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ez_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-06 00:00:00.000000000 Z
12
+ date: 2012-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &19350100 !ruby/object:Gem::Requirement
16
+ requirement: &14966720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.8.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *19350100
24
+ version_requirements: *14966720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yard
27
- requirement: &19349520 !ruby/object:Gem::Requirement
27
+ requirement: &14966140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.7'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *19349520
35
+ version_requirements: *14966140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &19349020 !ruby/object:Gem::Requirement
38
+ requirement: &14965460 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.12'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *19349020
46
+ version_requirements: *14965460
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &19368200 !ruby/object:Gem::Requirement
49
+ requirement: &14964740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.0.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *19368200
57
+ version_requirements: *14964740
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &19367640 !ruby/object:Gem::Requirement
60
+ requirement: &14964180 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.8.3
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *19367640
68
+ version_requirements: *14964180
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
- requirement: &19367120 !ruby/object:Gem::Requirement
71
+ requirement: &14963500 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *19367120
79
+ version_requirements: *14963500
80
80
  description: ez_config loads yml files from specified path and allows you to easily
81
81
  access your config data.
82
82
  email: aq1018@gmail.com
@@ -113,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
113
  version: '0'
114
114
  segments:
115
115
  - 0
116
- hash: -3859281619698538461
116
+ hash: 3088852549082243496
117
117
  required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  none: false
119
119
  requirements: