diff --git a/burden_web/app/controllers/burden_web/application_controller.rb b/burden_web/app/controllers/burden_web/application_controller.rb index 063eab5..178319b 100644 --- a/burden_web/app/controllers/burden_web/application_controller.rb +++ b/burden_web/app/controllers/burden_web/application_controller.rb @@ -1,9 +1,11 @@ module BurdenWeb class ApplicationController < ActionController::Base - def tasks - Rails.application.load_tasks - Rake.application.tasks.keep_if do |task| - task.name =~ /^[a-z0-9_:]+$/ + def rake_tasks + @rake_tasks ||= begin + Rails.application.load_tasks + Rake.application.tasks.keep_if do |task| + task.name =~ /^[a-z0-9_:]+$/ + end end end end diff --git a/burden_web/app/controllers/burden_web/runs_controller.rb b/burden_web/app/controllers/burden_web/runs_controller.rb index 7bf0d1c..35c8add 100644 --- a/burden_web/app/controllers/burden_web/runs_controller.rb +++ b/burden_web/app/controllers/burden_web/runs_controller.rb @@ -1,7 +1,7 @@ module BurdenWeb class RunsController < ApplicationController def index - @runs = Burden::Storage.run.history(params[:task_id]) + @runs = Burden.runs.history(params[:task_id]) end end end diff --git a/burden_web/app/controllers/burden_web/tasks_controller.rb b/burden_web/app/controllers/burden_web/tasks_controller.rb index 538f9f2..c41e613 100644 --- a/burden_web/app/controllers/burden_web/tasks_controller.rb +++ b/burden_web/app/controllers/burden_web/tasks_controller.rb @@ -1,10 +1,10 @@ module BurdenWeb class TasksController < ApplicationController def index - @tasks = Burden::Storage.run.summary - (tasks.map(&:name) - @tasks.map(&:name)).each do |nr_task| # Never runned tasks + @tasks = Burden.runs.summary + (rake_tasks.map(&:name) - @tasks.map(&:name)).each do |nr_task| # Never runned tasks next if ignore? nr_task - @tasks << Burden::Storage.run.new( + @tasks << Burden.runs.new( name: nr_task ) end diff --git a/burden_web/lib/burden_web/version.rb b/burden_web/lib/burden_web/version.rb index 56e1f92..dc37116 100644 --- a/burden_web/lib/burden_web/version.rb +++ b/burden_web/lib/burden_web/version.rb @@ -1,3 +1,3 @@ module BurdenWeb - VERSION = '0.1.1' + VERSION = '0.1.2' end diff --git a/lib/burden.rb b/lib/burden.rb index e47ce00..0177884 100644 --- a/lib/burden.rb +++ b/lib/burden.rb @@ -11,11 +11,7 @@ require 'burden/version' require 'burden/wrapper' module Burden - include Config::Helper - - def wrap(name, &block) - Wrapper.new(name, block).execute - end - - extend self + extend Config::Helper + extend Storage::Helper + extend Wrapper::Helper end diff --git a/lib/burden/statistics.rb b/lib/burden/statistics.rb index 82408f3..25d7961 100644 --- a/lib/burden/statistics.rb +++ b/lib/burden/statistics.rb @@ -16,7 +16,7 @@ module Burden ActiveRecord::Base.establish_connection(conf) begin - Storage.run.create(name: name, success: success, execution_time: execution_time, timestamp: timestamp) + Burden.runs.create(name: name, success: success, execution_time: execution_time, timestamp: timestamp) rescue log_to_stdout(:failed) end diff --git a/lib/burden/storage.rb b/lib/burden/storage.rb index 253f757..2ed9203 100644 --- a/lib/burden/storage.rb +++ b/lib/burden/storage.rb @@ -1,21 +1,23 @@ module Burden module Storage - def run - case Burden.config.storage - when :active_record, :activerecord - require 'burden/storage/active_record/run' - Burden::Storage::ActiveRecord::Run - when :mongoid - require 'burden/storage/mongoid/run' - Burden::Storage::Mongoid::Run - when :mongo_mapper, :mongomapper - require 'burden/storage/mongo_mapper/run' - Burden::Storage::MongoMapper::Run - else - raise Exception.new("Unknown storage: #{storage}") + module Helper + def runs + @storage_class ||= begin + case Burden.config.storage + when :active_record, :activerecord + require 'burden/storage/active_record/run' + Burden::Storage::ActiveRecord::Run + when :mongoid + require 'burden/storage/mongoid/run' + Burden::Storage::Mongoid::Run + when :mongo_mapper, :mongomapper + require 'burden/storage/mongo_mapper/run' + Burden::Storage::MongoMapper::Run + else + raise Exception.new("Unknown storage: #{storage}") + end + end end end - - extend self end end diff --git a/lib/burden/version.rb b/lib/burden/version.rb index b097a22..f34a1fc 100644 --- a/lib/burden/version.rb +++ b/lib/burden/version.rb @@ -1,3 +1,3 @@ module Burden - VERSION = '0.1.1' + VERSION = '0.1.2' end diff --git a/lib/burden/wrapper.rb b/lib/burden/wrapper.rb index 60c0281..471e687 100644 --- a/lib/burden/wrapper.rb +++ b/lib/burden/wrapper.rb @@ -54,5 +54,11 @@ module Burden def save_statistics Statistics.new(name: name, success: success, execution_time: execution_time, timestamp: timestamp).save end + + module Helper + def wrap(name, &block) + Wrapper.new(name, block).execute + end + end end end