guard-strainer 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.travis.yml +3 -0
  4. data/CONTRIBUTING.md +29 -0
  5. data/Gemfile +12 -0
  6. data/Guardfile +6 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +51 -0
  9. data/Rakefile +34 -0
  10. data/guard-strainer.gemspec +25 -0
  11. data/lib/guard/strainer.rb +112 -0
  12. data/lib/guard/strainer/runner.rb +48 -0
  13. data/lib/guard/strainer/templates/Guardfile +7 -0
  14. data/lib/guard/strainer/version.rb +5 -0
  15. data/spec/fixtures/cookbooks/git/.gitignore +14 -0
  16. data/spec/fixtures/cookbooks/git/.kitchen.yml +46 -0
  17. data/spec/fixtures/cookbooks/git/Berksfile +8 -0
  18. data/spec/fixtures/cookbooks/git/CHANGELOG.md +76 -0
  19. data/spec/fixtures/cookbooks/git/CONTRIBUTING +29 -0
  20. data/spec/fixtures/cookbooks/git/Gemfile +3 -0
  21. data/spec/fixtures/cookbooks/git/LICENSE +201 -0
  22. data/spec/fixtures/cookbooks/git/README.md +115 -0
  23. data/spec/fixtures/cookbooks/git/TESTING.md +25 -0
  24. data/spec/fixtures/cookbooks/git/attributes/default.rb +40 -0
  25. data/spec/fixtures/cookbooks/git/metadata.rb +35 -0
  26. data/spec/fixtures/cookbooks/git/recipes/default.rb +46 -0
  27. data/spec/fixtures/cookbooks/git/recipes/server.rb +57 -0
  28. data/spec/fixtures/cookbooks/git/recipes/source.rb +49 -0
  29. data/spec/fixtures/cookbooks/git/recipes/windows.rb +32 -0
  30. data/spec/fixtures/cookbooks/git/templates/default/git-xinetd.d.erb +10 -0
  31. data/spec/fixtures/cookbooks/git/templates/default/sv-git-daemon-log-run.erb +2 -0
  32. data/spec/fixtures/cookbooks/git/templates/default/sv-git-daemon-run.erb +3 -0
  33. data/spec/fixtures/cookbooks/sudo/.chef/knife.rb +1 -0
  34. data/spec/fixtures/cookbooks/sudo/.gitignore +14 -0
  35. data/spec/fixtures/cookbooks/sudo/.kitchen.yml +35 -0
  36. data/spec/fixtures/cookbooks/sudo/.rspec +2 -0
  37. data/spec/fixtures/cookbooks/sudo/Berksfile +8 -0
  38. data/spec/fixtures/cookbooks/sudo/CHANGELOG.md +63 -0
  39. data/spec/fixtures/cookbooks/sudo/CONTRIBUTING.md +257 -0
  40. data/spec/fixtures/cookbooks/sudo/Gemfile +12 -0
  41. data/spec/fixtures/cookbooks/sudo/LICENSE +201 -0
  42. data/spec/fixtures/cookbooks/sudo/README.md +229 -0
  43. data/spec/fixtures/cookbooks/sudo/TESTING.md +25 -0
  44. data/spec/fixtures/cookbooks/sudo/attributes/default.rb +25 -0
  45. data/spec/fixtures/cookbooks/sudo/files/default/README +17 -0
  46. data/spec/fixtures/cookbooks/sudo/metadata.rb +46 -0
  47. data/spec/fixtures/cookbooks/sudo/providers/default.rb +135 -0
  48. data/spec/fixtures/cookbooks/sudo/recipes/default.rb +54 -0
  49. data/spec/fixtures/cookbooks/sudo/resources/default.rb +38 -0
  50. data/spec/fixtures/cookbooks/sudo/templates/default/sudoer.erb +6 -0
  51. data/spec/fixtures/cookbooks/sudo/templates/default/sudoers.erb +26 -0
  52. data/spec/fixtures/cookbooks/tmux/.chef/knife.rb +2 -0
  53. data/spec/fixtures/cookbooks/tmux/.gitignore +1 -0
  54. data/spec/fixtures/cookbooks/tmux/.travis.yml +7 -0
  55. data/spec/fixtures/cookbooks/tmux/CHANGELOG.md +39 -0
  56. data/spec/fixtures/cookbooks/tmux/CONTRIBUTING.md +257 -0
  57. data/spec/fixtures/cookbooks/tmux/Gemfile +6 -0
  58. data/spec/fixtures/cookbooks/tmux/LICENSE +201 -0
  59. data/spec/fixtures/cookbooks/tmux/README.md +52 -0
  60. data/spec/fixtures/cookbooks/tmux/Rakefile +34 -0
  61. data/spec/fixtures/cookbooks/tmux/attributes/default.rb +15 -0
  62. data/spec/fixtures/cookbooks/tmux/metadata.rb +7 -0
  63. data/spec/fixtures/cookbooks/tmux/recipes/default.rb +33 -0
  64. data/spec/fixtures/cookbooks/tmux/recipes/package.rb +5 -0
  65. data/spec/fixtures/cookbooks/tmux/recipes/source.rb +45 -0
  66. data/spec/fixtures/cookbooks/tmux/templates/default/tmux.conf.erb +35 -0
  67. data/spec/fixtures/cookbooks/tmux/test/kitchen/Kitchenfile +6 -0
  68. data/spec/guard/strainer/runner_spec.rb +66 -0
  69. data/spec/guard/strainer_spec.rb +114 -0
  70. data/spec/spec_helper.rb +24 -0
  71. metadata +213 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2e578a855d122750882a758fd89ba735f6cfa401
