Class: Marj::Relation

Inherits:
Object
  • Object
show all
Includes:
Enumerable, JobsInterface
Defined in:
lib/marj/relation.rb

Overview

Returned by JobsInterface query methods to enable chaining and Enumerable methods.

Instance Method Summary collapse

Methods included from JobsInterface

#count, #discard_all, #due, #next, #perform_all, #queue, #where

Constructor Details

#initialize(ar_relation) ⇒ Relation

Returns a Marj::Relation which wraps the specified ActiveRecord relation.



15
16
17
# File 'lib/marj/relation.rb', line 15

def initialize(ar_relation)
  @all = ar_relation
end

Instance Method Details

#each(&block) ⇒ Array

Yields each job in this relation.

Parameters:

  • block (Proc)

Returns:

  • (Array)

    the jobs in this relation



23
24
25
# File 'lib/marj/relation.rb', line 23

def each(&block)
  all.map(&:as_job).each(&block)
end

#pretty_print(pp) ⇒ NilClass

Provides pretty_inspect output containing arrays of jobs rather than arrays of records, similar to the output produced when calling pretty_inspect on ActiveRecord::Relation.

Instead of the default pretty_inspect output:

> Marj.all
 =>
#<Marj::Relation:0x000000012728bd88
 @ar_relation=
  [#<Marj::Record:0x0000000126c42080
    job_id: "1382cb98-c518-46ca-a0cc-d831e11a0714",
    job_class: TestJob,
    arguments: ["foo"],
    queue_name: "default",
    priority: nil,
    executions: 0,
    exception_executions: {},
    enqueued_at: 2024-01-25 15:31:06.115773 UTC,
    scheduled_at: nil,
    locale: "en",
    timezone: "UTC">]>

Produces:

> Marj.all
 =>
[#<TestJob:0x000000010b63cef8
  @_scheduled_at_time=nil,
  @arguments=[],
  @enqueued_at=2024-01-25 15:31:06 UTC,
  @exception_executions={},
  @executions=0,
  @job_id="1382cb98-c518-46ca-a0cc-d831e11a0714",
  @locale="en",
  @priority=nil,
  @provider_job_id=nil,
  @queue_name="default",
  @scheduled_at=nil,
  @serialized_arguments=["foo"],
  @timezone="UTC">]

Parameters:

  • pp (PP)

Returns:

  • (NilClass)


68
69
70
# File 'lib/marj/relation.rb', line 68

def pretty_print(pp)
  pp.pp(to_a)
end