Sha256: e55ae90d144724b64c454efa266977823e49e5f0bc169719041f8509b9bcceed

Contents?: true

Size: 1.44 KB

Versions: 20

Compression:

Stored size: 1.44 KB

Contents

module PgEngine
  module Naming
    deprecate :gender, deprecator: PgEngine.deprecator
    def gender
      self.class.model_name.human.downcase.ends_with?('a') ? 'f' : 'm'
    end

    def self.included(base)
      base.extend(ClassMethods)
    end

    module ClassMethods
      # This is a per class variable, all subclasses of BaseRecord inherit it
      # BUT **the values are independent between all of them**
      attr_accessor :default_modal, :inline_editable_fields

      def gender
        model_name.human.downcase.ends_with?('a') ? 'f' : 'm'
      end

      def inline_editable?(attribute)
        inline_editable_fields.present? && inline_editable_fields.include?(attribute.to_sym)
      end

      def ransackable_associations(_auth_object = nil)
        authorizable_ransackable_associations
      end

      def ransackable_attributes(_auth_object = nil)
        authorizable_ransackable_attributes
      end

      def nombre_plural
        model_name.human(count: 2)
      end

      def nombre_singular
        model_name.human(count: 1)
      end

      def human_attribute_name(attribute, options = {})
        # Remove suffixes
        if attribute.to_s.ends_with?('_text')
          # Si es un enumerized
          super(attribute[0..-6], options)
        elsif attribute.to_s.ends_with?('_f')
          # Si es un decorated method
          super(attribute[0..-3], options)
        else
          super
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

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