Sha256: a0e39f289a6fc5abbc211e34f397a24ab6c13f3abb03a6ee7d1401511ab45eeb

Contents?: true

Size: 1.23 KB

Versions: 11

Compression:

Stored size: 1.23 KB

Contents

if defined?(CarrierWave::Mount)
  require 'carrierwave/orm/activerecord'
end

module Tramway
  module Core
    class ApplicationRecord < ActiveRecord::Base
      self.abstract_class = true
      audited
      extend ::Enumerize

      state_machine :state, initial: :active do
        state :active
        state :removed

        event :remove do
          transition active: :remove
        end
      end

      scope :active, -> { where state: :active }

      include ::PgSearch

      # FIXME detect inhertited locales
      class << self
        def human_attribute_name(attribute_name, *args)
          excepted_attributes = %w( created_at updated_at state )
          if attribute_name.to_s.in? excepted_attributes
            I18n.t "activerecord.attributes.tramway/core/application_record.#{attribute_name}"
          else
            super attribute_name
          end
        end

        def search_by(*attributes, **associations)
          pg_search_scope :full_text_search, against: attributes, associated_against: associations
        end
      end

      # FIXME detect inhertited locales
      def human_state_name
        I18n.t "activerecord.state_machines.tramway/core/application_record.state.states.#{state}"
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
tramway-core-1.13.1.1 app/models/tramway/core/application_record.rb
tramway-core-1.13.1 app/models/tramway/core/application_record.rb
tramway-core-1.13.0.2 app/models/tramway/core/application_record.rb
tramway-core-1.13.0.1 app/models/tramway/core/application_record.rb
tramway-core-1.13 app/models/tramway/core/application_record.rb
tramway-core-1.12.1 app/models/tramway/core/application_record.rb
tramway-core-1.12.0.2 app/models/tramway/core/application_record.rb
tramway-core-1.12.0.1 app/models/tramway/core/application_record.rb
tramway-core-1.12 app/models/tramway/core/application_record.rb
tramway-core-1.11.2.1 app/models/tramway/core/application_record.rb
tramway-core-1.11.2 app/models/tramway/core/application_record.rb