Method: Dbee::Base.to_model
- Defined in:
- lib/dbee/base.rb
.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 |