rake-hooks 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/LICENSE +22 -0
  2. data/README +54 -0
  3. data/Rakefile +10 -0
  4. data/lib/rake/hooks.rb +16 -0
  5. data/test/test_rake_hooks.rb +59 -0
  6. metadata +70 -0
data/LICENSE ADDED
@@ -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
+
data/README ADDED
@@ -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
data/Rakefile ADDED
@@ -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
data/lib/rake/hooks.rb ADDED
@@ -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
@@ -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
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
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"
10
+ platform: ruby
11
+ authors:
12
+ - "Guillermo \xC3\x81lvarez"
13
+ autorequire:
14
+ bindir: bin
15
+ 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
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - README
31
+ - LICENSE
32
+ - Rakefile
33
+ - test/test_rake_hooks.rb
34
+ - lib/rake/hooks.rb
35
+ has_rdoc: true
36
+ homepage: http://github.com/guillermo/rake-hooks
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ 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
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.7
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Add after and before hooks to rake tasks
69
+ test_files: []
70
+