Class: Dbee::Base

Inherits:
Object
  • Object
show all
Extended by:
Dsl::Methods, Dsl::Reflectable
Defined in:
lib/dbee/base.rb

Overview

Instead of using the configuration-first approach, you could use this super class for Model declaration.

Constant Summary collapse

BASE_CLASS_CONSTANT =
Dbee::Base

Class Method Summary collapse

Methods included from Dsl::Reflectable

reversed_subclasses, subclasses

Methods included from Dsl::Methods

association, associations_by_name, child, parent, partitioner, partitioners, table, table_name, table_name?

Class Method Details

.inflected_class_nameObject



47
48
49
# File 'lib/dbee/base.rb', line 47

def inflected_class_name
  inflector.underscore(inflector.demodulize(name))
end

.inherited_associationsObject



35
36
37
38
39
# File 'lib/dbee/base.rb', line 35

def inherited_associations
  reversed_subclasses(BASE_CLASS_CONSTANT).each_with_object({}) do |subclass, memo|
    memo.merge!(subclass.associations_by_name)
  end.values
end

.inherited_partitionersObject



41
42
43
44
45
# File 'lib/dbee/base.rb', line 41

def inherited_partitioners
  reversed_subclasses(BASE_CLASS_CONSTANT).inject([]) do |memo, subclass|
    memo + subclass.partitioners
  end
end

.inherited_table_nameObject



30
31
32
33
# File 'lib/dbee/base.rb', line 30

def inherited_table_name
  subclasses(BASE_CLASS_CONSTANT).find(&:table_name?)&.table_name ||
    inflected_table_name(reversed_subclasses(BASE_CLASS_CONSTANT).first.name)
end

.to_schema(key_chain) ⇒ Object

Returns the smallest needed Dbee::Schema for the provided key_chain.



26
27
28
# File 'lib/dbee/base.rb', line 26

def to_schema(key_chain)
  DslSchemaBuilder.new(self, key_chain).to_schema
end