Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 6548f527f9e1f796793cf48a28e8c34ccf5863de Todd Blackman committed Jul 9, 2012
Showing with 189 additions and 0 deletions.
  1. +17 −0 Gemfile.lock
  2. +22 −0 LICENSE
  3. +54 −0 README
  4. +10 −0 Rakefile
  5. +16 −0 lib/rake/hooks.rb
  6. +11 −0 rake-hooks.gemspec
  7. +59 −0 test/test_rake_hooks.rb
17 Gemfile.lock
@@ -0,0 +1,17 @@
+PATH
+ remote: .
+ specs:
+ rake-hooks (1.2.3)
+ rake
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ rake (0.9.2.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bundler
+ rake-hooks!
22 LICENSE
@@ -0,0 +1,22 @@
+The MIT License
+
+Copyright (c) <2010> <Guillermo Álvarez Fernández>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
54 README
@@ -0,0 +1,54 @@
+# rake-hooks
+
+Rake hooks let you add callbacks to rake:
+
+## Usage
+
+For example in your Rakefile
+
+ require 'rake/hooks'
+
+ task :say_hello do
+ puts "Good Morning !"
+ end
+
+ after :say_hello do
+ puts "GoodBye"
+ end
+
+ after :say_hello do
+ puts "Now go to bed !"
+ end
+
+ before :say_hello do
+ puts "Hi !"
+ end
+
+Now run with rake
+
+ $ rake say_hello
+ Hi !
+ Good Morning !
+ GoodBye
+ Now go to bed !"
+
+
+## Installation
+
+With rubygems use:
+ gem install rake-hooks
+
+With other systems
+ Add lib dir to load path.
+
+## Author
+
+Guillermo Álvarez <guillermo@cientifico.net>
+
+## Web
+
+http://github.com/guillermo/rake-hooks
+
+## Date of writing
+
+22 Jul 2010
10 Rakefile
@@ -0,0 +1,10 @@
+require 'rake/testtask'
+
+Rake::TestTask.new do |t|
+ t.libs << "test"
+ t.test_files = FileList['test/test*.rb']
+ t.verbose = true
+end
+
+
+task :default => :test
16 lib/rake/hooks.rb
@@ -0,0 +1,16 @@
+def before(task_name, &new_task)
+ old_task = Rake.application.instance_variable_get('@tasks').delete(task_name.to_s)
+ task task_name do
+ new_task.call
+ old_task.invoke
+ end
+end
+
+def after(task_name, &new_task)
+ old_task = Rake.application.instance_variable_get('@tasks').delete(task_name.to_s)
+
+ task task_name do
+ old_task.invoke
+ new_task.call
+ end
+end
11 rake-hooks.gemspec
@@ -0,0 +1,11 @@
+Gem::Specification.new do |s|
+ s.name = "rake-hooks"
+ s.version = "0.1"
+ s.date = "2010-06-22"
+ s.authors = ["Guillermo Álvarez"]
+ s.email = "guillermo@cientifico.net"
+ s.summary = "Add after and before hooks to rake tasks"
+ s.homepage = "http://github.com/guillermo/rake-hooks"
+ s.description = "Add after and before hooks to rake tasks. You can use \"after :task do ... end\" and \"before :task do ... end\"."
+ s.files = [ "README", "LICENSE", "Rakefile", "test/test_rake_hooks.rb", "lib/rake/hooks.rb"]
+end
59 test/test_rake_hooks.rb
@@ -0,0 +1,59 @@
+require 'test/unit'
+require 'rubygems'
+require 'rake'
+require 'rake/hooks'
+
+class Store
+ def self.<<(string)
+ @@data ||= ""
+ @@data << string
+ end
+
+ def self.to_s
+ @@data || ""
+ end
+
+ def self.clean
+ @@data = ""
+ end
+end
+
+
+class TestRakeHooks < Test::Unit::TestCase
+
+ def setup
+ Store.clean
+ end
+
+ def test_after
+ task :task do Store << "wadus"; end
+ after :task do Store << "way" ; end
+
+ execute(:task)
+
+ assert_equal "wadusway", Store.to_s
+ end
+
+ def test_before
+ task :supertask do Store << "wadus" ; end
+ before :supertask do Store << "super" ; end
+
+ execute(:supertask)
+ assert_equal "superwadus", Store.to_s
+ end
+
+ def test_after_and_before
+ task :super_task do Store << "wadus" ; end
+ before :super_task do Store << "love " ; end
+ before :super_task do Store << "I " ; end
+ after :super_task do Store << " way" ; end
+ after :super_task do Store << "." ; end
+
+ execute(:super_task)
+ assert_equal "I love wadus way.", Store.to_s
+ end
+
+ def execute(task_name)
+ Rake::Task[task_name].execute
+ end
+end

0 comments on commit 6548f52

Please sign in to comment.