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



8
9
10
11
12
13
14
# File 'lib/closure_tree/active_record_support.rb', line 8

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

#quote(field) ⇒ Object



4
5
6
# File 'lib/closure_tree/active_record_support.rb', line 4

def quote(field)
  connection.quote(field)
end

#remove_prefix_and_suffix(table_name) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/closure_tree/active_record_support.rb', line 16

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