mirror of
https://github.com/plashchynski/crono.git
synced 2026-07-11 07:12:50 +02:00
Add basic Period class
This commit is contained in:
@@ -3,6 +3,7 @@ PATH
|
|||||||
specs:
|
specs:
|
||||||
periodicity (0.0.1)
|
periodicity (0.0.1)
|
||||||
activejob
|
activejob
|
||||||
|
activesupport
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
@@ -37,6 +38,7 @@ GEM
|
|||||||
rspec-support (~> 3.2.0)
|
rspec-support (~> 3.2.0)
|
||||||
rspec-support (3.2.2)
|
rspec-support (3.2.2)
|
||||||
thread_safe (0.3.4)
|
thread_safe (0.3.4)
|
||||||
|
timecop (0.7.3)
|
||||||
tzinfo (1.2.2)
|
tzinfo (1.2.2)
|
||||||
thread_safe (~> 0.1)
|
thread_safe (~> 0.1)
|
||||||
|
|
||||||
@@ -48,3 +50,4 @@ DEPENDENCIES
|
|||||||
periodicity!
|
periodicity!
|
||||||
rake
|
rake
|
||||||
rspec (~> 3.0)
|
rspec (~> 3.0)
|
||||||
|
timecop
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
module Periodicity
|
module Periodicity
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require "active_support/all"
|
||||||
require "periodicity/version.rb"
|
require "periodicity/version.rb"
|
||||||
require "periodicity/period.rb"
|
require "periodicity/period.rb"
|
||||||
require "periodicity/rails.rb"
|
require "periodicity/rails.rb"
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
module Periodicity
|
module Periodicity
|
||||||
module Extensions
|
module Extensions
|
||||||
class ActiveJob
|
class ActiveJob
|
||||||
def perform_every(period, *args)
|
def self.perform_every(period, *args)
|
||||||
|
@period = period
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
module Periodicity
|
||||||
|
class Period
|
||||||
|
def initialize(period)
|
||||||
|
@period = period
|
||||||
|
end
|
||||||
|
|
||||||
|
def next
|
||||||
|
@period.from_now
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -13,9 +13,11 @@ Gem::Specification.new do |s|
|
|||||||
s.rubyforge_project = "periodicity"
|
s.rubyforge_project = "periodicity"
|
||||||
|
|
||||||
s.add_runtime_dependency "activejob"
|
s.add_runtime_dependency "activejob"
|
||||||
|
s.add_runtime_dependency "activesupport"
|
||||||
s.add_development_dependency "rake"
|
s.add_development_dependency "rake"
|
||||||
s.add_development_dependency "bundler", ">= 1.0.0"
|
s.add_development_dependency "bundler", ">= 1.0.0"
|
||||||
s.add_development_dependency "rspec", "~> 3.0"
|
s.add_development_dependency "rspec", "~> 3.0"
|
||||||
|
s.add_development_dependency "timecop"
|
||||||
|
|
||||||
s.files = `git ls-files`.split("\n")
|
s.files = `git ls-files`.split("\n")
|
||||||
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
require "spec_helper"
|
||||||
|
|
||||||
|
describe Periodicity::Period do
|
||||||
|
around(:each) do |example|
|
||||||
|
Timecop.freeze do
|
||||||
|
example.run
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#next" do
|
||||||
|
context "in daily basis" do
|
||||||
|
it "should return the time 2 days from now" do
|
||||||
|
@period = Periodicity::Period.new(2.day)
|
||||||
|
expect(@period.next).to be_eql(2.day.from_now)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
require 'bundler/setup'
|
require 'bundler/setup'
|
||||||
Bundler.setup
|
Bundler.setup
|
||||||
|
|
||||||
|
require 'timecop'
|
||||||
require 'periodicity'
|
require 'periodicity'
|
||||||
|
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user