chef_cap 0.3.14 → 0.3.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module ChefCap
2
- VERSION = "0.3.14"
2
+ VERSION = "0.3.15"
3
3
  end
data/recipes/chef_cap.rb CHANGED
@@ -13,6 +13,7 @@ before "chef:setup", "bootstrap:ruby"
13
13
 
14
14
  set :application, ChefDnaParser.parsed["application"]["name"] rescue nil
15
15
  set :repository, ChefDnaParser.parsed["application"]["repository"] rescue nil
16
+ set :default_ruby_version, "1.9.3-p0"
16
17
 
17
18
  ChefCapConfiguration.set_repository_settings
18
19
 
@@ -45,6 +46,9 @@ if ChefDnaParser.parsed["environments"]
45
46
  default_environment["RAILS_ENV"] = rails_env
46
47
 
47
48
  ChefCapHelper.parse_hash(environment_hash)
49
+ merged_environment = ChefDnaParser.parsed["environments"]["defaults"] || {} rescue {}
50
+ environment_hash.each { |k, v| ChefCapHelper.recursive_merge(merged_environment || {}, k, v) }
51
+ set :environment, merged_environment
48
52
 
49
53
  (environment_hash["servers"] || []).each do |server|
50
54
  if server["roles"] && server["hostname"]
@@ -28,7 +28,18 @@ class ChefCapHelper
28
28
  when "Array_Array"
29
29
  hash[key] = hash[key] | value
30
30
  when "Hash_Hash"
31
- hash[key] = hash[key].merge(value)
31
+ hash[key].merge!(value) do |k, oldvalue, newvalue|
32
+ case "#{oldvalue.class}_#{newvalue.class}"
33
+ when "Hash_Hash"
34
+ if oldvalue.has_key?(oldvalue) && newvalue.has_key?(newvalue)
35
+ recursive_merge(oldvalue, k, newvalue)
36
+ else
37
+ oldvalue.merge(newvalue)
38
+ end
39
+ else
40
+ newvalue
41
+ end
42
+ end
32
43
  else
33
44
  hash[key] = value
34
45
  end
data/recipes/rbenv.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  namespace :bootstrap do
2
2
  desc "Create a standalone rbenv installation with a default ruby to use with chef-solo"
3
3
  task :rbenv do
4
- set :ruby_version, (ChefDnaParser.parsed["environment"]["ruby_version"] rescue "1.9.3-p0" || "1.9.3-p0")
4
+ set :ruby_version, default_ruby_version
5
5
  ruby_version.gsub!(/^ruby\-/,'')
6
6
  standup_script = <<-SH
7
7
  #!/bin/bash
data/recipes/rvm.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  namespace :bootstrap do
2
2
  desc "Create a standalone rvm installation with a default ruby to use with chef-solo"
3
3
  task :rvm do
4
- set :ruby_version, (ChefDnaParser.parsed["environment"]["ruby_version"] rescue "ruby-1.9.3-p0" || "ruby-1.9.3-p0")
4
+ set :ruby_version, default_ruby_version
5
5
  if ruby_version =~ /^[0-9]/
6
6
  ruby_version = "ruby-#{ruby_version}"
7
7
  end
@@ -116,6 +116,13 @@ describe ChefCapHelper do
116
116
  resulting_hash["key"].should == { "one" => nil }
117
117
  end
118
118
 
119
+ it "merges hashes recursively" do
120
+ original_hash = {"key" => { "one" => { "two" => "three", "five" => "six" }}}
121
+
122
+ resulting_hash = ChefCapHelper.recursive_merge(original_hash, "key", {"one" => { "two" => "four" }})
123
+ resulting_hash["key"].should == { "one" => { "two" => "four", "five" => "six" } }
124
+ end
125
+
119
126
  it "merge will overwrite hashes with arrays" do
120
127
  original_hash = {"key" => {"array" => ["one"] }}
121
128
 
@@ -128,6 +128,31 @@ describe "chef_cap" do
128
128
  end
129
129
  end
130
130
 
131
+ describe "merging defaults and a specific environment" do
132
+ it "sets the RAILS_ENV to rails_env" do
133
+ @test_dna = <<-ERB
134
+ {
135
+ "chef": {
136
+ "root": "path_to_cookbooks"
137
+ },
138
+ "environments": {
139
+ "defaults": {
140
+ "rails_env": "default",
141
+ "foo": "bar"
142
+ },
143
+ "some_env": {
144
+ "rails_env": "my_env"
145
+ }
146
+ }
147
+ }
148
+ ERB
149
+
150
+ chef_cap.cap_task[:some_env].call
151
+ chef_cap.cap_variable[:environment].should_not be_nil
152
+ chef_cap.cap_variable[:environment]["rails_env"].should == "my_env"
153
+ chef_cap.cap_variable[:environment]["foo"].should == "bar"
154
+ end
155
+ end
131
156
 
132
157
  describe ":repositories" do
133
158
  context "svn" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef_cap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 0.3.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-29 00:00:00.000000000 Z
12
+ date: 2012-03-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
16
- requirement: &2243595100 !ruby/object:Gem::Requirement
16
+ requirement: &70301691251260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.5.5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2243595100
24
+ version_requirements: *70301691251260
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec-rails
27
- requirement: &2243594600 !ruby/object:Gem::Requirement
27
+ requirement: &70301691250760 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '2.1'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2243594600
35
+ version_requirements: *70301691250760
36
36
  description: chef_cap uses chef"s JSON config format to drive both capistrano and
37
37
  chef-solo"
38
38
  email:
@@ -93,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  segments:
95
95
  - 0
96
- hash: 3296026032842137277
96
+ hash: 855178474274855074
97
97
  required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  none: false
99
99
  requirements:
@@ -102,10 +102,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  segments:
104
104
  - 0
105
- hash: 3296026032842137277
105
+ hash: 855178474274855074
106
106
  requirements: []
107
107
  rubyforge_project:
108
- rubygems_version: 1.8.15
108
+ rubygems_version: 1.8.17
109
109
  signing_key:
110
110
  specification_version: 3
111
111
  summary: capistrano + chef-solo == chef_cap"