tarot 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+ gemspec
3
+ gem 'rspec'
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
@@ -0,0 +1,3 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new('spec')
@@ -0,0 +1,12 @@
1
+ require "rails_generator"
2
+
3
+ module Tarot
4
+ class TarotGenerator < Rails::Generator::Base
5
+ def manifest
6
+ record do |m|
7
+ m.file 'initializer.rb', 'config/initializers/tarot.rb'
8
+ m.file 'config.yml', 'config/tarot.yml'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ ---
2
+
3
+ base: &base
4
+ foo: bar
5
+ nested:
6
+ tree: value
7
+ array:
8
+ - value 1
9
+ - value 2
10
+
11
+ development: &development
12
+ <<: *base
13
+
14
+ test: &test
15
+ <<: *base
16
+
17
+ production: &production
18
+ <<: *base
@@ -0,0 +1,4 @@
1
+ TAROT = Tarot::Config.new(File.join(Rails.root, "config", "tarot.yml"), Rails.env)
2
+ def config *args
3
+ TAROT.get *args
4
+ end
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
@@ -0,0 +1,3 @@
1
+ module Tarot
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,12 @@
1
+ ---
2
+ development: &development
3
+ foo: bar
4
+ fizz: buzz
5
+ nested:
6
+ tree:
7
+ with:
8
+ value: 42
9
+
10
+ production: &production
11
+ <<: *development
12
+ fizz: bang
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'tarot'
4
+
5
+ RSpec.configure do |config|
6
+ end
@@ -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