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.36.2 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.17.2 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.17.4 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.17.3 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.17.5 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.18.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.17.6 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.19.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.20.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.20.1 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.21.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.21.2 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.21.1 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.21.3 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.22.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.22.1 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.23.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.23.1 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.24.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb
backlog-0.25.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb