Sha256: 46eaf7bf649bb57236e7f488392877cdadd666186792fc3b086595a14edc4e68

Contents?: true

Size: 1.67 KB

Versions: 38

Compression:

Stored size: 1.67 KB

Contents

module RedHillConsulting::Core::ActiveRecord
  module Base
    def self.included(base)
      base.extend(ClassMethods)
    end

    module ClassMethods
      def self.extended(base)
        class << base
          alias_method_chain :columns, :redhillonrails_core unless method_defined?(:columns_without_redhillonrails_core)
          alias_method_chain :abstract_class?, :redhillonrails_core unless method_defined?(:abstract_class_without_redhillonrails_core?)
        end
      end

      def base_class?
        self == base_class
      end

      def abstract_class_with_redhillonrails_core?
        abstract_class_without_redhillonrails_core? || !(name =~ /^Abstract/).nil?
      end

      def columns_with_redhillonrails_core
        unless @columns
          columns_without_redhillonrails_core
          cols = columns_hash
          indexes.each do |index|
            column_name = index.columns.reverse.detect { |name| name !~ /_id$/ } || index.columns.last
            column = cols[column_name]
            column.case_sensitive = index.case_sensitive?
            column.unique_scope = index.columns.reject { |name| name == column_name } if index.unique
          end
        end
        @columns
      end

      def pluralized_table_name(table_name)
        ActiveRecord::Base.pluralize_table_names ? table_name.to_s.pluralize : table_name
      end

      def indexes
        @indexes ||= connection.indexes(table_name)
      end

      def foreign_keys
        @foreign_keys ||= connection.foreign_keys(table_name, "#{name} Foreign Keys")
      end

      def reverse_foreign_keys
        connection.reverse_foreign_keys(table_name, "#{name} Reverse Foreign Keys")
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
backlog-0.26.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.28.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.29.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.30.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.31.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.32.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.31.1 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.33.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.34.1 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.33.1 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.34.2 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.35.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.34 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.35.1 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.35.2 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.35.3 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.35.4 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.35.5 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb