Class: ArRepository
- Inherits:
-
Object
- Object
- ArRepository
- Defined in:
- lib/kick_ahead/ar_repository.rb
Instance Method Summary collapse
- #create(job_class, schedule_at, *args) ⇒ Object
- #delete(id) ⇒ Object
- #each_job_in_the_past ⇒ Object
-
#initialize(klass) ⇒ ArRepository
constructor
A new instance of ArRepository.
Constructor Details
#initialize(klass) ⇒ ArRepository
Returns a new instance of ArRepository.
2 3 4 |
# File 'lib/kick_ahead/ar_repository.rb', line 2 def initialize(klass) @klass = klass end |
Instance Method Details
#create(job_class, schedule_at, *args) ⇒ Object
12 13 14 15 |
# File 'lib/kick_ahead/ar_repository.rb', line 12 def create(job_class, schedule_at, *args) job = @klass.create! job_class: job_class, job_args: args, scheduled_at: schedule_at job.id end |
#delete(id) ⇒ Object
17 18 19 20 |
# File 'lib/kick_ahead/ar_repository.rb', line 17 def delete(id) raise 'Not possible!' if id.nil? @klass.find(id).delete end |
#each_job_in_the_past ⇒ Object
6 7 8 9 10 |
# File 'lib/kick_ahead/ar_repository.rb', line 6 def each_job_in_the_past @klass.where('scheduled_at <= ?', KickAhead.current_time.call).find_each do |job| yield(as_hash(job)) end end |