tarot 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 +4 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +62 -0
- data/Rakefile +3 -0
- data/generators/tarot_generator.rb +12 -0
- data/generators/templates/config.yml +18 -0
- data/generators/templates/initializer.rb +4 -0
- data/lib/tarot.rb +19 -0
- data/lib/tarot/version.rb +3 -0
- data/spec/data/test.yml +12 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/tarot_spec.rb +27 -0
- data/tarot.gemspec +22 -0
- metadata +96 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2011 Chris Heald
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Tarot
|
2
|
+
|
3
|
+
Tarot is a quick, simple, and useful configuration manager for Rails applications. It supports easy-to-use deeply-nested configuration trees, default values, and multiple environments. Tarot leverages YAML to enable DRY configurations, and features I18n-style access to subtrees.
|
4
|
+
|
5
|
+
## Getting Started
|
6
|
+
|
7
|
+
Add Tarot to your gemfile:
|
8
|
+
|
9
|
+
gem "tarot"
|
10
|
+
|
11
|
+
Next, install the Tarot configuration:
|
12
|
+
|
13
|
+
bundle install
|
14
|
+
script/generate tarot
|
15
|
+
|
16
|
+
This installs config/tarot.yml (your primary configuration), and an initializer to help you get up and running quickly.
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Tarot installs a helper method, `config`, with the following signature:
|
21
|
+
|
22
|
+
config(path, default = nil, override_environment = nil)
|
23
|
+
|
24
|
+
Assuming you have a config file like so:
|
25
|
+
|
26
|
+
---
|
27
|
+
base: &base
|
28
|
+
foo: bar
|
29
|
+
nested:
|
30
|
+
tree: value
|
31
|
+
array:
|
32
|
+
- value 1
|
33
|
+
- value 2
|
34
|
+
|
35
|
+
development: &development
|
36
|
+
<<: *base
|
37
|
+
|
38
|
+
test: &test
|
39
|
+
<<: *base
|
40
|
+
|
41
|
+
production: &production
|
42
|
+
<<: *base
|
43
|
+
foo: baz
|
44
|
+
|
45
|
+
You could can access values by key, or by dot-delimited path:
|
46
|
+
|
47
|
+
config('foo') => 'bar'
|
48
|
+
config('nested.tree') => value
|
49
|
+
|
50
|
+
Default values are similarly easy.
|
51
|
+
|
52
|
+
config('foo.missing', 42) => 42
|
53
|
+
|
54
|
+
Finally, while Tarot will read your current application environment's config, if you want to reach into another environment, that's likewise easy:
|
55
|
+
|
56
|
+
config('foo', nil, 'production') => 'baz'
|
57
|
+
|
58
|
+
This lets you build out config files easily while sharing common configuration between environments.
|
59
|
+
|
60
|
+
## Credits
|
61
|
+
|
62
|
+
Tarot was written by Chris Heald (cheald@gmail.com). See LICENSE for license details.
|
data/Rakefile
ADDED
data/lib/tarot.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "tarot/version"
|
2
|
+
require "active_support/core_ext"
|
3
|
+
|
4
|
+
module Tarot
|
5
|
+
class Config
|
6
|
+
attr_accessor :config_file, :yaml, :env
|
7
|
+
def initialize(file, env)
|
8
|
+
@config_file = file
|
9
|
+
@yaml = YAML::load(File.open(file).read.untaint).stringify_keys!
|
10
|
+
@config_cache = {}
|
11
|
+
@env = env
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(key, default = nil, env = @env)
|
15
|
+
@config_cache[env] ||= {}
|
16
|
+
@config_cache[env][key] ||= key.split('.').inject(@yaml[env || @env]) {|e, part| e.try(:[], part) } || default
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/data/test.yml
ADDED
data/spec/spec_helper.rb
ADDED
data/spec/tarot_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Tarot do
|
4
|
+
before :all do
|
5
|
+
@tarot = Tarot::Config.new("spec/data/test.yml", "development")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should load a YAML file" do
|
9
|
+
@tarot.should_not == nil
|
10
|
+
@tarot.yaml.should be_a(Hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should accept a default value for a key" do
|
14
|
+
@tarot.get("bad key").should == nil
|
15
|
+
@tarot.get("bad key", "with default").should == "with default"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should walk a nested tree" do
|
19
|
+
@tarot.get( "nested.tree.with.value" ).should == 42
|
20
|
+
@tarot.get( "nested.tree.with.bad.key" ).should == nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should accept an override environment" do
|
24
|
+
@tarot.get("fizz").should == "buzz"
|
25
|
+
@tarot.get("fizz", nil, "production").should == "bang"
|
26
|
+
end
|
27
|
+
end
|
data/tarot.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "tarot/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "tarot"
|
7
|
+
s.version = Tarot::VERSION
|
8
|
+
s.authors = ["Chris Heald"]
|
9
|
+
s.email = ["cheald@gmail.com"]
|
10
|
+
s.homepage = "http://coffeepowered.net"
|
11
|
+
s.summary = %q{Tarot is a small, concise configuration library for Rails apps.}
|
12
|
+
s.description = %q{Tarot is a small, concise configuration library for Rails apps.}
|
13
|
+
|
14
|
+
s.add_dependency('activesupport')
|
15
|
+
|
16
|
+
s.rubyforge_project = "tarot"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tarot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Chris Heald
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-06-28 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activesupport
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
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
|
+
description: Tarot is a small, concise configuration library for Rails apps.
|
35
|
+
email:
|
36
|
+
- cheald@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- .rspec
|
46
|
+
- Gemfile
|
47
|
+
- LICENSE
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- generators/tarot_generator.rb
|
51
|
+
- generators/templates/config.yml
|
52
|
+
- generators/templates/initializer.rb
|
53
|
+
- lib/tarot.rb
|
54
|
+
- lib/tarot/version.rb
|
55
|
+
- spec/data/test.yml
|
56
|
+
- spec/spec_helper.rb
|
57
|
+
- spec/tarot_spec.rb
|
58
|
+
- tarot.gemspec
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://coffeepowered.net
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project: tarot
|
89
|
+
rubygems_version: 1.6.2
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: Tarot is a small, concise configuration library for Rails apps.
|
93
|
+
test_files:
|
94
|
+
- spec/data/test.yml
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
- spec/tarot_spec.rb
|