Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactoring executable, updating gemspec

  • Loading branch information...
commit 304bd344e3d3ded0f4188538151848580796321f 1 parent dd1a1d6
@mkocher authored
View
15 bin/soloist
@@ -1,17 +1,14 @@
#!/usr/bin/env ruby
-require 'rubygems'
require File.join(File.dirname(__FILE__), '..', 'lib', 'soloist')
-log_level = ENV['LOG_LEVEL'] || "info"
+include Soloist::Util
-def with_or_without_dot(file_name)
- [file_name, ".#{file_name}"]
-end
+log_level = ENV['LOG_LEVEL'] || "info"
-soloistrc_contents, soloistrc_path = Soloist::Util.walk_up_and_find_file(with_or_without_dot("soloistrc"))
+soloistrc_contents, soloistrc_path = walk_up_and_find_file(with_or_without_dot("soloistrc"))
config_generator = Soloist::ChefConfigGenerator.new(YAML.load(soloistrc_contents), soloistrc_path)
-soloistrc_contents, soloistrc_path = Soloist::Util.walk_up_and_find_file(with_or_without_dot("soloistrc_local"), :required => false)
+soloistrc_contents, soloistrc_path = walk_up_and_find_file(with_or_without_dot("soloistrc_local"), :required => false)
config_generator.merge_config(YAML.load(soloistrc_contents), soloistrc_path) if soloistrc_contents
if ARGV.length >= 1
@@ -20,8 +17,8 @@ if ARGV.length >= 1
config_generator.recipes = [requested_recipe]
end
-solo_rb = Soloist::Util.fileify(config_generator.solo_rb)
-metadata_json = Soloist::Util.fileify(config_generator.json_file)
+solo_rb = fileify(config_generator.solo_rb)
+metadata_json = fileify(config_generator.json_file)
command = "sudo bash -c '#{config_generator.preserved_environment_variables_string} chef-solo -j #{metadata_json.path} -c #{solo_rb.path} -l #{log_level}'"
View
9 lib/soloist.rb
@@ -1,12 +1,9 @@
-require File.join(File.dirname(__FILE__), 'soloist', 'chef_config_generator')
-require File.join(File.dirname(__FILE__), 'soloist', 'util')
-
+require 'rubygems'
require "json"
require 'fileutils'
require 'yaml'
require 'tempfile'
+require File.join(File.dirname(__FILE__), 'soloist', 'chef_config_generator')
+require File.join(File.dirname(__FILE__), 'soloist', 'util')
-module Soloist
- # Your code goes here...
-end
View
10 lib/soloist/util.rb
@@ -1,13 +1,17 @@
module Soloist
- class Util
- def self.fileify(contents)
+ module Util
+ def with_or_without_dot(file_name)
+ [file_name, ".#{file_name}"]
+ end
+
+ def fileify(contents)
file = Tempfile.new("soloist")
file << contents
file.flush
file
end
- def self.walk_up_and_find_file(filenames, opts={})
+ def walk_up_and_find_file(filenames, opts={})
pwd = FileUtils.pwd
file = nil
path_to_file = ""
View
4 soloist.gemspec
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.authors = ["Matthew Kocher"]
s.email = ["kocher@gmail.com"]
- s.homepage = "http://rubygems.org/gems/soloist"
+ s.homepage = "http://github.com/mkocher/soloist"
s.summary = %q{Soloist is a simple way of running chef-solo}
s.description = %q{Soloist is an easy way of running chef solo, but it's not doing much.}
@@ -21,4 +21,4 @@ Gem::Specification.new do |s|
s.add_dependency('chef', '0.9.12')
s.add_dependency('json', '1.4.6')
-end
+end
View
8 spec/util_spec.rb
@@ -2,15 +2,19 @@
require 'lib/soloist'
describe Soloist::Util do
+ class TestClass
+ extend Soloist::Util
+ end
+
describe "walk_up_and_find_file" do
it "raises an error when the file isn't found" do
lambda do
- Soloist::Util.walk_up_and_find_file("file_not_on_the_filesystem")
+ TestClass.walk_up_and_find_file(["file_not_on_the_filesystem"])
end.should raise_error(Errno::ENOENT, "No such file or directory - file_not_on_the_filesystem not found")
end
it "doesn't raise an error if :required => false is passed" do
- Soloist::Util.walk_up_and_find_file("file_not_on_the_filesystem", :required => false).should == [nil, nil]
+ TestClass.walk_up_and_find_file(["file_not_on_the_filesystem"], :required => false).should == [nil, nil]
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.