1
0
Fork 0

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

14
.gitignore vendored
View File

@ -1,17 +1,3 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp

View File

@ -1 +1,16 @@
require "bundler/gem_tasks"
require 'bundler/gem_tasks'
require 'rake_control'
task :regular_task do
puts 'I am being invoked'
end
task :failing_task do
raise 'wtf'
end
task :sleepy_task do
puts 'Sleeping...'
sleep 2
puts 'Woke up!'
end

11
lib/rake/task.rb Normal file
View File

@ -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

View File

@ -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

View File

@ -1,3 +1,3 @@
module RakeControl
VERSION = "0.0.1"
VERSION = '0.1.0'
end

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

View File

@ -1,23 +1,23 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'rake_control/version'
Gem::Specification.new do |spec|
spec.name = "rake_control"
spec.name = 'rake_control'
spec.version = RakeControl::VERSION
spec.authors = ["Gregory Eremin"]
spec.email = ["magnolia_fan@me.com"]
spec.description = %q{TODO: Write a gem description}
spec.summary = %q{TODO: Write a gem summary}
spec.homepage = ""
spec.license = "MIT"
spec.authors = ['Gregory Eremin']
spec.email = ['magnolia_fan@me.com']
spec.description = %q{}
spec.summary = %q{Rake tasks manager and statistics collector}
spec.homepage = 'https://github.com/magnolia-fan/rake_control'
spec.license = 'MIT'
spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.require_paths = ['lib']
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_runtime_dependency 'rake'
spec.add_development_dependency 'bundler', '~> 1.3'
# spec.add_development_dependency 'sqlite'
end