Working prototype

This commit is contained in:
Gregory Eremin
2013-06-04 22:11:41 +04:00
parent 97960929cf
commit 5a3b0b8754
7 changed files with 94 additions and 29 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
module RakeControl
VERSION = "0.0.1"
VERSION = '0.1.0'
end
+47
View File
@@ -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