rake-hooks 0.1 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # A sample Gemfile
2
+ source "http://rubygems.org"
3
+
4
+ gemspec
@@ -0,0 +1,77 @@
1
+ # rake-hooks
2
+
3
+ Rake hooks let you add callbacks to rake:
4
+
5
+ [![Build Status](https://secure.travis-ci.org/guillermo/rake-hooks.png)](http://travis-ci.org/guillermo/rake-hooks)
6
+
7
+
8
+ ## Usage
9
+
10
+ For example in your Rakefile
11
+
12
+ ```ruby
13
+ require 'rake/hooks'
14
+
15
+ task :say_hello do
16
+ puts "Good Morning !"
17
+ end
18
+
19
+ after :say_hello do
20
+ puts "GoodBye"
21
+ end
22
+
23
+ after :say_hello do
24
+ puts "Now go to bed !"
25
+ end
26
+
27
+ before :say_hello do
28
+ puts "Hi !"
29
+ end
30
+ ```
31
+
32
+ Now run with rake
33
+
34
+ ```bash
35
+ $ rake say_hello
36
+ Hi !
37
+ Good Morning !
38
+ GoodBye
39
+ Now go to bed !
40
+ ```
41
+
42
+ You can also pass more than one task and each task will be setup with the
43
+ callback
44
+
45
+ ```ruby
46
+ before :say_hello, :say_goodbye do
47
+ puts "Hi !"
48
+ end
49
+ ```
50
+
51
+
52
+ ## Installation
53
+
54
+ With rubygems use:
55
+ ```bash
56
+ $ gem install rake-hooks
57
+ ```
58
+
59
+ With other systems
60
+ Add lib dir to load path.
61
+
62
+ ## Dependencies
63
+
64
+ * Rake
65
+
66
+ ## Author
67
+
68
+ * [Joel Moss](mailto:joel@developwithstyle.com)
69
+ * [Guillermo Álvarez](mailto:guillermo@cientifico.net)
70
+
71
+ ## Web
72
+
73
+ http://github.com/guillermo/rake-hooks
74
+
75
+ ## Date of writing
76
+
77
+ 9 Sep 2011
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ require "bundler/gem_tasks"
1
2
  require 'rake/testtask'
2
3
 
3
4
  Rake::TestTask.new do |t|
@@ -1,16 +1,21 @@
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
1
+ def before(*task_names, &new_task)
2
+ task_names.each do |task_name|
3
+ old_task = Rake.application.instance_variable_get('@tasks').delete(task_name.to_s)
4
+ desc old_task.full_comment
5
+ task task_name do
6
+ new_task.call
7
+ old_task.invoke
8
+ end
6
9
  end
7
10
  end
8
11
 
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
12
+ def after(*task_names, &new_task)
13
+ task_names.each do |task_name|
14
+ old_task = Rake.application.instance_variable_get('@tasks').delete(task_name.to_s)
15
+ desc old_task.full_comment
16
+ task task_name do
17
+ old_task.invoke
18
+ new_task.call
19
+ end
15
20
  end
16
21
  end
@@ -0,0 +1,5 @@
1
+ module Rake
2
+ module Hooks
3
+ VERSION = "1.1"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rake/hooks/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rake-hooks"
7
+ s.version = Rake::Hooks::VERSION
8
+ s.email = ["guillermo@cientifico.net"]
9
+ s.authors = ["Guillermo Álvarez"]
10
+ s.description = "Add after and before hooks to rake tasks. You can use \"after :task do ... end\" and \"before :task do ... end\"."
11
+ s.summary = "Add after and before hooks to rake tasks"
12
+
13
+ s.rubyforge_project = "rake-hooks"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_runtime_dependency "rake", ">=0.9.2"
21
+
22
+ s.add_development_dependency "bundler"
23
+ end
24
+
25
+
@@ -1,5 +1,4 @@
1
1
  require 'test/unit'
2
- require 'rubygems'
3
2
  require 'rake'
4
3
  require 'rake/hooks'
5
4
 
@@ -8,11 +7,11 @@ class Store
8
7
  @@data ||= ""
9
8
  @@data << string
10
9
  end
11
-
10
+
12
11
  def self.to_s
13
12
  @@data || ""
14
13
  end
15
-
14
+
16
15
  def self.clean
17
16
  @@data = ""
18
17
  end
@@ -20,40 +19,76 @@ end
20
19
 
21
20
 
22
21
  class TestRakeHooks < Test::Unit::TestCase
23
-
22
+ begin
23
+ include Rake::DSL
24
+ rescue
25
+ end
26
+
24
27
  def setup
28
+ Rake::TaskManager.record_task_metadata = true
25
29
  Store.clean
26
30
  end
27
-
31
+
28
32
  def test_after
29
33
  task :task do Store << "wadus"; end
30
34
  after :task do Store << "way" ; end
31
-
35
+
32
36
  execute(:task)
33
37
 
34
38
  assert_equal "wadusway", Store.to_s
35
39
  end
36
-
40
+
41
+ def test_after_multiple
42
+ task :task_one do Store << "wadus"; end
43
+ task :task_two do Store << "badus"; end
44
+ after :task_one, :task_two do Store << "way" ; end
45
+
46
+ execute(:task_one)
47
+ assert_equal "wadusway", Store.to_s
48
+
49
+ Store.clean
50
+
51
+ execute(:task_two)
52
+ assert_equal "badusway", Store.to_s
53
+ end
54
+
37
55
  def test_before
38
56
  task :supertask do Store << "wadus" ; end
39
57
  before :supertask do Store << "super" ; end
40
-
58
+
41
59
  execute(:supertask)
42
60
  assert_equal "superwadus", Store.to_s
43
61
  end
44
-
62
+
45
63
  def test_after_and_before
46
64
  task :super_task do Store << "wadus" ; end
47
65
  before :super_task do Store << "love " ; end
48
66
  before :super_task do Store << "I " ; end
49
67
  after :super_task do Store << " way" ; end
50
68
  after :super_task do Store << "." ; end
51
-
69
+
52
70
  execute(:super_task)
53
71
  assert_equal "I love wadus way.", Store.to_s
54
72
  end
55
-
73
+
74
+ def test_save_comment_on_after_tasks
75
+ desc 'this is my task'
76
+ task :my_task do ; end
77
+
78
+ after :my_task do; end
79
+ assert_equal "this is my task", Rake::Task[:my_task].full_comment
80
+ end
81
+
82
+
83
+ def test_save_comment_on_before_tasks
84
+ desc 'this is my task'
85
+ task :my_task2 do ; end
86
+
87
+ before :my_task2 do; end
88
+ assert_equal "this is my task", Rake::Task[:my_task2].full_comment
89
+ end
90
+
56
91
  def execute(task_name)
57
92
  Rake::Task[task_name].execute
58
93
  end
59
- end
94
+ end
metadata CHANGED
@@ -1,70 +1,79 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rake-hooks
3
- version: !ruby/object:Gem::Version
4
- hash: 9
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- version: "0.1"
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.1'
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
12
- - "Guillermo \xC3\x81lvarez"
7
+ authors:
8
+ - Guillermo Álvarez
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-06-22 00:00:00 +02:00
18
- default_executable:
19
- dependencies: []
20
-
21
- description: Add after and before hooks to rake tasks. You can use "after :task do ... end" and "before :task do ... end".
22
- email: guillermo@cientifico.net
12
+ date: 2011-09-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &2153485780 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2153485780
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &2153485360 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2153485360
36
+ description: Add after and before hooks to rake tasks. You can use "after :task do
37
+ ... end" and "before :task do ... end".
38
+ email:
39
+ - guillermo@cientifico.net
23
40
  executables: []
24
-
25
41
  extensions: []
26
-
27
42
  extra_rdoc_files: []
28
-
29
- files:
30
- - README
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - Gemfile.lock
31
47
  - LICENSE
48
+ - README.md
32
49
  - Rakefile
33
- - test/test_rake_hooks.rb
34
50
  - lib/rake/hooks.rb
35
- has_rdoc: true
36
- homepage: http://github.com/guillermo/rake-hooks
51
+ - lib/rake/hooks/version.rb
52
+ - rake-hooks.gemspec
53
+ - test/test_rake_hooks.rb
54
+ homepage:
37
55
  licenses: []
38
-
39
56
  post_install_message:
40
57
  rdoc_options: []
41
-
42
- require_paths:
58
+ require_paths:
43
59
  - lib
44
- required_ruby_version: !ruby/object:Gem::Requirement
60
+ required_ruby_version: !ruby/object:Gem::Requirement
45
61
  none: false
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- hash: 3
50
- segments:
51
- - 0
52
- version: "0"
53
- required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
67
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
62
72
  requirements: []
63
-
64
- rubyforge_project:
65
- rubygems_version: 1.3.7
73
+ rubyforge_project: rake-hooks
74
+ rubygems_version: 1.8.6
66
75
  signing_key:
67
76
  specification_version: 3
68
77
  summary: Add after and before hooks to rake tasks
69
- test_files: []
70
-
78
+ test_files:
79
+ - test/test_rake_hooks.rb
data/README DELETED
@@ -1,54 +0,0 @@
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