Module: ClosureTree::ActiveRecordSupport

Included in:
Generators::MigrationGenerator, Support
Defined in:
lib/closure_tree/active_record_support.rb

Instance Method Summary collapse

Instance Method Details

#ensure_fixed_table_name(table_name) ⇒ Object


3
4
5
6
7
8
9
# File 'lib/closure_tree/active_record_support.rb', line 3

def ensure_fixed_table_name(table_name)
  [
    ActiveRecord::Base.table_name_prefix,
    remove_prefix_and_suffix(table_name),
    ActiveRecord::Base.table_name_suffix
  ].compact.join
end

#remove_prefix_and_suffix(table_name) ⇒ Object


11
12
13
14
15
16
17
18
# File 'lib/closure_tree/active_record_support.rb', line 11

def remove_prefix_and_suffix(table_name)
  pre, suff = ActiveRecord::Base.table_name_prefix, ActiveRecord::Base.table_name_suffix
  if table_name.start_with?(pre) && table_name.end_with?(suff)
    table_name[pre.size..-(suff.size + 1)]
  else
    table_name
  end
end