Class: Dbee::Base
- Inherits:
-
Object
- Object
- Dbee::Base
- 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
- .inherited_associations ⇒ Object
- .inherited_partitioners ⇒ Object
- .inherited_table_name ⇒ Object
-
.to_model(key_chain, name = nil, constraints = [], path_parts = []) ⇒ Object
This method is cycle-resistant due to the fact that it is a requirement to send in a key_chain.
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
.inherited_associations ⇒ Object
49 50 51 52 53 |
# File 'lib/dbee/base.rb', line 49 def inherited_associations reversed_subclasses(BASE_CLASS_CONSTANT).each_with_object({}) do |subclass, memo| memo.merge!(subclass.associations_by_name) end.values end |
.inherited_partitioners ⇒ Object
55 56 57 58 59 |
# File 'lib/dbee/base.rb', line 55 def inherited_partitioners reversed_subclasses(BASE_CLASS_CONSTANT).inject([]) do |memo, subclass| memo + subclass.partitioners end end |
.inherited_table_name ⇒ Object
44 45 46 47 |
# File 'lib/dbee/base.rb', line 44 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_model(key_chain, name = nil, constraints = [], path_parts = []) ⇒ Object
This method is cycle-resistant due to the fact that it is a requirement to send in a key_chain. That means each model produced using to_model is specific to a set of desired fields. Basically, you cannot derive a Model from a Base subclass without the context of a Query. This is not true for configuration-first Model definitions because, in that case, cycles do not exist since the nature of the configuration is flat.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dbee/base.rb', line 30 def to_model(key_chain, name = nil, constraints = [], path_parts = []) derived_name = name.to_s.empty? ? inflected_class_name(self.name) : name.to_s key = [key_chain, derived_name, constraints, path_parts] to_models[key] ||= Model.make( model_config( key_chain, derived_name, constraints, path_parts + [name] ) ) end |