rake_bubbler 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'rake'
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "ruby-debug"
12
+ gem "shoulda", ">= 0"
13
+ gem "bundler", "~> 1.0.0"
14
+ gem "jeweler", "~> 1.6.4"
15
+ gem "rcov", ">= 0"
16
+ end
@@ -0,0 +1,31 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ columnize (0.3.4)
5
+ git (1.2.5)
6
+ jeweler (1.6.4)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ linecache (0.46)
11
+ rbx-require-relative (> 0.0.4)
12
+ rake (0.9.2.2)
13
+ rbx-require-relative (0.0.5)
14
+ rcov (0.9.11)
15
+ ruby-debug (0.10.4)
16
+ columnize (>= 0.1)
17
+ ruby-debug-base (~> 0.10.4.0)
18
+ ruby-debug-base (0.10.4)
19
+ linecache (>= 0.3)
20
+ shoulda (2.11.3)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ bundler (~> 1.0.0)
27
+ jeweler (~> 1.6.4)
28
+ rake
29
+ rcov
30
+ ruby-debug
31
+ shoulda
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 innov8on.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ = rake-bubbler gem
2
+
3
+ This gem allows capturing raketask output along with additional information (task name, duration, start time, error) while preserving old rake behavior. Such functionality can be useful for logging and monitoring purposes.
4
+
5
+ Actions and prerequisites are captured as well.
6
+
7
+ == Configuration
8
+
9
+ Configuration should be included in Rakefile:
10
+
11
+ RakeBubbler::RakeBubbler.config do |config|
12
+
13
+ # tasks to be captured (default none)
14
+ config.tasks = ['db:migrate', 'upload']
15
+
16
+ config.executed = Proc.new do |task_name, duration, output, started, error|
17
+ puts task_name => "example_task"
18
+ puts duration => 3.0709819
19
+ puts output => "Example output\n"
20
+ puts started => Thu Nov 03 11:13:27 +0100 2011
21
+ puts error => nil
22
+ end
23
+
24
+ # additional conditions required to capture data (optional)
25
+ config.conditions = Proc.new do
26
+ [true, false][rand(2)]
27
+ end
28
+
29
+ end
30
+
31
+ === Executed option parameters
32
+
33
+ [+task_name+] Name of the task.
34
+ [+duration+] Real task duration with actions and prerequisites.
35
+ [+output+] Task output captured from stdout.
36
+ [+started+] Time when task execution began.
37
+ [+error+] Exception captured during task execution. Nil if none.
38
+
39
+ == Contributing to rake-bubbler
40
+
41
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
42
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
43
+ * Fork the project
44
+ * Start a feature/bugfix branch
45
+ * Commit and push until you are happy with your contribution
46
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
47
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
48
+
49
+ == Copyright
50
+
51
+ Copyright (c) 2011 innov8on.com. See LICENSE.txt for
52
+ further details.
53
+
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "rake_bubbler"
18
+ gem.homepage = "http://github.com/Innov8on/RakeBubbler"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Captures raketask output along with additional information (task name, duration, start time, error) for further usage.}
21
+ gem.email = "grzegorz@innov8on.com"
22
+ gem.authors = ["Grzegorz Miklaszewski"]
23
+ # dependencies defined in Gemfile
24
+ end
25
+ Jeweler::RubygemsDotOrgTasks.new
26
+
27
+ require 'rake/testtask'
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.libs << 'lib' << 'test'
30
+ test.pattern = 'test/**/test_*.rb'
31
+ test.verbose = true
32
+ end
33
+
34
+ require 'rcov/rcovtask'
35
+ Rcov::RcovTask.new do |test|
36
+ test.libs << 'test'
37
+ test.pattern = 'test/**/test_*.rb'
38
+ test.verbose = true
39
+ test.rcov_opts << '--exclude "gems/*"'
40
+ end
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "rake_bubbler #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,9 @@
1
+ require 'rake'
2
+
3
+ require 'rake_bubbler/config'
4
+ require 'rake_bubbler/bubble_task'
5
+ require 'rake_bubbler/rake_bubbler'
6
+
7
+ Rake::Task.class_eval do
8
+ include RakeBubbler::BubbleTask
9
+ end
@@ -0,0 +1,43 @@
1
+ require 'benchmark'
2
+ require 'digest/md5'
3
+ require 'shell'
4
+ require 'tempfile'
5
+
6
+ module RakeBubbler
7
+ module BubbleTask
8
+
9
+ def self.included(klass)
10
+ klass.class_eval do
11
+
12
+ def invoke_with_output_capture(*params)
13
+ return invoke_without_output_capture(*params) unless RakeBubbler.capture_task?(name)
14
+
15
+ duration, error = nil
16
+ started = Time.now
17
+
18
+ # capture task output
19
+ output = RakeBubbler.capture_output do
20
+ time = Benchmark.measure(name) do
21
+ begin
22
+ # invoke task
23
+ invoke_without_output_capture(*params)
24
+ rescue Exception => e
25
+ error = e
26
+ end
27
+ end
28
+
29
+ duration = time.real
30
+ end
31
+
32
+ RakeBubbler.executed(name, duration, output, started, error)
33
+ raise error if error
34
+ end # invoke_with_output_capture
35
+
36
+ alias_method :invoke_without_output_capture, :invoke
37
+ alias_method :invoke, :invoke_with_output_capture
38
+
39
+ end
40
+ end
41
+
42
+ end # BubbleTask
43
+ end # RakeBubbler
@@ -0,0 +1,17 @@
1
+ module RakeBubbler
2
+ class Config
3
+ attr_writer :tasks, :conditions, :executed
4
+
5
+ def call_executed(name, duration, output, started, error)
6
+ @executed.respond_to?(:call) && @executed.call(name, duration, output, started, error)
7
+ end
8
+
9
+ def tasks_include?(name)
10
+ @tasks.respond_to?(:include?) && @tasks.include?(name)
11
+ end
12
+
13
+ def call_conditions
14
+ !@conditions.respond_to?(:call) || @conditions.call
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,47 @@
1
+ module RakeBubbler
2
+ module RakeBubbler
3
+ extend self
4
+
5
+ @config = Config.new
6
+
7
+ def config
8
+ yield @config
9
+ end
10
+
11
+ def executed(name, duration, output, started, error)
12
+ @config.call_executed(name, duration, output, started, error)
13
+ end
14
+
15
+ def capture_task?(name)
16
+ @config.tasks_include?(name) && @config.call_conditions
17
+ end
18
+
19
+ def capture_output
20
+ file = Tempfile.new(Digest::MD5.hexdigest((Time.now.to_i + rand(2**16)).to_s))
21
+
22
+ read, write = IO.pipe
23
+
24
+ save_stdout = $stdout.dup
25
+ $stdout.reopen(write)
26
+
27
+ if fork
28
+ read.close
29
+ yield
30
+ write.close
31
+ $stdout.reopen(save_stdout)
32
+ save_stdout.close
33
+ Process.wait
34
+ file.unlink
35
+ file.read
36
+ else
37
+ write.close
38
+ $stdout.close
39
+ Shell.new.tee(file.path) < read > save_stdout
40
+ read.close
41
+ save_stdout.close
42
+ exit!
43
+ end # fork
44
+ end # capture_output
45
+
46
+ end
47
+ end
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rake_bubbler}
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Grzegorz Miklaszewski"]
12
+ s.date = %q{2011-11-03}
13
+ s.email = %q{grzegorz@innov8on.com}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE.txt",
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/rake_bubbler.rb",
27
+ "lib/rake_bubbler/bubble_task.rb",
28
+ "lib/rake_bubbler/config.rb",
29
+ "lib/rake_bubbler/rake_bubbler.rb",
30
+ "rake_bubbler.gemspec",
31
+ "test/helper.rb",
32
+ "test/test_rake_bubbler.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/Innov8on/RakeBubbler}
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.7.2}
38
+ s.summary = %q{Captures raketask output along with additional information (task name, duration, start time, error) for further usage.}
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<rake>, [">= 0"])
45
+ s.add_development_dependency(%q<ruby-debug>, [">= 0"])
46
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
47
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
49
+ s.add_development_dependency(%q<rcov>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<rake>, [">= 0"])
52
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
53
+ s.add_dependency(%q<shoulda>, [">= 0"])
54
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
55
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
56
+ s.add_dependency(%q<rcov>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<rake>, [">= 0"])
60
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
61
+ s.add_dependency(%q<shoulda>, [">= 0"])
62
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
64
+ s.add_dependency(%q<rcov>, [">= 0"])
65
+ end
66
+ end
67
+
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'rake_bubbler'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,79 @@
1
+ require 'helper'
2
+
3
+ class TestRakeBubbler < Test::Unit::TestCase
4
+ extend Rake::DSL
5
+
6
+ task(:bubbler_task1){ puts "Task 1"; sleep 1; }
7
+ task(:bubbler_task2, [:arg1] => :bubbler_task1){ puts "Task 2" }
8
+ task(:error_task){ puts "Error task"; raise 'Help me!!!' }
9
+
10
+ context 'executed block' do
11
+ setup do
12
+ @run = 0
13
+ @name, @duration, @output, @started, @error = nil
14
+
15
+ @executed_proc = Proc.new do |p_name, p_duration, p_output, p_started, p_error|
16
+ @run += 1
17
+ @name = p_name
18
+ @duration = p_duration
19
+ @output = p_output
20
+ @started = p_started
21
+ @error = p_error
22
+ end
23
+ end
24
+
25
+ should 'should be executed if no error' do
26
+ config(['bubbler_task2'], nil, @executed_proc)
27
+ Rake::Task['bubbler_task2'].invoke('10')
28
+
29
+ assert_equal 1, @run
30
+ assert_equal "Task 1\nTask 2\n", @output
31
+ assert_operator @duration, :>, 0
32
+ assert_kind_of Time, @started
33
+ assert_equal 'bubbler_task2', @name
34
+ assert_nil @error
35
+ end
36
+
37
+ should 'be executed if error' do
38
+ config(['error_task'], nil, @executed_proc)
39
+
40
+ assert_raise(RuntimeError) do
41
+ Rake::Task['error_task'].invoke
42
+ end
43
+
44
+ assert_equal 1, @run
45
+ assert_equal "Error task\n", @output
46
+ assert_operator @duration, :>, 0
47
+ assert_kind_of Time, @started
48
+ assert_equal 'error_task', @name
49
+ assert_not_nil @error
50
+ end
51
+ end # end context executed block
52
+
53
+ context '.capture_task?' do
54
+ should 'return true if task is included on the list' do
55
+ config(['bubbler_task1'])
56
+ assert RakeBubbler::RakeBubbler.capture_task?('bubbler_task1')
57
+ end
58
+
59
+ should 'return false if conditions are not met' do
60
+ config(['bubbler_task1'], Proc.new{false})
61
+ assert !RakeBubbler::RakeBubbler.capture_task?('bubbler_task1')
62
+ end
63
+
64
+ should 'return false if task is not on the list' do
65
+ config()
66
+ assert !RakeBubbler::RakeBubbler.capture_task?('bubbler_task1')
67
+ end
68
+ end # end context .capture_task?
69
+
70
+ private
71
+
72
+ def config(tasks = nil, conditions = nil, executed = nil)
73
+ RakeBubbler::RakeBubbler.config do |config|
74
+ config.tasks = tasks
75
+ config.conditions = conditions
76
+ config.executed = executed
77
+ end
78
+ end
79
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rake_bubbler
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Grzegorz Miklaszewski
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-03 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ version_requirements: *id001
31
+ name: rake
32
+ prerelease: false
33
+ type: :runtime
34
+ - !ruby/object:Gem::Dependency
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ hash: 3
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ version_requirements: *id002
45
+ name: ruby-debug
46
+ prerelease: false
47
+ type: :development
48
+ - !ruby/object:Gem::Dependency
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ version_requirements: *id003
59
+ name: shoulda
60
+ prerelease: false
61
+ type: :development
62
+ - !ruby/object:Gem::Dependency
63
+ requirement: &id004 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ hash: 23
69
+ segments:
70
+ - 1
71
+ - 0
72
+ - 0
73
+ version: 1.0.0
74
+ version_requirements: *id004
75
+ name: bundler
76
+ prerelease: false
77
+ type: :development
78
+ - !ruby/object:Gem::Dependency
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ~>
83
+ - !ruby/object:Gem::Version
84
+ hash: 7
85
+ segments:
86
+ - 1
87
+ - 6
88
+ - 4
89
+ version: 1.6.4
90
+ version_requirements: *id005
91
+ name: jeweler
92
+ prerelease: false
93
+ type: :development
94
+ - !ruby/object:Gem::Dependency
95
+ requirement: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ version_requirements: *id006
105
+ name: rcov
106
+ prerelease: false
107
+ type: :development
108
+ description:
109
+ email: grzegorz@innov8on.com
110
+ executables: []
111
+
112
+ extensions: []
113
+
114
+ extra_rdoc_files:
115
+ - LICENSE.txt
116
+ - README.rdoc
117
+ files:
118
+ - .document
119
+ - Gemfile
120
+ - Gemfile.lock
121
+ - LICENSE.txt
122
+ - README.rdoc
123
+ - Rakefile
124
+ - VERSION
125
+ - lib/rake_bubbler.rb
126
+ - lib/rake_bubbler/bubble_task.rb
127
+ - lib/rake_bubbler/config.rb
128
+ - lib/rake_bubbler/rake_bubbler.rb
129
+ - rake_bubbler.gemspec
130
+ - test/helper.rb
131
+ - test/test_rake_bubbler.rb
132
+ homepage: http://github.com/Innov8on/RakeBubbler
133
+ licenses:
134
+ - MIT
135
+ post_install_message:
136
+ rdoc_options: []
137
+
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ hash: 3
146
+ segments:
147
+ - 0
148
+ version: "0"
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ hash: 3
155
+ segments:
156
+ - 0
157
+ version: "0"
158
+ requirements: []
159
+
160
+ rubyforge_project:
161
+ rubygems_version: 1.7.2
162
+ signing_key:
163
+ specification_version: 3
164
+ summary: Captures raketask output along with additional information (task name, duration, start time, error) for further usage.
165
+ test_files: []
166
+