From 16ea9b47f3a1b3644a78b9558c6b29cb97da5dfb Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Wed, 5 Jun 2013 00:41:48 +0400 Subject: [PATCH] Statistics --- README.md | 24 +++++++++++++++++------- lib/rake/task.rb | 4 ++++ lib/rake_control.rb | 8 +++++++- lib/rake_control/config.rb | 6 ++++++ lib/rake_control/statistics.rb | 23 +++++++++++++++++++++++ 5 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 lib/rake_control/statistics.rb diff --git a/README.md b/README.md index 1cfa3ec..b0052c7 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,34 @@ # RakeControl -TODO: Write a gem description +RakeControl is a tool for managing Rake tasks. ## Installation Add this line to your application's Gemfile: - - gem 'rake_control' +```ruby +gem 'rake_control' +``` And then execute: +``` +$ bundle +``` - $ bundle +## Configuration -Or install it yourself as: - $ gem install rake_control +Add this lines to the top of your application's Rakefile: +```ruby +require 'rake_control' +RakeControl.configure do |c| + c.storage = :active_record # or :mongoid, :mongo_mapper +end +``` ## Usage -TODO: Write usage instructions here +stats = Rake::Task['my:task:name'].stats +stats.log ## Contributing diff --git a/lib/rake/task.rb b/lib/rake/task.rb index 12e1173..456334f 100644 --- a/lib/rake/task.rb +++ b/lib/rake/task.rb @@ -7,5 +7,9 @@ module Rake original_execute(args) end end + + def stats + RakeControl::Statistics.new(name) + end end end diff --git a/lib/rake_control.rb b/lib/rake_control.rb index c1b6da2..e2203b4 100644 --- a/lib/rake_control.rb +++ b/lib/rake_control.rb @@ -2,8 +2,9 @@ require 'bundler/setup' require 'rake' require File.expand_path('../rake/task', __FILE__) -require 'rake_control/version' require 'rake_control/config' +require 'rake_control/statistics' +require 'rake_control/version' require 'rake_control/wrapper' module RakeControl @@ -11,6 +12,11 @@ module RakeControl @config ||= Config.new end + def configure + yield config if block_given? + config.apply + end + def wrap(name, description, &block) Wrapper.new(name, description, block).execute end diff --git a/lib/rake_control/config.rb b/lib/rake_control/config.rb index bcf0cc9..a14be88 100644 --- a/lib/rake_control/config.rb +++ b/lib/rake_control/config.rb @@ -6,6 +6,12 @@ module RakeControl @storage = :active_record end + def apply + setup_storage_model + end + + private + def setup_storage_model case storage when :active_record, :activerecord diff --git a/lib/rake_control/statistics.rb b/lib/rake_control/statistics.rb new file mode 100644 index 0000000..f8d6008 --- /dev/null +++ b/lib/rake_control/statistics.rb @@ -0,0 +1,23 @@ +module RakeControl + class Statistics + attr_reader :name + + def initialize(name) + @name = name + end + + def last + relation.last + end + + def log + relation.all + end + + private + + def relation + Run.where(name: name) + end + end +end