guard-librarian 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Yann Lugrin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,69 @@
1
+ = Guard::Librarian
2
+
3
+ Librarian guard allows to automatically & intelligently install/update chef cookbooks when needed.
4
+
5
+ == Install
6
+
7
+ Please be sure to have {Guard}[https://github.com/guard/guard] installed before continue.
8
+
9
+ Install the gem:
10
+
11
+ gem install guard-librarian
12
+
13
+ Add it to your Gemfile:
14
+
15
+ gem 'guard-librarian'
16
+
17
+ Add guard definition to your Guardfile by running this command:
18
+
19
+ guard init librarian
20
+
21
+ == Usage
22
+
23
+ Please read {Guard usage doc}[https://github.com/guard/guard#readme]
24
+
25
+ == Guardfile
26
+
27
+ === Simple example
28
+
29
+ guard 'librarian' do
30
+ watch('Cheffile')
31
+ end
32
+
33
+ == Options
34
+
35
+ You can pass options to librarian-chef with:
36
+
37
+ guard 'librarian', :cli => '--clean --verbose' do
38
+ ...
39
+ end
40
+
41
+ By default it will run on start, but this can be disabled with :run_on_start =>
42
+ false.
43
+
44
+ When it runs on start, it will assume your Cheffile is in the current
45
+ directory containing your Guardfile. (It doesn't look at the paths specified by
46
+ your 'watch' commands except when those files change.) So if your Cheffile is
47
+ in a subdirectory, you will probably see "Cannot find Cheffile!" and will want
48
+ to set :run_on_start => false.
49
+
50
+ You can disable desktop notification with:
51
+
52
+ guard 'librarian', :notify => false do
53
+ ...
54
+ end
55
+
56
+ Please read {Guard doc}[https://github.com/guard/guard#readme] for more info about Guardfile DSL.
57
+
58
+ == Development
59
+
60
+ - Source hosted at {GitHub}[https://github.com/TylerRick/guard-librarian]
61
+ - Report issues/Questions/Feature requests on {GitHub Issues}[https://github.com/TylerRick/guard-librarian/issues]
62
+
63
+ Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change
64
+ you make.
65
+
66
+ == Authors
67
+
68
+ {Yann Lugrin}[https://github.com/yannlugrin] (created guard-bundler)
69
+ {Tyler Rick}[https://github.com/TylerRick] (adapted guard-bundler to work with Cheffile)
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+ require 'guard'
3
+ require 'guard/guard'
4
+ #require 'librarian'
5
+
6
+ module Guard
7
+ class Librarian < Guard
8
+ autoload :Notifier, 'guard/librarian/notifier'
9
+
10
+ def initialize(watchers = [], options = {})
11
+ super
12
+ options[:run_on_start] = true unless options[:run_on_start] == false
13
+ options[:notify] = true if options[:notify].nil?
14
+ end
15
+
16
+ def start
17
+ refresh_bundle if options[:run_on_start]
18
+ end
19
+
20
+ def reload
21
+ start
22
+ end
23
+
24
+ def run_on_change(paths = [])
25
+ #puts "paths=#{paths.join(' ')}"
26
+ dirs = paths.map {|_| File.dirname(_) }
27
+ refresh_bundle(dirs)
28
+ end
29
+
30
+ private
31
+
32
+ def notify?
33
+ !!options[:notify]
34
+ end
35
+
36
+ def refresh_bundle(dirs = ['.'])
37
+ if bundle_need_refresh?
38
+ UI.info 'Refresh cookbooks', :reset => true
39
+ start_at = Time.now
40
+ dirs.each do |dir|
41
+ Dir.chdir(dir) do
42
+ #puts "Dir.getwd=#{Dir.getwd.inspect}"
43
+ @result = system("librarian-chef install#{options[:cli] ? " #{options[:cli]}" : ''}")
44
+ end
45
+ end
46
+ Notifier::notify(@result, Time.now - start_at) if notify?
47
+ @result
48
+ else
49
+ UI.info 'Cookbooks already up-to-date', :reset => true
50
+ Notifier::notify('up-to-date', nil) if notify?
51
+ true
52
+ end
53
+ end
54
+
55
+ def bundle_need_refresh?
56
+ true
57
+ #::Bundler.with_clean_env do
58
+ # `bundle check`
59
+ #end
60
+ #$? == 0 ? false : true
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+ module Guard
3
+ class Librarian
4
+ class Notifier
5
+
6
+ def self.guard_message(result, duration)
7
+ case result
8
+ when 'up-to-date'
9
+ "Cookbooks already up-to-date"
10
+ when true
11
+ "Cookbooks have been updated\nin %.1f seconds." % [duration]
12
+ else
13
+ "Cookbooks can't be updated,\nplease check manually."
14
+ end
15
+ end
16
+
17
+ # failed | success
18
+ def self.guard_image(result)
19
+ icon = if result
20
+ :success
21
+ else
22
+ :failed
23
+ end
24
+ end
25
+
26
+ def self.notify(result, duration)
27
+ message = guard_message(result, duration)
28
+ image = guard_image(result)
29
+
30
+ ::Guard::Notifier.notify(message, :title => 'Cookbooks updated', :image => image)
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ guard 'librarian' do
2
+ watch('Cheffile')
3
+ end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ module Guard
3
+ module LibrarianVersion
4
+ Version = '0.0.1'
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-librarian
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yann Lugrin
9
+ - Tyler Rick
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-02-23 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: guard
17
+ requirement: &17731900 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.2.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *17731900
26
+ - !ruby/object:Gem::Dependency
27
+ name: librarian
28
+ requirement: &17731020 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *17731020
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ requirement: &17730220 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 2.6.0
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *17730220
48
+ - !ruby/object:Gem::Dependency
49
+ name: guard-rspec
50
+ requirement: &17729400 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 0.3.1
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *17729400
59
+ description: Guard::Librarian automatically installs your cookbook dependencies from
60
+ your Cheffile using librarian-chef when needed
61
+ email:
62
+ - yann.lugrin@sans-savoir.net
63
+ - tyler@k3integrations.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - lib/guard/librarian/templates/Guardfile
69
+ - lib/guard/librarian/notifier.rb
70
+ - lib/guard/librarian/version.rb
71
+ - lib/guard/librarian.rb
72
+ - LICENSE
73
+ - README.rdoc
74
+ homepage: http://rubygems.org/gems/guard-librarian
75
+ licenses: []
76
+ post_install_message:
77
+ rdoc_options:
78
+ - --charset=UTF-8
79
+ - --main=README.rdoc
80
+ - --exclude='(lib|test|spec)|(Gem|Guard|Rake)file'
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: 1.3.6
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 1.8.10
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Guard gem for Librarian
101
+ test_files: []