Sha256: 8e2f6db8fa1aee422570a21cec727c75162c69dd76ed4accddf5f669f969f208

Contents?: true

Size: 1.53 KB

Versions: 10

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

module GoodJob
  # Base ActiveRecord class that all GoodJob models inherit from.
  # Parent class can be configured with +GoodJob.active_record_parent_class+.
  # @!parse
  #   class BaseRecord < ActiveRecord::Base; end
  class BaseRecord < ActiveRecordParentClass
    self.abstract_class = true
    self.strict_loading_by_default = false

    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

    # Checks for whether the schema is up to date.
    # Can be overriden by child class.
    # @return [Boolean]
    def self.migrated?
      return true if table_exists?

      migration_pending_warning!
      false
    end

    # Runs the block with self.logger silenced.
    # If self.logger is nil, simply runs the block.
    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

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

ActiveSupport.run_load_hooks(:good_job_base_record, GoodJob::BaseRecord)

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
good_job-4.8.0 app/models/good_job/base_record.rb
good_job-4.7.0 app/models/good_job/base_record.rb
good_job-4.6.0 app/models/good_job/base_record.rb
good_job-4.5.1 app/models/good_job/base_record.rb
good_job-4.5.0 app/models/good_job/base_record.rb
good_job-4.4.2 app/models/good_job/base_record.rb
good_job-4.4.1 app/models/good_job/base_record.rb
good_job-4.4.0 app/models/good_job/base_record.rb
good_job-4.3.0 app/models/good_job/base_record.rb
good_job-4.2.1 app/models/good_job/base_record.rb