Module: InheritanceIntegerType::Extensions::ClassMethods

Defined in:
lib/inheritance_integer_type/extensions.rb

Instance Method Summary collapse

Instance Method Details

#find_sti_class(type_name) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/inheritance_integer_type/extensions.rb', line 10

def find_sti_class(type_name)
  lookup = self._inheritance_mapping[type_name.to_i]
  if lookup
    if ActiveRecord::VERSION::MAJOR < 5
      super(lookup)
    else
      begin
        if store_full_sti_class
          ActiveSupport::Dependencies.constantize(lookup)
        else
          compute_type(lookup)
        end
      rescue NameError
        raise SubclassNotFound,
          "The single-table inheritance mechanism failed to locate the subclass: '#{type_name}'. " +
          "This error is raised because the column '#{inheritance_column}' is reserved for storing the class in case of inheritance. " +
          "Please rename this column if you didn't intend it to be used for storing the inheritance class " +
          "or overwrite #{name}.inheritance_column to use another column for that information."
      end
    end
  else
    super
  end
end

#integer_inheritance=(val) ⇒ Object



6
7
8
# File 'lib/inheritance_integer_type/extensions.rb', line 6

def integer_inheritance=(val)
  self._inheritance_mapping[val] = sti_name_without_integer_types
end

#sti_name_with_integer_typesObject



35
36
37
38
# File 'lib/inheritance_integer_type/extensions.rb', line 35

def sti_name_with_integer_types
  klass = sti_name_without_integer_types
  self._inheritance_mapping.key(klass) || klass
end