tarot 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,10 +8,14 @@ module Tarot
8
8
  @config_files = files
9
9
  @config_files = [@config_files] if @config_files.is_a? String
10
10
  @yaml = {}
11
+ yaml = "---\n" + @config_files.map do |file|
12
+ File.open(file).read.untaint.gsub(/^---.*$/, '')
13
+ end.join("\n")
14
+ @yaml = YAML::load(yaml).stringify_keys!
11
15
  @config_files.each do |file|
12
- yaml = YAML::load(File.open(file).read.untaint).stringify_keys!
13
- recursive_merge @yaml, yaml
14
- end
16
+ yaml = YAML::load(open(file).read).stringify_keys!
17
+ recursive_merge(@yaml, yaml)
18
+ end
15
19
  add_mm @yaml
16
20
  @config_cache = {}
17
21
  @env = env
@@ -22,6 +26,13 @@ module Tarot
22
26
  @config_cache[env][key] ||= key.split('.').inject(@yaml[env || @env]) {|e, part| e.try(:[], part) } || default
23
27
  end
24
28
 
29
+ def with_environment(env)
30
+ old_env, self.env = self.env, env
31
+ yield if block_given?
32
+ self.env = old_env
33
+ nil
34
+ end
35
+
25
36
  private
26
37
 
27
38
  def recursive_merge(left, right)
@@ -1,3 +1,3 @@
1
1
  module Tarot
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  ---
2
2
  development:
3
+ <<: *inclusion
3
4
  foo: fizzle
4
5
  mah: rizzle
@@ -1,4 +1,7 @@
1
1
  ---
2
+ inclusion: &inclusion
3
+ included: true
4
+
2
5
  development: &development
3
6
  foo: bar
4
7
  fizz: buzz
@@ -37,14 +37,29 @@ describe Tarot do
37
37
  it "should fail when method_missing follows a multi-level chain that doesn't exist" do
38
38
  lambda { @tarot.blarg.blaze }.should raise_error(NameError)
39
39
  end
40
+
41
+ it "should accept an override environment as a block" do
42
+ @tarot.with_environment("production") do
43
+ @tarot.env.should == "production"
44
+ @tarot.get("fizz").should == "bang"
45
+ end
46
+ @tarot.env.should == "development"
47
+ end
40
48
  end
41
49
 
42
50
  context "Given multiple config files" do
51
+ before :all do
52
+ @tarot = Tarot::Config.new(["spec/data/test.yml", "spec/data/recursive.yml"], "development")
53
+ end
54
+
43
55
  it "should produce a recursively merged hash when given multiple files to load" do
44
- @tarot = Tarot::Config.new(["spec/data/test.yml", "spec/data/recursive.yml"], "development")
45
56
  @tarot.get("foo").should == "fizzle"
46
57
  @tarot.get("mah").should == "rizzle"
47
58
  @tarot.get("fizz").should == "buzz"
48
59
  end
60
+
61
+ it "should accept YAML inclusions across files" do
62
+ @tarot.get("included").should == true
63
+ end
49
64
  end
50
65
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tarot
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Heald
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-29 00:00:00 -07:00
19
- default_executable:
18
+ date: 2011-07-27 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: activesupport
@@ -58,7 +57,6 @@ files:
58
57
  - spec/spec_helper.rb
59
58
  - spec/tarot_spec.rb
60
59
  - tarot.gemspec
61
- has_rdoc: true
62
60
  homepage: https://github.com/cheald/tarot
63
61
  licenses: []
64
62
 
@@ -88,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
86
  requirements: []
89
87
 
90
88
  rubyforge_project: tarot
91
- rubygems_version: 1.6.2
89
+ rubygems_version: 1.8.6
92
90
  signing_key:
93
91
  specification_version: 3
94
92
  summary: Tarot is a small, concise configuration library for Rails apps.