Module: Dripper

Defined in:
lib/dripper.rb,
lib/dripper/resque_scheduler.rb

Defined Under Namespace

Modules: ClassMethods, ResqueScheduler

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



6
7
8
# File 'lib/dripper.rb', line 6

def self.included(klass)
  klass.extend ClassMethods
end

Instance Method Details

#enqueue(time) ⇒ Object



50
51
52
# File 'lib/dripper.rb', line 50

def enqueue(time)
  # nothing here
end

#initialize(instance) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
14
# File 'lib/dripper.rb', line 10

def initialize(instance)
  raise ArgumentError, "The object must respond to #id" unless instance.respond_to?(:id)
  raise ArgumentError, "The object must respond to #created_at" unless instance.respond_to?(:created_at)
  @instance = instance
end

#offset_time(offset) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dripper.rb', line 20

def offset_time(offset)
  calculated_time = starting_time + offset
  options = self.class.send_at_options
  unless options[:weekends]
    if calculated_time.wday == 6 # Saturday
      calculated_time = calculated_time - 1.day
    elsif calculated_time.wday == 0 # Sunday
      calculated_time = calculated_time + 1.day
    end
  end
  calculated_time
end

#schedule!Object



44
45
46
47
48
# File 'lib/dripper.rb', line 44

def schedule!
  scheduled_times.each do |time|
    enqueue(time)
  end
end

#scheduled_timesObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/dripper.rb', line 33

def scheduled_times
  offset = self.class.send_at_offset
  self.class.after_blocks.map do |b|
    t = offset_time(b[:offset])
    if offset and b[:offset] >= 1.day
      t = t.beginning_of_day + offset[0].hours + offset[1].minutes
    end
    t
  end
end

#starting_timeObject



16
17
18
# File 'lib/dripper.rb', line 16

def starting_time
  @instance.created_at  # Fix this
end