Working prototype
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
module Rake
|
||||
class Task
|
||||
alias :original_execute :execute
|
||||
|
||||
def execute(args)
|
||||
RakeControl.wrap(name, comment) do
|
||||
original_execute(args)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
+8
-2
@@ -1,5 +1,11 @@
|
||||
require "rake_control/version"
|
||||
require 'rake_control/version'
|
||||
require 'rake_control/wrapper'
|
||||
require File.expand_path('../rake/task', __FILE__)
|
||||
|
||||
module RakeControl
|
||||
# Your code goes here...
|
||||
def wrap(name, description, &block)
|
||||
Wrapper.new(name, description, block).execute
|
||||
end
|
||||
|
||||
extend self
|
||||
end
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module RakeControl
|
||||
VERSION = "0.0.1"
|
||||
VERSION = '0.1.0'
|
||||
end
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
module RakeControl
|
||||
class Wrapper
|
||||
attr_reader :name, :description, :block, :success, :exception, :execution_time
|
||||
|
||||
def initialize(name, description, block)
|
||||
@name = name
|
||||
@description = description
|
||||
@block = block
|
||||
@success = true
|
||||
end
|
||||
|
||||
def execute
|
||||
result = measure_time do
|
||||
intercept_exceptions do
|
||||
block.call
|
||||
end
|
||||
end
|
||||
save_statistics
|
||||
|
||||
success ? result : raise(exception)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def measure_time
|
||||
t = Time.now
|
||||
result = yield
|
||||
@execution_time = Time.now.to_f - t.to_f
|
||||
result
|
||||
end
|
||||
|
||||
def intercept_exceptions
|
||||
begin
|
||||
yield
|
||||
rescue => e
|
||||
@success = false
|
||||
@exception = e
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def save_statistics
|
||||
puts "Task #{name} #{success ? 'finished successfully' : 'failed'}"
|
||||
puts "Execution time: #{execution_time.round(4)}"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user