configreader 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/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm --create use 1.9.2@config_reader
1
+ rvm --create use 1.8.7@config_reader
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- configreader (0.0.1)
4
+ configreader (0.0.2)
5
5
  rails
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
- # ConfigReader 0.0.1 [![Build Status](https://secure.travis-ci.org/TheGiftsProject/configreader.png)](http://travis-ci.org/TheGiftsProject/configreader)
1
+ # ConfigReader 0.0.2 [![Build Status](https://secure.travis-ci.org/TheGiftsProject/configreader.png)](http://travis-ci.org/TheGiftsProject/configreader)
2
2
 
3
3
  ConfigReader provides an easy way to load up your configuration YAML files into Ruby objects,
4
4
  providing a more concise API to access your configuration data, by accessing methods instead of Hash keys. It also
5
5
  allows you to configure environment aware configuration objects, keeping your code DRY.
6
6
 
7
+ You can use it to access your FACEBOOK / ANALYTICS configuration YAML's for instance.
8
+
7
9
  Note: Only the first level YAML keys can be accessed as methods.
8
10
 
9
11
  ## Usage
@@ -17,30 +19,40 @@ Note: The examples are for a Rails 3 app.
17
19
  * The most simple way to use ConfigReader is to change your existing config initializer files to use it
18
20
  like so:
19
21
 
20
- Let's say you have a YAML config like `config/initializers/example.rb`
22
+ Let's say you have a YAML config like `config/facebook.yml`
21
23
  ```yaml
24
+ defaults:
25
+ id: default_id
26
+ secret_key: default_secret_key
22
27
  development:
23
- some_config: 123
28
+ id: 123
29
+ secret_key: secret_key
24
30
  production:
25
- some_config: 456
31
+ id: 456
32
+ secret_key: secret_key
26
33
  test:
27
- some_config: 678
34
+ id: 678
35
+ secret_key: secret_key
28
36
  staging:
29
- some_config: 154
37
+ id: 154
38
+ secret_key: secret_key
30
39
  ```
31
40
 
32
41
  In your config initializer, initialize an EnvConfigReader like so:
33
42
  ```ruby
34
- EXAMPLE = ConfigReader::EnvConfigReader.new("example.yml")
43
+ FACEBOOK = ConfigReader::EnvConfigReader.new("facebook.yml")
35
44
  ```
36
45
 
37
- Then you could access EXAMPLE config from anywhere in your Rails app:
46
+ Then you could access FACEBOOK config from anywhere in your Rails app:
38
47
  ```ruby
39
- EXAMPLE.some_config
48
+ FACEBOOK.id
49
+ FACEBOOK.secret_key
40
50
  ```
41
51
 
42
- Since we are using an EnvConfigReader object, the some_config we asked for is loaded up from the current RAILS_ENVIRONMENT.
52
+ Since we are using an EnvConfigReader object, the FACEBOOK.id key we asked for is loaded up from the current RAILS_ENVIRONMENT.
43
53
  By default, ConfigReader will assume your config folder is your Rails.root/config, and will build the full path using it.
54
+ If the current environment is not specified in the YAML file (for example the demo environment) then EnvConfigReader will use
55
+ the settings nested under the 'defaults' hash. If no 'defaults' hash exist then the EnvConfigReader will raise an exception.
44
56
 
45
57
  There's also a FlatConfigReader, which is the more basic version. it's useful for flat config files like so:
46
58
  ```yaml
@@ -79,7 +91,7 @@ in your Rails app, just like we already did in the initializers.
79
91
  like ConfigReader, so then you'll be able to access them using that object: `ConfigReader::EXAMPLE`
80
92
 
81
93
  `auto_create_config_folder` - The default value to the config_folder is `#{Rails.root}/config/configreader`. Use this config
82
- item to override it another path.
94
+ item to override it to another path.
83
95
 
84
96
  ## Requirements
85
97
 
@@ -1,4 +1,4 @@
1
- require_relative './flat_configreader'
1
+ require File.expand_path('../flat_configreader', __FILE__)
2
2
 
3
3
  module ConfigReader
4
4
 
@@ -8,7 +8,7 @@ module ConfigReader
8
8
 
9
9
  def initialize(file_name)
10
10
  super(file_name)
11
- @data = @data[Rails.env]
11
+ @data = @data[Rails.env] || @data['defaults']
12
12
  raise EnvironmentNotFoundInYaml.new if @data.nil?
13
13
  end
14
14
 
