From 6b185c44ac8ff7acf6cb30419a2bf480a9a3735d Mon Sep 17 00:00:00 2001 From: Dzmitry Plashchynski Date: Mon, 2 Mar 2015 22:03:18 +0200 Subject: [PATCH] Add PerformerProxy --- lib/periodicity.rb | 1 + lib/periodicity/performer_proxy.rb | 15 +++++++++++++++ spec/performer_proxy_spec.rb | 13 +++++++++++++ spec/spec_helper.rb | 1 - 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 lib/periodicity/performer_proxy.rb create mode 100644 spec/performer_proxy_spec.rb diff --git a/lib/periodicity.rb b/lib/periodicity.rb index 8311015..0ca81d8 100644 --- a/lib/periodicity.rb +++ b/lib/periodicity.rb @@ -5,3 +5,4 @@ require "active_support/all" require "periodicity/version.rb" require "periodicity/period.rb" require "periodicity/config.rb" +require "periodicity/performer_proxy.rb" \ No newline at end of file diff --git a/lib/periodicity/performer_proxy.rb b/lib/periodicity/performer_proxy.rb new file mode 100644 index 0000000..b57bf11 --- /dev/null +++ b/lib/periodicity/performer_proxy.rb @@ -0,0 +1,15 @@ +module Periodicity + class PerformerProxy + def initialize(performer) + @performer = performer + end + + def every(period, *args) + Config.instance.schedule += [@performer, Period.new(period, *args)] + end + end + + def self.perform(performer) + PerformerProxy.new(performer) + end +end diff --git a/spec/performer_proxy_spec.rb b/spec/performer_proxy_spec.rb new file mode 100644 index 0000000..d77c022 --- /dev/null +++ b/spec/performer_proxy_spec.rb @@ -0,0 +1,13 @@ +require "spec_helper" +require "active_job" + +class TestJob < ActiveJob::Base + def perform;end +end + +describe Periodicity::PerformerProxy do + it "should add job and period to schedule" do + Periodicity.perform(TestJob).every(2.days, at: "15:30") + expect(Periodicity::Config.instance.schedule).to_not be_empty + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6f68c42..2c822b8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,6 @@ require 'bundler/setup' Bundler.setup -require 'active_job' require 'timecop' require 'periodicity'