Module: ActiveRecord::Schemas::Base

Included in:
Base
Defined in:
lib/active_record/schemas/base.rb

Instance Method Summary collapse

Instance Method Details

#reset_schema_nameObject

calculates the schema name based on the class’s module



22
23
24
25
26
27
28
29
30
31
# File 'lib/active_record/schemas/base.rb', line 22

def reset_schema_name
  ar_descendant = class_of_active_record_descendant(self)
  if ar_descendant == self
    name = self.name.split('::').first.downcase
    set_schema_name name
    name
  else
    ar_descendant.schema_name
  end
end

#reset_table_name_with_schemaObject

sets the table name with the schema



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/active_record/schemas/base.rb', line 40

def reset_table_name_with_schema
  ar_descendant = class_of_active_record_descendant(self)
  if self == ar_descendant
    name = reset_table_name
    if use_schema_names? && schema_name
      name = "#{"#{schema_name}." if schema_name}#{name}"
      set_table_name name
    end
    name
  else
    name = ar_descendant.table_name
    set_table_name name
    name
  end
end

#schema_nameObject

returns the schema name, either based on the module (via reset_schema_name) of an explicitly set value defined by the class



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

def schema_name
  reset_schema_name
end

#schema_name=(value = nil, &block) ⇒ Object Also known as: set_schema_name

overrides the default schema based on the module



34
35
36
# File 'lib/active_record/schemas/base.rb', line 34

def schema_name=(value = nil, &block)
  define_attr_method :schema_name, value, &block
end

#use_schema_names=(value) ⇒ Object Also known as: set_use_schema_names

sets if schema names should be used.



11
12
13
# File 'lib/active_record/schemas/base.rb', line 11

def use_schema_names=(value)
  write_inheritable_attribute(:use_schema_names, value)
end

#use_schema_names?Boolean

returns true if schema names should be used. Default is false

Returns:

  • (Boolean)


6
7
8
# File 'lib/active_record/schemas/base.rb', line 6

def use_schema_names?
  read_inheritable_attribute(:use_schema_names)
end