4
+ data.tar.gz: 2449a8028b72e23a9e967f812a52171514ceea4c
5
+ SHA512:
6
+ metadata.gz: 45b53d473f97c9c2979ee3726f9ad18cff7028dfe697d9eace2db738ffd0aba0157d98b1b14d8d6f68f7869ce502c88bb8372a8808da5f6648420bc9a889491e
7
+ data.tar.gz: cc94868fc238f746e876beebe1e7bee8b89a2832ea700a68a9b5914de6f936c371a9538d76a8589e2f22fbff8845d116b63bbffdfcd8fc0feb5d99c33cdd1d95
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
@@ -0,0 +1,29 @@
1
+ # Contributing to Guard::Strainer
2
+
3
+ ## File an issue
4
+
5
+ You can report bugs and feature requests to [GitHub Issues](https://github.com/wingrunr21/guard-strainer/issues).
6
+
7
+ Try to figure out where the issue belongs to: Is it an issue with Guard::Strainer itself or with Guard?
8
+
9
+ When you file a bug, please try to follow these simple rules if applicable:
10
+
11
+ * Make sure you've read the README carefully.
12
+ * Make sure you run Guard with `bundle exec` first.
13
+ * Add debug information to the issue by running Guard with the `--debug` option.
14
+ * Add your `Guardfile` and `Gemfile` to the issue.
15
+ * Make sure that the issue is reproducible with your description.
16
+
17
+ **It's most likely that your bug gets resolved faster if you provide as much information as possible!**
18
+
19
+ Development
20
+ -----------
21
+
22
+ * Source hosted at [GitHub](https://github.com/wingrunr21/guard-strainer).
23
+
24
+ Pull requests are welcome! Please try to follow these rules for contributions:
25
+
26
+ * Please create a topic branch for every unique change
27
+ * Please make sure you create tests for your new features
28
+ * Please update the README as applicable
29
+ * Please **do not change** the version number
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in guard-strainer.gemspec
4
+ gemspec
5
+
6
+ gem 'rake'
7
+
8
+ group :test do
9
+ gem 'rspec', '~> 2.13.0'
10
+ gem 'guard-rspec', '~> 3.0.2'
11
+ gem 'simplecov', '~> 0.7.1'
12
+ end
@@ -0,0 +1,6 @@
1
+ guard :rspec do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Stafford Brunk
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # Guard::Strainer
2
+ [![Build Status](https://travis-ci.org/wingrunr21/guard-strainer.png)](https://travis-ci.org/wingrunr21/guard-strainer) [![Gem Version](https://badge.fury.io/rb/guard-strainer.png)](http://badge.fury.io/rb/guard-strainer)
3
+
4
+ ```guard-strainer``` will automatically execute a Strainerfile for a watched chef-repo or cookbook when it detects changes
5
+
6
+ ## Requirements
7
+ * [strainer](https://github.com/customink/strainer) v3.2.1 or later
8
+
9
+ ## Installation
10
+
11
+ Add to your chef-repo or cookbook's Gemfile:
12
+
13
+ gem 'guard-strainer'
14
+
15
+ Or install the gem (make sure you also have [Guard](https://github.com/guard/guard):
16
+
17
+ $ gem install guard-strainer
18
+
19
+ Finally add the guard-strainer definition to your Guardfile:
20
+
21
+ guard init strainer
22
+
23
+ ## Usage
24
+ Please read the [Guard usage doc](http://github.com/guard/guard#readme)
25
+
26
+ ## Options
27
+
28
+ ```ruby
29
+ :standalone => true # set to true for cookbook operation. Default false.
30
+ :all_on_pass => false # set to true to run all Strainerfiles on pass. Default true.
31
+ :all_on_start => false # set to true to run all Strainerfiles on start. Default true.
32
+ :fail_fast => false # set to true to fail immediately upon any non-zero exit code. Default true.
33
+ :except => ['foodcritic'] # labels to ignore in the Strainerfiles
34
+ :only => ['foodcritic'] # labels to include in the Strainerfiles
35
+ :cookbooks_path => '/path/to/cookbooks' # path to the cookbook store
36
+ :config => "/path/to/client.rb" # path to the knife.rb/client.rb config
37
+ :debug => true # set to true to enable debugging log output. Default false.
38
+ :color => false # set to false to disable colored output. Default is true
39
+ ```
40
+
41
+ ## Development
42
+
43
+ Pull requests are welcome! Please try to follow these rules for contributions:
44
+
45
+ * Please create a topic branch for every unique change
46
+ * Please make sure you create tests for your new features
47
+ * Please update the README as applicable
48
+ * Please **do not change** the version number
49
+
50
+ ## Author
51
+ [Stafford Brunk](https://github.com/wingrunr21)
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler::GemHelper.install_tasks
4
+ require 'rspec/core/rake_task'
5
+
6
+ # Rake tasks from https://github.com/mojombo/rakegem/blob/master/Rakefile
7
+
8
+ # Helper Functions
9
+ def name
10
+ @name ||= Dir['*.gemspec'].first.split('.').first.gsub('-', '/')
11
+ end
12
+
13
+ def version
14
+ line = File.read("lib/#{name}/version.rb")[/^\s*VERSION\s*=\s*.*/]
15
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
16
+ end
17
+
18
+ # Standard tasks
19
+ RSpec::Core::RakeTask.new(:spec)
20
+ task :test => :spec
21
+ task :default => :spec
22
+
23
+ require 'rdoc/task'
24
+ Rake::RDocTask.new do |rdoc|
25
+ rdoc.rdoc_dir = 'rdoc'
26
+ rdoc.title = "#{name} #{version}"
27
+ rdoc.rdoc_files.include('README*')
28
+ rdoc.rdoc_files.include('lib/**/*.rb')
29
+ end
30
+
31
+ desc "Open an pry session preloaded with this library"
32
+ task :console do
33
+ sh "pry -Ilib -r #{name}.rb"
34
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'guard/strainer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'guard-strainer'
8
+ spec.version = Guard::StrainerVersion::VERSION
9
+ spec.authors = ['Stafford Brunk']
10
+ spec.email = ['stafford.brunk@gmail.com']
11
+ spec.description = %q{Watch for changes in your chef-repo or cookbook and automatically run Strainer}
12
+ spec.summary = %q{guard-strainer will automatically execute a Strainerfile for a watched chef-repo or cookbook when it detects changes}
13
+ spec.homepage = 'https://github.com/wingrunr21/guard-strainer'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'guard', '>= 1.8.0'
22
+ spec.add_dependency 'strainer', '>= 3.2.1'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ end
@@ -0,0 +1,112 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+
4
+ module Guard
5
+ class Strainer < Guard
6
+ require 'strainer'
7
+ require 'guard/strainer/runner'
8
+
9
+ # Initialize guard-strainer.
10
+ #
11
+ # @param [Array<Guard::Watcher>] watchers the Guard plugin file watchers
12
+ # @param [Hash] options the custom Guard plugin options
13
+ # @option options [Boolean] :standalone set to true for cookbook operation. Default false.
14
+ # @option options [Boolean] :all_on_pass set to true to run all Strainerfiles on pass. Default true.
15
+ # @option options [Boolean] :all_on_start set to true to run all Strainerfiles on start. Default true.
16
+ # @option options [Boolean] :fail_fast set to true to fail immediately upon any non-zero exit code. Default true.
17
+ # @option options [Array<String>] :except labels to ignore in the Strainerfiles
18
+ # @option options [Array<String>] :only labels to include in the Strainerfiles
19
+ # @option options [String] :cookbooks_path path to the cookbook store
20
+ # @option options [String] :config path to the knife.rb/client.rb config
21
+ # @option options [Boolean] :debug set to true to enable debugging log output. Default false.
22
+ # @option options [Boolean] :color set to false to disable colored output. Default is true
23
+ #
24
+ def initialize(watchers = [], options = {})
25
+ # Override the config file if it's specified
26
+ ::Berkshelf::Chef::Config.path = options.delete(:config) if options[:config]
27
+
28
+ # Set the Strainer path if it's specified
29
+ ::Strainer.sandbox_path = options.delete(:sandbox) if options[:sandbox]
30
+
31
+ # Use Strainer::Shell as the primary output shell
32
+ ::Thor::Base.shell = ::Strainer::Shell
33
+
34
+ # Set whether color output is enabled
35
+ ::Thor::Base.shell.enable_colors = false unless options.delete(:color)
36
+
37
+ # Use debugging output if asked
38
+ $DEBUG = true if options.delete(:debug)
39
+
40
+ super
41
+
42
+ @options = {
43
+ :standalone => false,
44
+ :all_on_start => true,
45
+ :all_on_pass => true,
46
+ :fail_fast => true
47
+ }.merge(options)
48
+
49
+ @runner = Runner.new(@options)
50
+ end
51
+
52
+ def start
53
+ UI.info "Guard::Strainer is running"
54
+ run_all if @options[:all_on_start]
55
+ end
56
+
57
+ # Called when just `enter` is pressed
58
+ # This method should be principally used for long action like running all specs/tests/...
59
+ #
60
+ # @raise [:task_has_failed] when run_all has failed
61
+ # @return [Object] the task result
62
+ #
63
+ def run_all
64
+ passed = @runner.run_all!
65
+
66
+ throw :task_has_failed unless passed
67
+ end
68
+
69
+ # Common run definition used in run_on_additions,
70
+ # run_on_modifications, and run_on_removals
71
+ #
72
+ # @param [Array<String>] paths to Strain
73
+ # @raise [:task_has_failed] when run has failed
74
+ # @return [Object] the task result
75
+ def run(paths)
76
+ passed = @runner.run!(paths)
77
+
78
+ throw :task_has_failed unless passed
79
+ @runner.run_all! if @options[:all_on_pass]
80
+ end
81
+
82
+ # Called on file(s) additions that the Guard plugin watches.
83
+ #
84
+ # @param [Array<String>] paths the changes files or paths
85
+ # @raise [:task_has_failed] when run_on_additions has failed
86
+ # @return [Object] the task result
87
+ #
88
+ def run_on_additions(paths)
89
+ run(paths)
90
+ end
91
+
92
+ # Called on file(s) modifications that the Guard plugin watches.
93
+ #
94
+ # @param [Array<String>] paths the changes files or paths
95
+ # @raise [:task_has_failed] when run_on_modifications has failed
96
+ # @return [Object] the task result
97
+ #
98
+ def run_on_modifications(paths)
99
+ run(paths)
100
+ end
101
+
102
+ # Called on file(s) removals that the Guard plugin watches.
103
+ #
104
+ # @param [Array<String>] paths the changes files or paths
105
+ # @raise [:task_has_failed] when run_on_removals has failed
106
+ # @return [Object] the task result
107
+ #
108
+ def run_on_removals(paths)
109
+ run(paths)
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,48 @@
1
+ module Guard
2
+ class Strainer
3
+ class Runner
4
+ attr_reader :cabinet
5
+
6
+ def initialize(options)
7
+ @options = options
8
+ @cabinet = {}
9
+ end
10
+
11
+ def run!(paths = [])
12
+ cookbooks = paths.map{|path| find_cookbook_name(path)}
13
+ runner = runner_for_cookbooks(cookbooks)
14
+
15
+ UI.info "Straining: #{cookbooks.join(',')}"
16
+ runner.run!
17
+ end
18
+
19
+ def run_all!
20
+ paths = Dir[File.join('**', 'metadata.rb')].sort
21
+ run!(paths)
22
+ end
23
+
24
+ protected
25
+ def find_cookbook_name(path)
26
+ current_path = Pathname.new(File.dirname(path))
27
+ cookbook = nil
28
+
29
+ until current_path == ::Guard::Dsl.options["guardfile_path"] do
30
+ if File.exist?(File.join(current_path, 'metadata.rb'))
31
+ cookbook = current_path.basename
32
+ break
33
+ else
34
+ current_path = current_path.parent
35
+ end
36
+ end
37
+
38
+ cookbook
39
+ end
40
+
41
+ def runner_for_cookbooks(cookbooks)
42
+ @cabinet.fetch(cookbooks) do |books|
43
+ ::Strainer::Runner.new(books, @options.merge({strainer_file: File.join(File.dirname(::Guard::Dsl.options["guardfile_path"]), ::Strainer::Strainerfile::DEFAULT_FILENAME)}))
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,7 @@
1
+ guard 'strainer' do
2
+ watch %r{^cookbooks/(.+)/}
3
+
4
+ # Comment the above and uncomment this line if you are using Strainer in standalone mode
5
+ # Make sure to set the :standalone option above!
6
+ # watch %r{(.+)%}
7
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module StrainerVersion
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ .vagrant
2
+ Berksfile.lock
3
+ Gemfile.lock
4
+ *~
5
+ *#
6
+ .#*
7
+ \#*#
8
+ .*.sw[a-z]
9
+ *.un~
10
+ .bundle
11
+ .cache
12
+ .kitchen
13
+ bin
14
+ .kitchen.local.yml
@@ -0,0 +1,46 @@
1
+ ---
2
+ driver_plugin: vagrant
3
+ driver_config:
4
+ require_chef_omnibus: true
5
+
6
+ platforms:
7
+ - name: ubuntu-12.04
8
+ driver_config:
9
+ box: opscode-ubuntu-12.04
10
+ box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box
11
+ run_list:
12
+ - recipe[apt]
13
+
14
+ - name: ubuntu-10.04
15
+ driver_config:
16
+ box: opscode-ubuntu-10.04
17
+ box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-10.04_provisionerless.box
18
+ run_list:
19
+ - recipe[apt]
20
+
21
+ - name: centos-6.4
22
+ driver_config:
23
+ box: opscode-centos-6.4
24
+ box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-6.4_provisionerless.box
25
+
26
+ - name: centos-5.9
27
+ driver_config:
28
+ box: opscode-centos-5.9
29
+ box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_centos-5.9_provisionerless.box
30
+
31
+ suites:
32
+ - name: default
33
+ run_list:
34
+ - recipe[git]
35
+ attributes: {}
36
+
37
+ - name: source
38
+ excludes: ["ubuntu-12.04", "ubuntu-10.04"]
39
+ run_list:
40
+ - recipe[git::source]
41
+ attributes: {}
42
+
43
+ - name: server
44
+ run_list:
45
+ - recipe[git::server]
46
+ attributes: {}