soloist 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,14 +2,17 @@ require 'yaml'
2
2
 
3
3
  module Soloist
4
4
  class Soloist::ChefConfigGenerator
5
+ include Soloist::Util
6
+
5
7
  def initialize(config, relative_path_to_soloistrc)
6
8
  @recipes = []
7
9
  @cookbook_paths = []
10
+ @cookbook_gems = []
8
11
  @preserved_environment_variables = %w{PATH BUNDLE_PATH GEM_HOME GEM_PATH RAILS_ENV RACK_ENV}
9
12
  merge_config(config, relative_path_to_soloistrc)
10
13
  end
11
14
 
12
- attr_reader :preserved_environment_variables, :cookbook_paths
15
+ attr_reader :preserved_environment_variables, :cookbook_paths, :cookbook_gems
13
16
  attr_accessor :recipes
14
17
 
15
18
  def support_old_format(hash)
@@ -32,6 +35,9 @@ module Soloist
32
35
  if sub_hash["cookbook_paths"]
33
36
  @cookbook_paths = (@cookbook_paths + append_path(sub_hash["cookbook_paths"], relative_path_to_soloistrc)).uniq
34
37
  end
38
+ if sub_hash["cookbook_gems"]
39
+ (@cookbook_gems += sub_hash["cookbook_gems"]).uniq!
40
+ end
35
41
  if sub_hash["env_variable_switches"]
36
42
  merge_env_variable_switches(sub_hash["env_variable_switches"], relative_path_to_soloistrc)
37
43
  end
@@ -48,7 +54,12 @@ module Soloist
48
54
  end
49
55
 
50
56
  def solo_rb
51
- "cookbook_path #{cookbook_paths.inspect}"
57
+ all_cookbook_paths = cookbook_paths
58
+ cookbook_gems.each do |gem_cookbook|
59
+ Kernel.require gem_cookbook
60
+ all_cookbook_paths << Kernel.const_get(camelize(gem_cookbook)).const_get('COOKBOOK_PATH')
61
+ end
62
+ "cookbook_path #{all_cookbook_paths.inspect}"
52
63
  end
53
64
 
54
65
  def json_hash
data/lib/soloist/util.rb CHANGED
@@ -30,5 +30,12 @@ module Soloist
30
30
  raise Errno::ENOENT, "#{filenames.join(" or ")} not found" unless file || opts[:required] == false
31
31
  end
32
32
  end
33
+
34
+ # stolen from activesupport
35
+ def camelize(term)
36
+ string = term.to_s
37
+ string = string.sub(/^[a-z\d]*/) { $&.capitalize }
38
+ string.gsub(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
39
+ end
33
40
  end
34
41
  end
@@ -1,3 +1,3 @@
1
1
  module Soloist
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
data/lib/soloist.rb CHANGED
@@ -4,6 +4,6 @@ require 'fileutils'
4
4
  require 'yaml'
5
5
  require 'tempfile'
6
6
 
7
- require File.join(File.dirname(__FILE__), 'soloist', 'chef_config_generator')
8
7
  require File.join(File.dirname(__FILE__), 'soloist', 'util')
8
+ require File.join(File.dirname(__FILE__), 'soloist', 'chef_config_generator')
9
9
 
@@ -7,6 +7,8 @@ describe Soloist::ChefConfigGenerator do
7
7
  @config = <<-CONFIG
8
8
  Cookbook_Paths:
9
9
  - ./chef/cookbooks/
10
+ cookbook_gems:
11
+ - pivotal_workstation_cookbook
10
12
  Recipes:
11
13
  - pivotal_workstation::ack
12
14
  CONFIG
@@ -26,7 +28,11 @@ CONFIG
26
28
  end
27
29
 
28
30
  it "can generate a solo.rb contents" do
29
- @generator.solo_rb.should == 'cookbook_path ["/current/working/directory/../.././chef/cookbooks/"]'
31
+ module ::PivotalWorkstationCookbook
32
+ COOKBOOK_PATH = "/var/lib/ruby/gems/pivotal_workstation/cookbooks/"
33
+ end
34
+ Kernel.stub!(:require).with("pivotal_workstation_cookbook").and_return(true)
35
+ @generator.solo_rb.should == 'cookbook_path ["/current/working/directory/../.././chef/cookbooks/", "/var/lib/ruby/gems/pivotal_workstation/cookbooks/"]'
30
36
  end
31
37
 
32
38
  it "can generate the json contents" do
@@ -134,6 +140,24 @@ env_variable_switches:
134
140
  ]
135
141
  end
136
142
 
143
+ it "merges cookbook_gems" do
144
+ @config = <<-CONFIG
145
+ cookbook_gems:
146
+ - pivotal_shared
147
+ env_variable_switches:
148
+ RACK_ENV:
149
+ development:
150
+ cookbook_gems:
151
+ - pivotal_shared
152
+ - pivotal_workstation
153
+ CONFIG
154
+ @generator = Soloist::ChefConfigGenerator.new(YAML.load(@config), "../..")
155
+ @generator.cookbook_gems.should =~ [
156
+ "pivotal_shared",
157
+ "pivotal_workstation"
158
+ ]
159
+ end
160
+
137
161
  it "splits the value on comma and applies all matching" do
138
162
  ENV["ROLES"]="application,database"
139
163
  @config = <<-CONFIG
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soloist
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
5
- prerelease: false
4
+ hash: 63
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 1
10
- version: 0.9.1
9
+ - 2
10
+ version: 0.9.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matthew Kocher
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-21 00:00:00 -07:00
18
+ date: 2011-07-26 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  requirements: []
112
112
 
113
113
  rubyforge_project: soloist
114
- rubygems_version: 1.3.7
114
+ rubygems_version: 1.6.2
115
115
  signing_key:
116
116
  specification_version: 3
117
117
  summary: Soloist is a simple way of running chef-solo