initial commit

This commit is contained in:
John Bintz 2011-06-30 22:48:18 -04:00
commit b33bdc4a2e
11 changed files with 199 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.gem
.bundle
Gemfile.lock
pkg/*

9
Gemfile Normal file
View File

@ -0,0 +1,9 @@
source "http://rubygems.org"
# Specify your gem's dependencies in guard-puppet.gemspec
gemspec
require 'rbconfig'
if RbConfig::CONFIG['host_os'] =~ /linux/
gem 'libnotify'
end

9
Guardfile Normal file
View File

@ -0,0 +1,9 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end

1
Rakefile Normal file
View File

@ -0,0 +1 @@
require 'bundler/gem_tasks'

26
guard-puppet.gemspec Normal file
View File

@ -0,0 +1,26 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "guard/puppet/version"
Gem::Specification.new do |s|
s.name = "guard-puppet"
s.version = Guard::PuppetVersion::VERSION
s.authors = ["John Bintz"]
s.email = ["john@coswellproductions.com"]
s.homepage = ""
s.summary = %q{TODO: Write a gem summary}
s.description = %q{TODO: Write a gem description}
s.rubyforge_project = "guard-puppet"
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.add_dependency 'guard'
s.add_dependency 'puppet'
s.add_development_dependency 'rspec', '~> 2.6.0'
s.add_development_dependency 'mocha'
end

30
lib/guard/puppet.rb Normal file
View File

@ -0,0 +1,30 @@
require 'guard/guard'
module ::Guard
class Puppet < ::Guard::Guard
class << self
attr_accessor :is_wrapping_exit
end
def initialize(watchers = [], options = {})
super
@options = options
end
def run_all
UI.info msg = "Applying Puppet configuration..."
Notifier.notify msg, :title => "Puppet Config", :image => :pending
if Runner.new(@options).run != 0
Notifier.notify "Puppet config failure!", :title => "Puppet Config", :image => :failed
else
Notifier.notify "Puppet config reapplied successfully!", :title => "Puppet Config"
end
end
def run_on_change(files = [])
run_all
end
end
end
require 'guard/puppet/runner'

View File

@ -0,0 +1,32 @@
require 'guard/puppet'
require 'puppet/util/command_line'
require 'puppet/application/apply'
module Guard
class Puppet
class Runner
attr_reader :options
def initialize(options)
@options = options
end
def run
::Puppet::Util::CommandLine.new('puppet', command_line_params)
rescue SystemExit => e
e.status
end
def command_line_params
command = [ "apply" ]
command << "-v" if @options[:verbose]
if @options[:config_dir]
@options[:config_dir] = Dir.pwd if @options[:config_dir] == true
command << %{--confdir="#{@options[:config_dir]}"} if @options[:config_dir]
end
command << @options[:manifest] if @options[:manifest]
command
end
end
end
end

View File

@ -0,0 +1,5 @@
module Guard
module PuppetVersion
VERSION = '0.0.1'
end
end

View File

@ -0,0 +1,47 @@
require 'spec_helper'
require 'guard/puppet/runner'
describe Guard::Puppet::Runner do
let(:options) { {} }
let(:runner) { described_class.new(options) }
describe '#command_line_params' do
subject { runner.command_line_params }
context 'default' do
it { should == [ 'apply' ] }
end
context 'verbose' do
let(:options) { { :verbose => true } }
it { should == [ 'apply', '-v' ] }
end
context 'config dir with path' do
let(:options) { { :config_dir => '/123' } }
it { should == [ 'apply', '--confdir="/123"' ] }
end
context 'config dir with true' do
let(:options) { { :config_dir => true } }
it { should == [ 'apply', %{--confdir="#{Dir.pwd}"} ] }
end
context 'manifest' do
let(:options) { { :manifest => '123' } }
it { should == [ 'apply', '123' ] }
end
end
describe '#run' do
it 'should return the result of an exit call' do
::Puppet::Util::CommandLine.expects(:new).raises(SystemExit.new(10))
runner.run.should == 10
end
end
end

View File

@ -0,0 +1,32 @@
require 'spec_helper'
require 'guard/puppet'
describe Guard::Puppet do
let(:guard) { described_class.new }
describe '#run_all' do
before do
Guard::UI.expects(:info)
Guard::Notifier.expects(:notify).with("Applying Puppet configuration...", { :image => :pending, :title => "Puppet Config" })
Guard::Puppet::Runner.any_instance.expects(:run).returns(return_value)
end
context 'fails' do
let(:return_value) { 1 }
it 'should show the failure message' do
Guard::Notifier.expects(:notify).with("Puppet config failure!", :image => :failed, :title => "Puppet Config")
guard.run_all
end
end
context 'succeeds' do
let(:return_value) { 0 }
it 'should show the success message' do
Guard::Notifier.expects(:notify).with("Puppet config reapplied successfully!", :title => "Puppet Config")
guard.run_all
end
end
end
end

4
spec/spec_helper.rb Normal file
View File

@ -0,0 +1,4 @@
RSpec.configure do |c|
c.mock_with :mocha
end