app_configuration 0.0.1
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/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +144 -0
- data/Rakefile +1 -0
- data/app_configuration.gemspec +22 -0
- data/lib/app_configuration/config.rb +75 -0
- data/lib/app_configuration/config_registry.rb +22 -0
- data/lib/app_configuration/optional_attr.rb +41 -0
- data/lib/app_configuration/version.rb +3 -0
- data/lib/app_configuration.rb +13 -0
- data/spec/app_configuration/config_spec.rb +118 -0
- data/spec/app_configuration/optional_attr_spec.rb +60 -0
- data/spec/app_configuration_spec.rb +24 -0
- data/spec/fixtures/global/config.yml +2 -0
- data/spec/fixtures/local/config.yml +2 -0
- data/spec/spec_helper.rb +19 -0
- metadata +109 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Guido Marucci Blas
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
# AppConfiguration
|
2
|
+
|
3
|
+
[](https://travis-ci.org/guidomb/app_configuration)
|
4
|
+
[](https://coveralls.io/r/guidomb/app_configuration)
|
5
|
+
<a href="/github/guidomb/app_configuration/badges"><img alt="App_configuration" src="https://codeclimate.com/github/guidomb/app_configuration.png" style="position: relative; top: 4px"></a>
|
6
|
+
|
7
|
+
**AppConfiguration** is a very simple gem that helps you configure your Ruby applications. It was extracted from a Rails project
|
8
|
+
but it also can be used in non Rails projects. **AppConfiguration** uses YAML config files or environmental variales to set
|
9
|
+
the configuration parameters.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'app_configuration'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install app_configuration
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
**AppConfiguration** comes with great default values. So if you want to setup a new config all you need to do is
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
config = AppConfiguration.new
|
31
|
+
my_configurable_variable = config.foo
|
32
|
+
my_other_variable = config['bar']
|
33
|
+
```
|
34
|
+
|
35
|
+
By default, when getting the variable `foo` **AppConfiguration** will look for the environmental variable `FOO`.
|
36
|
+
If it cannot find it, **AppConfiguration** will look for the `.config.yml` file in the current working directory.
|
37
|
+
If there is no config file there, it will try to find the `.config.yml` in your home directory.
|
38
|
+
|
39
|
+
A possible `.config.yml` for this example could look like this
|
40
|
+
|
41
|
+
```yaml
|
42
|
+
foo: 'This is the foo variable'
|
43
|
+
bar: 'This is the bar variable'
|
44
|
+
```
|
45
|
+
|
46
|
+
### Customize your configuration ###
|
47
|
+
|
48
|
+
**AppConfiguration** can be customized to fit your needs. Here is an example
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
config = AppConfiguration.new('.setup.yml') do
|
52
|
+
base_local_path '/usr/local'
|
53
|
+
base_global_path '/config'
|
54
|
+
use_env_variables true
|
55
|
+
prefix 'my_app'
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
You can set the configuration file name by passing the name to the new method or you can use the `config_file_name`
|
60
|
+
method inside the configuration block.
|
61
|
+
|
62
|
+
* `config_file_name` Sets the name of the config file. Default `.config.yml`.
|
63
|
+
* `base_local_path` Sets the base path for the local configuration file. If there is no config file in this path it will
|
64
|
+
look in the global configuration path. Default `./`
|
65
|
+
* `base_global_path` Sets the base path for the global configuration file. Default `~/`
|
66
|
+
* `use_env_variables` Flag that activates the use of enviromental variable. Default `true`
|
67
|
+
* `prefix` A prefix to be appended when looking for environmental variables. For example if `prefix` is set to `my_app`,
|
68
|
+
when the `foo` variable is fetched, the `MY_APP_FOO` environmental variable will be checked.
|
69
|
+
This is used to avoid name collitions. Default `nil`
|
70
|
+
|
71
|
+
### Variable lookup ###
|
72
|
+
|
73
|
+
You can retrieve a variable from a `AppConfiguration::Config` object by doing
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
foo = config.foo
|
77
|
+
foo = config['foo']
|
78
|
+
```
|
79
|
+
|
80
|
+
Environmental variables will be checked first, adding the necesary prefix if provided. If there is no environmental
|
81
|
+
variable, the local config file will be checked. If there is no local file or a value has not been defined for
|
82
|
+
the given variable, the global config file will be checked. Otherwise it returns nil.
|
83
|
+
|
84
|
+
### Configuration registry ###
|
85
|
+
|
86
|
+
If you create a new config object by using `AppConfiguration.new`, then you must keep the reference to this configuration.
|
87
|
+
Instead you can registers a configuration by using `AppConfiguration.for`. Then you can obtain a configuration by using
|
88
|
+
`AppConfiguration[]`. For example
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
AppConfiguration.for :github
|
92
|
+
# ... Then somewhere else ...
|
93
|
+
github = AppConfiguration[:github]
|
94
|
+
github.api_key
|
95
|
+
```
|
96
|
+
|
97
|
+
In the previous example the name of the configuration file is assumed to be `.github.yml` and all the environmental variables
|
98
|
+
will be prefixed with `GITHUB_`. You can change this behaviour by passing a configuration block to the `for` method.
|
99
|
+
|
100
|
+
### Default values ###
|
101
|
+
|
102
|
+
To change the default local path and the default global path for all the `AppConfiguration::Config` objects all you
|
103
|
+
need to do is
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
AppConfiguration::Config.default_local_path = Rails.root
|
107
|
+
AppConfiguration::Config.default_global_path = '/usr/configs'
|
108
|
+
```
|
109
|
+
|
110
|
+
## Contributing
|
111
|
+
|
112
|
+
1. Fork it
|
113
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
114
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
115
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
116
|
+
5. Create new Pull Request
|
117
|
+
|
118
|
+
Please add specs for all new features. If you find a bug and an spec probing that the bug exists and in a separate commit
|
119
|
+
add the bug fix.
|
120
|
+
|
121
|
+
## License
|
122
|
+
|
123
|
+
Copyright (c) 2013 Guido Marucci Blas
|
124
|
+
|
125
|
+
MIT License
|
126
|
+
|
127
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
128
|
+
a copy of this software and associated documentation files (the
|
129
|
+
"Software"), to deal in the Software without restriction, including
|
130
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
131
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
132
|
+
permit persons to whom the Software is furnished to do so, subject to
|
133
|
+
the following conditions:
|
134
|
+
|
135
|
+
The above copyright notice and this permission notice shall be
|
136
|
+
included in all copies or substantial portions of the Software.
|
137
|
+
|
138
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
139
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
140
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
141
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
142
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
143
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
144
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'app_configuration/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "app_configuration"
|
8
|
+
gem.version = AppConfiguration::VERSION
|
9
|
+
gem.authors = ["Guido Marucci Blas"]
|
10
|
+
gem.email = ["guidomb@gmail.com"]
|
11
|
+
gem.description = %q{A gem to handle ruby application configurations using both YAML config files or environmental variables}
|
12
|
+
gem.summary = %q{A gem to handle ruby application configurations}
|
13
|
+
gem.homepage = "http://github.com/guidomb/app_configuration"
|
14
|
+
|
15
|
+
gem.add_development_dependency "rspec"
|
16
|
+
gem.add_development_dependency "rake"
|
17
|
+
|
18
|
+
gem.files = `git ls-files`.split($/)
|
19
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
21
|
+
gem.require_paths = ["lib"]
|
22
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module AppConfiguration
|
4
|
+
|
5
|
+
class Config
|
6
|
+
include OptionalAttr
|
7
|
+
|
8
|
+
optional_attr :config_file_name, default: '.config.yml'
|
9
|
+
optional_attr :base_local_path, default: './'
|
10
|
+
optional_attr :base_global_path, default: '~/'
|
11
|
+
optional_attr :use_env_variables, default: true
|
12
|
+
optional_attr :prefix
|
13
|
+
|
14
|
+
# Class Methods
|
15
|
+
|
16
|
+
class << self
|
17
|
+
|
18
|
+
def default_local_path=(default_local_path)
|
19
|
+
defaults[:base_local_path] = default_local_path
|
20
|
+
end
|
21
|
+
|
22
|
+
def default_global_path=(default_global_path)
|
23
|
+
defaults[:base_global_path] = default_global_path
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
# Instance Methods
|
29
|
+
|
30
|
+
def initialize(config_file_name, &block)
|
31
|
+
super() # Sets default values for optional attributes
|
32
|
+
@config_file_name = config_file_name
|
33
|
+
self.instance_eval(&block) if block_given?
|
34
|
+
end
|
35
|
+
|
36
|
+
def local_config_path
|
37
|
+
@local_config_path ||= config_path(@base_local_path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def global_config_path
|
41
|
+
@global_config_path ||= config_path(@base_global_path)
|
42
|
+
end
|
43
|
+
|
44
|
+
def [](name)
|
45
|
+
env_name = ''
|
46
|
+
env_name << "#{@prefix.upcase}_" if @prefix
|
47
|
+
env_name << name.to_s.upcase
|
48
|
+
if @use_env_variables && ENV[env_name]
|
49
|
+
ENV[env_name]
|
50
|
+
else
|
51
|
+
config[name]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def method_missing(method, *args, &block)
|
56
|
+
self[method]
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def config
|
62
|
+
return @config if @config
|
63
|
+
|
64
|
+
@config = {}
|
65
|
+
@config.merge!(YAML.load_file(global_config_path)) if File.exist?(global_config_path)
|
66
|
+
@config.merge!(YAML.load_file(local_config_path)) if File.exist?(local_config_path)
|
67
|
+
@config
|
68
|
+
end
|
69
|
+
|
70
|
+
def config_path(base_path)
|
71
|
+
File.expand_path(File.join(base_path, @config_file_name))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module AppConfiguration
|
2
|
+
|
3
|
+
module ConfigRegistry
|
4
|
+
|
5
|
+
def for(config, &block)
|
6
|
+
@configs[config] = new(".#{config}.yml") do
|
7
|
+
prefix config
|
8
|
+
block.call if block
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def [](config)
|
13
|
+
@configs[config]
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.extended(object)
|
17
|
+
object.instance_variable_set("@configs", {})
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module AppConfiguration
|
2
|
+
|
3
|
+
module OptionalAttr
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
def defaults
|
8
|
+
@defaults ||= {}
|
9
|
+
end
|
10
|
+
protected :defaults
|
11
|
+
|
12
|
+
def optional_attr(attribute, options = {})
|
13
|
+
define_method(attribute) do |value|
|
14
|
+
instance_variable_set("@#{attribute}", value)
|
15
|
+
end
|
16
|
+
|
17
|
+
defaults[attribute] = options[:default] if options[:default]
|
18
|
+
end
|
19
|
+
protected :optional_attr
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
module InstanceMethods
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
self.class.send(:defaults).each do |attribute, value|
|
27
|
+
instance_variable_set("@#{attribute}", value)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.included(receiver)
|
34
|
+
receiver.extend ClassMethods
|
35
|
+
receiver.send :include, InstanceMethods
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "app_configuration/version"
|
2
|
+
require "app_configuration/optional_attr"
|
3
|
+
require "app_configuration/config_registry"
|
4
|
+
require "app_configuration/config"
|
5
|
+
|
6
|
+
module AppConfiguration
|
7
|
+
extend ConfigRegistry
|
8
|
+
|
9
|
+
def self.new(config_file_name, &block)
|
10
|
+
Config.new(config_file_name, &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AppConfiguration::Config do
|
4
|
+
|
5
|
+
describe "#[]" do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
AppConfiguration::Config.default_local_path = File.join(fixture_path, 'local')
|
9
|
+
AppConfiguration::Config.default_global_path = File.join(fixture_path, 'global')
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:all) do
|
13
|
+
AppConfiguration::Config.default_local_path = nil
|
14
|
+
AppConfiguration::Config.default_global_path = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when there is only a global config file" do
|
18
|
+
|
19
|
+
let(:config) do
|
20
|
+
AppConfiguration::Config.new('config.yml') do
|
21
|
+
base_local_path ''
|
22
|
+
use_env_variables false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns the resquested config parameter value' do
|
27
|
+
config['variable1'].should eq 'global1'
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when there is only a local config file" do
|
33
|
+
|
34
|
+
let(:config) do
|
35
|
+
AppConfiguration::Config.new('config.yml') do
|
36
|
+
base_global_path ''
|
37
|
+
use_env_variables false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns the resquested config parameter value' do
|
42
|
+
config['variable1'].should eq 'local1'
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when there are local and global config files" do
|
48
|
+
|
49
|
+
let(:config) do
|
50
|
+
AppConfiguration::Config.new('config.yml') do
|
51
|
+
use_env_variables false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns the local config parameter value' do
|
56
|
+
config['variable1'].should eq 'local1'
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when environmental variables config parameters exists" do
|
62
|
+
|
63
|
+
before(:each) do
|
64
|
+
ENV.stub(:[]).with("VARIABLE1").and_return("env1")
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when use_env_variables is set to false" do
|
68
|
+
|
69
|
+
let(:config) do
|
70
|
+
AppConfiguration::Config.new('config.yml') do
|
71
|
+
use_env_variables false
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'returns the local config parameter value' do
|
76
|
+
config['variable1'].should eq 'local1'
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
context "when use_env_variables is set to true" do
|
82
|
+
|
83
|
+
let(:config) do
|
84
|
+
AppConfiguration::Config.new('config.yml') do
|
85
|
+
use_env_variables true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'returns the environmental variable config parameter value' do
|
90
|
+
config['variable1'].should eq 'env1'
|
91
|
+
end
|
92
|
+
|
93
|
+
context "when a prefix is set" do
|
94
|
+
|
95
|
+
before(:each) do
|
96
|
+
ENV.stub(:[]).with("THE_PREFIX_VARIABLE1").and_return("env1")
|
97
|
+
end
|
98
|
+
|
99
|
+
let(:config) do
|
100
|
+
AppConfiguration::Config.new('config.yml') do
|
101
|
+
use_env_variables true
|
102
|
+
prefix 'the_prefix'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'returns the environmental variable config parameter value' do
|
107
|
+
config['variable1'].should eq 'env1'
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AppConfiguration::OptionalAttr do
|
4
|
+
|
5
|
+
context 'when included into a class' do
|
6
|
+
|
7
|
+
let(:klass) { Class.new { include AppConfiguration::OptionalAttr } }
|
8
|
+
|
9
|
+
it 'defines the optional_attr method' do
|
10
|
+
klass.respond_to?(:optional_attr, true).should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".optional_attr" do
|
14
|
+
|
15
|
+
context "when invoked for the attribute 'foo'" do
|
16
|
+
|
17
|
+
before do
|
18
|
+
klass.class_eval { optional_attr :foo }
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:instance) do
|
22
|
+
klass.new
|
23
|
+
end
|
24
|
+
|
25
|
+
it "defines the 'foo' public method" do
|
26
|
+
instance.should respond_to(:foo).with(1).argument
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#foo" do
|
30
|
+
|
31
|
+
it "sets the instance variable @foo with the given value" do
|
32
|
+
instance.foo 1
|
33
|
+
instance.instance_variable_get("@foo").should be 1
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when invoked for the attribute 'bar' with default option value '1'" do
|
41
|
+
|
42
|
+
before do
|
43
|
+
klass.class_eval { optional_attr :bar, default: 1 }
|
44
|
+
end
|
45
|
+
|
46
|
+
let(:instance) do
|
47
|
+
klass.new
|
48
|
+
end
|
49
|
+
|
50
|
+
it "sets the instance variable @bar with the default value" do
|
51
|
+
instance.instance_variable_get("@bar").should eq 1
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AppConfiguration do
|
4
|
+
|
5
|
+
describe ".for" do
|
6
|
+
|
7
|
+
let(:config_name) { :spec }
|
8
|
+
before(:each) { AppConfiguration.for(config_name) }
|
9
|
+
|
10
|
+
it 'registers a new Config object' do
|
11
|
+
AppConfiguration[config_name].should_not be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'sets the config_file_name attribute based on the config name' do
|
15
|
+
AppConfiguration[config_name].instance_variable_get("@config_file_name").should eq ".#{config_name}.yml"
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'sets the prefix attribute based on the config name' do
|
19
|
+
AppConfiguration[config_name].instance_variable_get("@prefix").should eq config_name
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'coveralls'
|
3
|
+
|
4
|
+
require 'app_configuration'
|
5
|
+
|
6
|
+
module Helpers
|
7
|
+
|
8
|
+
def fixture_path
|
9
|
+
File.expand_path(File.join('.', 'spec', 'fixtures'))
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
Coveralls.wear!
|
15
|
+
RSpec.configure do |config|
|
16
|
+
|
17
|
+
config.include(Helpers)
|
18
|
+
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: app_configuration
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Guido Marucci Blas
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
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
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: A gem to handle ruby application configurations using both YAML config
|
47
|
+
files or environmental variables
|
48
|
+
email:
|
49
|
+
- guidomb@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- .rspec
|
56
|
+
- .travis.yml
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE.txt
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- app_configuration.gemspec
|
62
|
+
- lib/app_configuration.rb
|
63
|
+
- lib/app_configuration/config.rb
|
64
|
+
- lib/app_configuration/config_registry.rb
|
65
|
+
- lib/app_configuration/optional_attr.rb
|
66
|
+
- lib/app_configuration/version.rb
|
67
|
+
- spec/app_configuration/config_spec.rb
|
68
|
+
- spec/app_configuration/optional_attr_spec.rb
|
69
|
+
- spec/app_configuration_spec.rb
|
70
|
+
- spec/fixtures/global/config.yml
|
71
|
+
- spec/fixtures/local/config.yml
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
homepage: http://github.com/guidomb/app_configuration
|
74
|
+
licenses: []
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
hash: 3752812428979833115
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
hash: 3752812428979833115
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.8.23
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: A gem to handle ruby application configurations
|
103
|
+
test_files:
|
104
|
+
- spec/app_configuration/config_spec.rb
|
105
|
+
- spec/app_configuration/optional_attr_spec.rb
|
106
|
+
- spec/app_configuration_spec.rb
|
107
|
+
- spec/fixtures/global/config.yml
|
108
|
+
- spec/fixtures/local/config.yml
|
109
|
+
- spec/spec_helper.rb
|