@@ -1,3 +1,3 @@
1
1
  module ConfigReader
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,3 +1,8 @@
1
+ defaults:
2
+ id: defaultID
3
+ appid: defaultAppID
4
+ certid: defaultCertID
5
+
1
6
  test:
2
7
  id: testID
3
8
  devid: devid
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require_relative '../../lib/configreader/env_configreader'
2
+ require File.expand_path('../../../lib/configreader/env_configreader', __FILE__)
3
3
 
4
4
  describe ConfigReader::EnvConfigReader do
5
5
 
@@ -23,14 +23,23 @@ describe ConfigReader::EnvConfigReader do
23
23
  subject.id.should == "testID"
24
24
  end
25
25
 
26
- context "configuration file with out test env" do
27
- it "should raise an EnvironmentNotFoundInYaml when loading" do
26
+ context 'when an environment does not exist in the configuration' do
27
+
28
+ it 'should fallback to default settings if defaults exist' do
29
+ Rails.stub(:env) { 'unknown' }
30
+ config = ConfigReader::EnvConfigReader.new 'fake_env.yml'
31
+
32
+ config.id.should == 'defaultID'
33
+ config.appid.should == 'defaultAppID'
34
+ config.certid.should == 'defaultCertID'
35
+ end
36
+
37
+ it 'should raise an EnvironmentNotFoundInYaml when loading if defaults do not exist' do
28
38
  expect {
29
39
  ConfigReader::EnvConfigReader.new("fake_invalid.yml")
30
40
  }.to raise_error(ConfigReader::EnvConfigReader::EnvironmentNotFoundInYaml)
31
41
  end
32
- end
33
-
34
42
 
43
+ end
35
44
 
36
45
  end
metadata CHANGED
@@ -1,75 +1,78 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: configreader
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Itay Adler
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-11-13 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2013-01-08 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: rails
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
22
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
23
+ requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
31
35
  name: rake
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
39
36
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: rspec
48
- requirement: !ruby/object:Gem::Requirement
37
+ requirement: &id002 !ruby/object:Gem::Requirement
49
38
  none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
54
46
  type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
55
50
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
51
+ requirement: &id003 !ruby/object:Gem::Requirement
57
52
  none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- description: ! "ConfigReader provides an easy way to load up your configuration YAML
63
- files into Ruby objects,\n providing a more concise API to access
64
- your configuration data, by accessing methods instead of Hash keys. It also\n allows
65
- you to configure environment aware configuration objects, and by so inverting the
66
- logic of\n environment specific configuration into the ConfigReader."
67
- email:
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ type: :development
61
+ version_requirements: *id003
62
+ description: |-
63
+ ConfigReader provides an easy way to load up your configuration YAML files into Ruby objects,
64
+ providing a more concise API to access your configuration data, by accessing methods instead of Hash keys. It also
65
+ allows you to configure environment aware configuration objects, and by so inverting the logic of
66
+ environment specific configuration into the ConfigReader.
67
+ email:
68
68
  - itayadler@gmail.com
69
69
  executables: []
70
+
70
71
  extensions: []
72
+
71
73
  extra_rdoc_files: []
72
- files:
74
+
75
+ files:
73
76
  - .gemspec
74
77
  - .gitignore
75
78
  - .rspec
@@ -96,29 +99,38 @@ files:
96
99
  - spec/spec_helper.rb
97
100
  homepage: https://github.com/TheGiftsProject/configreader
98
101
  licenses: []
102
+
99
103
  post_install_message:
100
104
  rdoc_options: []
101
- require_paths:
105
+
106
+ require_paths:
102
107
  - lib
103
- required_ruby_version: !ruby/object:Gem::Requirement
108
+ required_ruby_version: !ruby/object:Gem::Requirement
104
109
  none: false
105
- requirements:
106
- - - ! '>='
107
- - !ruby/object:Gem::Version
108
- version: '0'
109
- required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
118
  none: false
111
- requirements:
112
- - - ! '>='
113
- - !ruby/object:Gem::Version
114
- version: '0'
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
115
126
  requirements: []
127
+
116
128
  rubyforge_project:
117
- rubygems_version: 1.8.24
129
+ rubygems_version: 1.8.17
118
130
  signing_key:
119
131
  specification_version: 3
120
132
  summary: ConfigReader - An easy way to manage your configuration files
121
- test_files:
122
- - spec/lib/config_spec.rb
123
- - spec/lib/env_configreader_spec.rb
133
+ test_files:
124
134
  - spec/lib/flat_configreader_spec.rb
135
+ - spec/lib/env_configreader_spec.rb
136
+ - spec/lib/config_spec.rb