Module: ActiveRecord::ModelSpaces::TableNames

Extended by:
Util
Defined in:
lib/active_record/model_spaces/table_names.rb

Class Method Summary collapse

Methods included from Util

all_model_superclasses, class_for_classname, class_from_classname, is_active_record_model?, model_from_name, name_from_model, require_for_classname

Class Method Details

.base_table_name(model) ⇒ Object



14
15
16
17
18
19
# File 'lib/active_record/model_spaces/table_names.rb', line 14

def base_table_name(model)
  name_from_model(model).
    instance_eval{ ActiveSupport::Inflector.demodulize(self)}.
    instance_eval{ ActiveSupport::Inflector.underscore(self)}.
    instance_eval{ ActiveSupport::Inflector.pluralize(self)}
end

.model_space_table_name(model_space_name, model_space_key, base_table_name) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/active_record/model_spaces/table_names.rb', line 21

def model_space_table_name(model_space_name, model_space_key, base_table_name)
  if (!model_space_name || model_space_name.to_s.empty?) &&
      (model_space_key && !model_space_key.to_s.empty?)
    raise "model_space_key cannot be non-empty if model_space_name is empty"
  end

  [ ("#{model_space_name}__" if model_space_name && !model_space_name.to_s.empty?),
    ("#{model_space_key}__" if model_space_key && !model_space_key.to_s.empty?),
    base_table_name].compact.join
end

.next_version(history_versions, v) ⇒ Object



37
38
39
# File 'lib/active_record/model_spaces/table_names.rb', line 37

def next_version(history_versions, v)
  version(history_versions, (v || 0)+1)
end

.table_name(model_space_name, model_space_key, model, history_versions, v) ⇒ Object



32
33
34
35
# File 'lib/active_record/model_spaces/table_names.rb', line 32

def table_name(model_space_name, model_space_key, model, history_versions, v)
  [model_space_table_name(model_space_name, model_space_key, model),
    ("__#{v}" if v && v>0)].compact.join
end