Module: RedhillonrailsCore::ActiveRecord::Base::ClassMethods

Defined in:
lib/redhillonrails_core/active_record/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/redhillonrails_core/active_record/base.rb', line 9

def self.extended(base)
  class << base
    alias_method_chain :columns, :redhillonrails_core
    alias_method_chain :abstract_class?, :redhillonrails_core
    alias_method_chain :reset_column_information, :redhillonrails_core
  end
end

Instance Method Details

#abstract_class_with_redhillonrails_core?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/redhillonrails_core/active_record/base.rb', line 21

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

#base_class?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/redhillonrails_core/active_record/base.rb', line 17

def base_class?
  self == base_class
end

#columns_with_redhillonrails_coreObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/redhillonrails_core/active_record/base.rb', line 25

def columns_with_redhillonrails_core
  unless @columns
    columns_without_redhillonrails_core
    cols = columns_hash
    indexes.each do |index|
      next if index.columns.blank?
      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

#foreign_keysObject



53
54
55
# File 'lib/redhillonrails_core/active_record/base.rb', line 53

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

#indexesObject



49
50
51
# File 'lib/redhillonrails_core/active_record/base.rb', line 49

def indexes
  @indexes ||= connection.indexes(table_name, "#{name} Indexes")
end

#pluralized_table_name(table_name) ⇒ Object



45
46
47
# File 'lib/redhillonrails_core/active_record/base.rb', line 45

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

#reset_column_information_with_redhillonrails_coreObject



40
41
42
43
# File 'lib/redhillonrails_core/active_record/base.rb', line 40

def reset_column_information_with_redhillonrails_core
  reset_column_information_without_redhillonrails_core
  @indexes = @foreign_keys = nil
end

#reverse_foreign_keysObject



57
58
59
# File 'lib/redhillonrails_core/active_record/base.rb', line 57

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