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.

Class Method Summary collapse

Class Method Details

.bind_value(name, value, type_class) ⇒ Object



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

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)


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

def self.migrated?
  return true if table_exists?

  migration_pending_warning!
  false
end

.migration_pending_warning!Object



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

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.



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

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