Class: GoodJob::BaseRecord

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/good_job/base_record.rb,
app/models/good_job/base_record.rb

Overview

Base ActiveRecord class that all GoodJob models inherit from. Parent class can be configured with GoodJob.active_record_parent_class.

Direct Known Subclasses

BatchRecord, Execution, Job, Process, Setting

Class Method Summary collapse

Class Method Details

.bind_value(name, value, type_class) ⇒ Object



44
45
46
# File 'app/models/good_job/base_record.rb', line 44

def self.bind_value(name, value, type_class)
  Arel::Nodes::BindParam.new(ActiveRecord::Relation::QueryAttribute.new(name, value, type_class.new))
end

.migrated?Boolean

Checks for whether the schema is up to date. Can be overriden by child class.

Returns:

  • (Boolean)


25
26
27
28
29
30
# File 'app/models/good_job/base_record.rb', line 25

def self.migrated?
  return true if table_exists?

  migration_pending_warning!
  false
end

.migration_pending_warning!Object



12
13
14
15
16
17
18
19
20
# File 'app/models/good_job/base_record.rb', line 12

def self.migration_pending_warning!
  GoodJob.deprecator.warn(<<~DEPRECATION)
    GoodJob has pending database migrations. To create the migration files, run:
        rails generate good_job:update
    To apply the migration files, run:
        rails db:migrate
  DEPRECATION
  nil
end

.with_logger_silenced(silent: true, &block) ⇒ Object

Runs the block with self.logger silenced. If self.logger is nil, simply runs the block.



34
35
36
37
38
39
40
41
42
# File 'app/models/good_job/base_record.rb', line 34

def self.with_logger_silenced(silent: true, &block)
  # Assign to a local variable, just in case it's modified in another thread concurrently
  logger = self.logger
  if silent && logger.respond_to?(:silence)
    logger.silence(&block)
  else
    yield
  end
end