Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial commit

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

0 comments on commit 6548f52

Please sign in to comment.
Something went wrong with that request. Please try again.