guard-chef 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,7 +19,7 @@ Add it to your Gemfile (inside test group):
19
19
 
20
20
  Add guard definition to your Guardfile by running this command:
21
21
 
22
- guard init bundler
22
+ guard init chef
23
23
 
24
24
  == Usage
25
25
 
@@ -0,0 +1,77 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+ require 'active_support/inflector'
4
+
5
+ Dir[File.expand_path('../chef/*_job.rb', __FILE__)].each {|f| require f}
6
+
7
+ module Guard
8
+ class Chef < Guard
9
+ def initialize(watchers=[], options={})
10
+ super
11
+ @base_dir = ::File.expand_path('../../../', __FILE__)
12
+ # init stuff here, thx!
13
+ end
14
+
15
+ # =================
16
+ # = Guard methods =
17
+ # =================
18
+
19
+ # If one of those methods raise an exception, the Guard::GuardName instance
20
+ # will be removed from the active guards.
21
+
22
+ # Called once when Guard starts
23
+ # Please override initialize method to init stuff
24
+ def start
25
+ true
26
+ end
27
+
28
+ # Called on Ctrl-C signal (when Guard quits)
29
+ def stop
30
+ true
31
+ end
32
+
33
+ # Called on Ctrl-Z signal
34
+ # This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
35
+ def reload
36
+ true
37
+ end
38
+
39
+ # Called on Ctrl-/ signal
40
+ # This method should be principally used for long action like running all specs/tests/...
41
+ def run_all
42
+ true
43
+ end
44
+
45
+ # Called on file(s) modifications
46
+ def run_on_change(paths)
47
+ paths.each do |path|
48
+ unless updated?(path)
49
+ return false
50
+ end
51
+ end
52
+ true
53
+ end
54
+
55
+ private
56
+
57
+ def updated?(path)
58
+ target = perform(path)
59
+ unless target.nil?
60
+ target.update
61
+ return true
62
+ end
63
+ false
64
+ end
65
+
66
+ def perform(path)
67
+ begin
68
+ matches = path.split("/")
69
+ type, target = "#{matches[0].classify}Job", matches[1]
70
+ type.constantize.new(@base_dir, target.gsub(".rb", ''))
71
+ rescue Exception
72
+ puts "#{type.classify} is not a valid watch type"
73
+ nil
74
+ end
75
+ end
76
+ end
77
+ end
@@ -13,11 +13,12 @@ class CookbookJob
13
13
 
14
14
  def update
15
15
  puts "uploading changed cookbook. (#{target}) Please wait."
16
- retval = `#{base_cmd} && rake upload_cookbook[#{target}]`
17
- if /upload complete/ =~ retval
16
+ if /upload complete/ =~ `#{base_cmd} && rake upload_cookbook[#{target}]`
18
17
  puts "cookbook (#{target}) uploaded."
18
+ true
19
19
  else
20
20
  puts "cookbook (#{target}) could not be uploaded."
21
+ false
21
22
  end
22
23
  end
23
24
  end
@@ -13,11 +13,12 @@ class DataBagJob
13
13
 
14
14
  def update
15
15
  puts "uploading changed databag. (#{target}) Please wait."
16
- retval = `#{base_cmd} && rake databag:upload[#{target}]`
17
- if /Updated data_bag_item/ =~ retval
16
+ if /Updated data_bag_item/ =~ `#{base_cmd} && rake databag:upload[#{target}]`
18
17
  puts "databag (#{target}) uploaded."
18
+ true
19
19
  else
20
20
  puts "databag (#{target}) could not be uploaded."
21
+ false
21
22
  end
22
23
  end
23
24
  end
@@ -13,11 +13,12 @@ class RoleJob
13
13
 
14
14
  def update
15
15
  puts "uploading changed role. (#{target}) Please wait."
16
- retval = `#{base_cmd} && rake role[#{target}]`
17
- if /Updated Role #{target}!/ =~ retval
16
+ if /Updated Role #{target}!/ =~ `#{base_cmd} && rake role[#{target}]`
18
17
  puts "role (#{target}) uploaded."
18
+ true
19
19
  else
20
20
  puts "role (#{target}) could not be uploaded."
21
+ false
21
22
  end
22
23
  end
23
24
  end
@@ -0,0 +1,5 @@
1
+ guard 'chef' do
2
+ watch(%r{^cookbooks/(.+)/})
3
+ watch(%r{^roles/(.+).rb})
4
+ watch(%r{^data_bags/(.+)/})
5
+ end
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Guard
3
3
  module ChefVersion
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
6
6
  end
@@ -0,0 +1,13 @@
1
+ task :upload_cookbook do
2
+ # noop
3
+ end
4
+
5
+ namespace :databag do
6
+ task :upload do
7
+ # noop
8
+ end
9
+ end
10
+
11
+ task :role do
12
+ # noop
13
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: guard-chef
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dreamr OKelly
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-11 00:00:00 Z
13
+ date: 2011-05-12 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: guard
@@ -58,7 +58,10 @@ files:
58
58
  - lib/guard/chef/cookbook_job.rb
59
59
  - lib/guard/chef/data_bag_job.rb
60
60
  - lib/guard/chef/role_job.rb
61
+ - lib/guard/chef/templates/Guardfile
61
62
  - lib/guard/chef/version.rb
63
+ - lib/guard/chef.rb
64
+ - lib/tasks/dummy.rake
62
65
  - LICENSE
63
66
  - README.rdoc
64
67
  homepage: http://rubygems.org/gems/guard-chef
@@ -85,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
88
  version: 1.3.6
86
89
  requirements: []
87
90
 
88
- rubyforge_project: guard-chef
91
+ rubyforge_project:
89
92
  rubygems_version: 1.7.2
90
93
  signing_key:
91
94
  specification_version: 3