Module: CronTable::Schedule::PrependedClassMethods

Defined in:
lib/cron-table/schedule.rb

Instance Method Summary collapse

Instance Method Details

#crontable(every:, key: self.name, &block) ⇒ Object

Raises:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cron-table/schedule.rb', line 32

def crontable(every:, key: self.name, &block)
  raise DuplicateKeyError.new(key) if CronTable.all.key? key

  block ||= -> { self.perform_later } if self.respond_to?(:perform_later)
  raise MissingBlockError if block.nil?

  case every
  when ActiveSupport::Duration
  when *CronTable.every.keys
  else
    raise InvalidEvery.new(every)
  end

  CronTable.all[key] = Definition.new(key:, every:, block:)

  self
end