Statistics

This commit is contained in:
Gregory Eremin 2013-06-05 00:41:48 +04:00
parent 7c6e2f442e
commit 16ea9b47f3
5 changed files with 57 additions and 8 deletions

View File

@ -1,24 +1,34 @@
# RakeControl # RakeControl
TODO: Write a gem description RakeControl is a tool for managing Rake tasks.
## Installation ## Installation
Add this line to your application's Gemfile: Add this line to your application's Gemfile:
```ruby
gem 'rake_control' gem 'rake_control'
```
And then execute: 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 ## Usage
TODO: Write usage instructions here stats = Rake::Task['my:task:name'].stats
stats.log
## Contributing ## Contributing

View File

@ -7,5 +7,9 @@ module Rake
original_execute(args) original_execute(args)
end end
end end
def stats
RakeControl::Statistics.new(name)
end
end end
end end

View File

@ -2,8 +2,9 @@ require 'bundler/setup'
require 'rake' require 'rake'
require File.expand_path('../rake/task', __FILE__) require File.expand_path('../rake/task', __FILE__)
require 'rake_control/version'
require 'rake_control/config' require 'rake_control/config'
require 'rake_control/statistics'
require 'rake_control/version'
require 'rake_control/wrapper' require 'rake_control/wrapper'
module RakeControl module RakeControl
@ -11,6 +12,11 @@ module RakeControl
@config ||= Config.new @config ||= Config.new
end end
def configure
yield config if block_given?
config.apply
end
def wrap(name, description, &block) def wrap(name, description, &block)
Wrapper.new(name, description, block).execute Wrapper.new(name, description, block).execute
end end

View File

@ -6,6 +6,12 @@ module RakeControl
@storage = :active_record @storage = :active_record
end end
def apply
setup_storage_model
end
private
def setup_storage_model def setup_storage_model
case storage case storage
when :active_record, :activerecord when :active_record, :activerecord

View File

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