mirror of
https://github.com/plashchynski/crono.git
synced 2026-03-20 00:24:42 +01:00
Add basic Period class
This commit is contained in:
@@ -3,6 +3,7 @@ PATH
|
||||
specs:
|
||||
periodicity (0.0.1)
|
||||
activejob
|
||||
activesupport
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
@@ -37,6 +38,7 @@ GEM
|
||||
rspec-support (~> 3.2.0)
|
||||
rspec-support (3.2.2)
|
||||
thread_safe (0.3.4)
|
||||
timecop (0.7.3)
|
||||
tzinfo (1.2.2)
|
||||
thread_safe (~> 0.1)
|
||||
|
||||
@@ -48,3 +50,4 @@ DEPENDENCIES
|
||||
periodicity!
|
||||
rake
|
||||
rspec (~> 3.0)
|
||||
timecop
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module Periodicity
|
||||
end
|
||||
|
||||
require "active_support/all"
|
||||
require "periodicity/version.rb"
|
||||
require "periodicity/period.rb"
|
||||
require "periodicity/rails.rb"
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
module Periodicity
|
||||
module Extensions
|
||||
class ActiveJob
|
||||
def perform_every(period, *args)
|
||||
def self.perform_every(period, *args)
|
||||
@period = period
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
11
lib/periodicity/period.rb
Normal file
11
lib/periodicity/period.rb
Normal file
@@ -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.add_runtime_dependency "activejob"
|
||||
s.add_runtime_dependency "activesupport"
|
||||
s.add_development_dependency "rake"
|
||||
s.add_development_dependency "bundler", ">= 1.0.0"
|
||||
s.add_development_dependency "rspec", "~> 3.0"
|
||||
s.add_development_dependency "timecop"
|
||||
|
||||
s.files = `git ls-files`.split("\n")
|
||||
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
||||
|
||||
18
spec/period_spec.rb
Normal file
18
spec/period_spec.rb
Normal file
@@ -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'
|
||||
Bundler.setup
|
||||
|
||||
require 'timecop'
|
||||
require 'periodicity'
|
||||
|
||||
|
||||
RSpec.configure do |config|
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user