Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Add Rake and Thor tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo committed Jul 1, 2013
1 parent 2984a85 commit 82f7700
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Strainer CHANGELOG
==================
v3.0.3
------
- Add Thor and Rake tasks

v3.0.2
------
- Output summary message
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
source "https://rubygems.org"
source 'https://rubygems.org'
gemspec
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,29 @@ Strainer runs everything in an isolated sandbox, inside your Chef Repo. When inc
# Strainerfile
foodcritic: bundle exec foodcritic -I foodcritic/* -f any $SANDBOX/$COOKBOOK

Rake Task
---------
Strainer includes a Rake task for convenience:

```ruby
require 'strainer/rake_task'

Strainer::RakeTask.new(:strainer) do |s|
s.except = [...]
s.strainerfile = 'MyStraienrfile'
end
```

Thor Task
---------
Strainer includes a Thor task for convenience:

```ruby
require 'strainer/thor'

Strainer::Thor...
```

Needs Your Help
---------------
This is a list of features or problem *you* can help solve! Fork and submit a pull request to make Strain even better!
Expand Down
64 changes: 64 additions & 0 deletions lib/strainer/rake_task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require 'rake'
require 'rake/tasklib'
require 'strainer/cli'

module Strainer
# Run Strainer from rake
#
# @example
# desc "Run Strainer with Rake"
# Strainer::RakeTask.new(:strainer) do |strainer|
# strainer.except = ['kitchen']
# end
class RakeTask < ::Rake::TaskLib
# @return [Symbol]
attr_accessor :name

# @return [Hash]
attr_reader :options

def initialize(task_name = nil)
@options = {}
@name = (task_name || :strainer).to_sym

yield self if block_given?

desc "Run Strainer" unless ::Rake.application.last_comment
task name, :cookbook_name do |t, args|
require 'strainer'
Strainer::Runner.new(Array(args[:cookbook_name]), options)
end
end

Strainer::Cli.class_options.each do |option|
name = option.first

define_method(name) do
options[name.to_sym]
end

define_method("#{name}=") do |value|
options[name.to_sym] = value
end
end

Striner::Cli.commands['test'].options.each do |key|
name = key.first

define_method(name) do
options[name.to_sym]
end

define_method("#{name}=") do |value|
options[name.to_sym] = value
end
end

# Set the path to the strainerfile
#
# @param [String] file
def strainerfile=(file)
options[:strainerfile] = file
end
end
end
5 changes: 5 additions & 0 deletions lib/strainer/thor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'strainer/cli'

module Strainer
Thor = Cli
end

0 comments on commit 82f7700

Please sign in to comment.