Working prototype
This commit is contained in:
		
							parent
							
								
									97960929cf
								
							
						
					
					
						commit
						5a3b0b8754
					
				
							
								
								
									
										14
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										14
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1,17 +1,3 @@
 | 
				
			|||||||
*.gem
 | 
					 | 
				
			||||||
*.rbc
 | 
					 | 
				
			||||||
.bundle
 | 
					.bundle
 | 
				
			||||||
.config
 | 
					 | 
				
			||||||
.yardoc
 | 
					 | 
				
			||||||
Gemfile.lock
 | 
					Gemfile.lock
 | 
				
			||||||
InstalledFiles
 | 
					 | 
				
			||||||
_yardoc
 | 
					 | 
				
			||||||
coverage
 | 
					 | 
				
			||||||
doc/
 | 
					 | 
				
			||||||
lib/bundler/man
 | 
					 | 
				
			||||||
pkg
 | 
					 | 
				
			||||||
rdoc
 | 
					 | 
				
			||||||
spec/reports
 | 
					 | 
				
			||||||
test/tmp
 | 
					 | 
				
			||||||
test/version_tmp
 | 
					 | 
				
			||||||
tmp
 | 
					tmp
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										17
									
								
								Rakefile
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								Rakefile
									
									
									
									
									
								
							@ -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
									
								
							
							
						
						
									
										11
									
								
								lib/rake/task.rb
									
									
									
									
									
										Normal 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
 | 
				
			||||||
@ -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
 | 
					module RakeControl
 | 
				
			||||||
  # Your code goes here...
 | 
					  def wrap(name, description, &block)
 | 
				
			||||||
 | 
					    Wrapper.new(name, description, block).execute
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  extend self
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +1,3 @@
 | 
				
			|||||||
module RakeControl
 | 
					module RakeControl
 | 
				
			||||||
  VERSION = "0.0.1"
 | 
					  VERSION = '0.1.0'
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										47
									
								
								lib/rake_control/wrapper.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								lib/rake_control/wrapper.rb
									
									
									
									
									
										Normal 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
 | 
				
			||||||
@ -1,23 +1,23 @@
 | 
				
			|||||||
# coding: utf-8
 | 
					 | 
				
			||||||
lib = File.expand_path('../lib', __FILE__)
 | 
					lib = File.expand_path('../lib', __FILE__)
 | 
				
			||||||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
 | 
					$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
 | 
				
			||||||
require 'rake_control/version'
 | 
					require 'rake_control/version'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Gem::Specification.new do |spec|
 | 
					Gem::Specification.new do |spec|
 | 
				
			||||||
  spec.name          = "rake_control"
 | 
					  spec.name          = 'rake_control'
 | 
				
			||||||
  spec.version       = RakeControl::VERSION
 | 
					  spec.version       = RakeControl::VERSION
 | 
				
			||||||
  spec.authors       = ["Gregory Eremin"]
 | 
					  spec.authors       = ['Gregory Eremin']
 | 
				
			||||||
  spec.email         = ["magnolia_fan@me.com"]
 | 
					  spec.email         = ['magnolia_fan@me.com']
 | 
				
			||||||
  spec.description   = %q{TODO: Write a gem description}
 | 
					  spec.description   = %q{}
 | 
				
			||||||
  spec.summary       = %q{TODO: Write a gem summary}
 | 
					  spec.summary       = %q{Rake tasks manager and statistics collector}
 | 
				
			||||||
  spec.homepage      = ""
 | 
					  spec.homepage      = 'https://github.com/magnolia-fan/rake_control'
 | 
				
			||||||
  spec.license       = "MIT"
 | 
					  spec.license       = 'MIT'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  spec.files         = `git ls-files`.split($/)
 | 
					  spec.files         = `git ls-files`.split($/)
 | 
				
			||||||
  spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
 | 
					  spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
 | 
				
			||||||
  spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
 | 
					  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_runtime_dependency 'rake'
 | 
				
			||||||
  spec.add_development_dependency "rake"
 | 
					  spec.add_development_dependency 'bundler', '~> 1.3'
 | 
				
			||||||
 | 
					  # spec.add_development_dependency 'sqlite'
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user