Sha256: e6659650bd483031c3220bd3efba55b8569d57eea07be5b472206582e6957d4f

Contents?: true

Size: 1.47 KB

Versions: 17

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

module PgEngine
  # rubocop:disable Rails/ApplicationRecord
  class BaseRecord < ActiveRecord::Base
    # rubocop:enable Rails/ApplicationRecord
    extend Enumerize
    include PrintHelper
    include PostgresHelper
    include Naming

    self.abstract_class = true

    before_create :setear_creado_y_actualizado_por
    before_update :setear_actualizado_por

    scope :unkept, -> { discarded }
    # ransacker :search do |parent|
    #   parent.table[:nombre]
    # end

    # Para el dom_id (index.html)
    def to_key
      if respond_to? :hashid
        [hashid]
      else
        super
      end
    end

    # overriden by PgEngine::ChildRecord
    def parent?
      false
    end

    def to_s
      %i[nombre name].each do |campo|
        # Using `_in_database` for consistent breadcrumbs when editing the name
        campo = :"#{campo}_in_database"

        return "#{send(campo)} ##{to_param}" if try(campo).present?
      end
      if to_param.present?
        "#{self.class.nombre_singular} ##{to_param}"
      else
        super
      end
    end

    private

    def setear_creado_y_actualizado_por
      setear_si_existe :creado_por, Current.user
      setear_si_existe :actualizado_por, Current.user
    end

    def setear_actualizado_por
      setear_si_existe :actualizado_por, Current.user
    end

    def setear_si_existe(campo, valor)
      metodo = "#{campo}="
      send(metodo, valor) if respond_to?(metodo) && valor.present?
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
pg_rails-7.6.23 pg_engine/app/models/pg_engine/base_record.rb
pg_rails-7.6.22 pg_engine/app/models/pg_engine/base_record.rb
pg_rails-7.6.22.pre.3 pg_engine/app/models/pg_engine/base_record.rb
pg_rails-7.6.22.pre.2 pg_engine/app/models/pg_engine/base_record.rb
pg_rails-7.6.22.pre.1 pg_engine/app/models/pg_engine/base_record.rb
pg_rails-7.6.21 pg_engine/app/models/pg_engine/base_record.rb
pg_rails-7.6.21.pre.11 pg_engine/app/models/pg_engine/base_record.rb
pg_rails-7.6.21.pre.10 pg_engine/app/models/pg_engine/base_record.rb
pg_rails-7.6.21.pre.9 pg_engine/app/models/pg_engine/base_record.rb
pg_rails-7.6.21.pre.8 pg_engine/app/models/pg_engine/base_record.rb
pg_rails-7.6.21.pre.7 pg_engine/app/models/pg_engine/base_record.rb
pg_rails-7.6.21.pre.6 pg_engine/app/models/pg_engine/base_record.rb
pg_rails-7.6.21.pre.5 pg_engine/app/models/pg_engine/base_record.rb
pg_rails-7.6.21.pre.4 pg_engine/app/models/pg_engine/base_record.rb
pg_rails-7.6.21.pre.3 pg_engine/app/models/pg_engine/base_record.rb
pg_rails-7.6.21.pre.2 pg_engine/app/models/pg_engine/base_record.rb
pg_rails-7.6.21.pre.1 pg_engine/app/models/pg_engine/base_record.rb