config_spartan 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +66 -0
- data/Rakefile +2 -0
- data/config_spartan.gemspec +20 -0
- data/lib/config_spartan.rb +27 -0
- data/lib/config_spartan/version.rb +3 -0
- data/spec/basic_spec.rb +30 -0
- data/spec/config1.yml +5 -0
- data/spec/config2.yml +9 -0
- data/spec/spec_helper.rb +14 -0
- metadata +99 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Christopher J. Bottaro
|
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,66 @@
|
|
1
|
+
# ConfigSpartan
|
2
|
+
|
3
|
+
Ultra simple application configuration (app config) gem with the
|
4
|
+
following features:
|
5
|
+
* YAML config files
|
6
|
+
* ERB support in config files
|
7
|
+
* Inheritance
|
8
|
+
* Object member notation to access config options
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'config_spartan'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install config_spartan
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
If you are using in a Rails app, you can do something like this...
|
27
|
+
|
28
|
+
# config/base.yml
|
29
|
+
app_name: MyCoolApp
|
30
|
+
domain: mycoolapp.com
|
31
|
+
lib_dir: <%= Rails.root + "/lib" %>
|
32
|
+
aws:
|
33
|
+
access_key: 123ABC
|
34
|
+
secret_key: ABC123
|
35
|
+
|
36
|
+
# config/development.yml
|
37
|
+
domain: dev.mycoolapp.com
|
38
|
+
|
39
|
+
# app/models/app_config.rb
|
40
|
+
AppConfig = ConfigSpartan.create do
|
41
|
+
file "#{Rails.root}/config/base.yml"
|
42
|
+
file "#{Rails.root}/config/#{Rails.env}.yml"
|
43
|
+
end
|
44
|
+
|
45
|
+
In `ConfigSpartan.create`, you can call `file` as many times as you
|
46
|
+
want. Each time, the configuration options from that file will be deep
|
47
|
+
merged into the existing configuration object.
|
48
|
+
|
49
|
+
Now fire up a Rails console (using the development environment)...
|
50
|
+
|
51
|
+
> AppConfig.lib_dir
|
52
|
+
=> "/Users/cjbottaro/my_cool_app/lib"
|
53
|
+
> AppConfig.aws.access_key
|
54
|
+
=> "123ABC"
|
55
|
+
> AppConfig["aws"]["secret_key"]
|
56
|
+
=> "ABC123"
|
57
|
+
> AppConfig.domain
|
58
|
+
=> "dev.mycoolapp.com"
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
1. Fork it
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
65
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/config_spartan/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Christopher J. Bottaro"]
|
6
|
+
gem.email = ["cjbottaro@alumni.cs.utexas.edu"]
|
7
|
+
gem.description = %q{Super simple application configuration gem}
|
8
|
+
gem.summary = %q{Ultra simple application configuration gem}
|
9
|
+
gem.homepage = "https://github.com/cjbottaro/config_spartan"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "config_spartan"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = ConfigSpartan::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency "hashie"
|
19
|
+
gem.add_development_dependency "rspec"
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "erb"
|
2
|
+
require "yaml"
|
3
|
+
require "hashie"
|
4
|
+
|
5
|
+
require "config_spartan/version"
|
6
|
+
|
7
|
+
class ConfigSpartan
|
8
|
+
|
9
|
+
attr_reader :config
|
10
|
+
|
11
|
+
def self.create(&block)
|
12
|
+
new.tap{ |spartan| spartan.instance_eval(&block) }.config
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@config = Hashie::Mash.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def file(path)
|
20
|
+
data = File.read(path)
|
21
|
+
yaml = ERB.new(data).result
|
22
|
+
hash = YAML.load(yaml)
|
23
|
+
mash = Hashie::Mash.new(hash)
|
24
|
+
@config.deep_merge!(mash)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/spec/basic_spec.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ConfigSpartan do
|
4
|
+
|
5
|
+
context ".create" do
|
6
|
+
|
7
|
+
it "works with a single file" do
|
8
|
+
config = ConfigSpartan.create{ file("spec/config1.yml") }
|
9
|
+
config.host.should == "dev.something.com"
|
10
|
+
config.urls.should == %w[www.google.com www.yahoo.com]
|
11
|
+
config[:count].should == 11
|
12
|
+
end
|
13
|
+
|
14
|
+
it "merges multiple files" do
|
15
|
+
config = ConfigSpartan.create do
|
16
|
+
file "spec/config1.yml"
|
17
|
+
file "spec/config2.yml"
|
18
|
+
end
|
19
|
+
|
20
|
+
config.host.should == "prod.something.com"
|
21
|
+
config.urls.should == %w[www.bing.com www.cuil.com]
|
22
|
+
config[:count].should == 11
|
23
|
+
config.nest.something.should == "blah"
|
24
|
+
config.nest.name.fname.should == "coco"
|
25
|
+
config.nest.name.lname.should == "bottaro"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/spec/config1.yml
ADDED
data/spec/config2.yml
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rspec'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
|
+
require 'config_spartan'
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: config_spartan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christopher J. Bottaro
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: hashie
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
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: rspec
|
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: Super simple application configuration gem
|
47
|
+
email:
|
48
|
+
- cjbottaro@alumni.cs.utexas.edu
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- config_spartan.gemspec
|
59
|
+
- lib/config_spartan.rb
|
60
|
+
- lib/config_spartan/version.rb
|
61
|
+
- spec/basic_spec.rb
|
62
|
+
- spec/config1.yml
|
63
|
+
- spec/config2.yml
|
64
|
+
- spec/spec_helper.rb
|
65
|
+
homepage: https://github.com/cjbottaro/config_spartan
|
66
|
+
licenses: []
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
hash: 1129902186988447237
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
hash: 1129902186988447237
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.8.23
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: Ultra simple application configuration gem
|
95
|
+
test_files:
|
96
|
+
- spec/basic_spec.rb
|
97
|
+
- spec/config1.yml
|
98
|
+
- spec/config2.yml
|
99
|
+
- spec/spec_helper.rb
|