module ModelOrchestration::Base::ClassMethods
Public Instance Methods
nested_model(model)
click to toggle source
Class method to declare a nested model. This invokes instantiation of the model when the orchestration model is instantiated. The nested model can be declared by symbol, type or string.
class HoldingClass include ModelOrchestration::Base nested_model :user end
# File lib/model_orchestration/base.rb, line 30 def nested_model(model) model_key = symbolize(model) self._nested_models << model_key end
nested_model_dependency(args = {})
click to toggle source
Class method to declare a dependency from one nested model to another.
class Signup include ModelOrchestration::Base nested_model :company nested_model :employee nested_model_dependency from: :employee, to: :company end
The example obove might be used to orchestrate the signup process of a user
who creates an account representative for his company. In the database
schema, company and employee have a 1:n relation, which is represented by
nested_model_dependency
.
# File lib/model_orchestration/base.rb, line 68 def nested_model_dependency(args = {}) unless args.include?(:from) && args.include?(:to) raise ArgumentError, ":from and :to hash keys must be included." end from = symbolize(args[:from]) tos = args[:to].is_a?(Array) ? args[:to] : [symbolize(args[:to])] tos.each do |to| if dependency_introduces_cycle?(from, to) raise ModelOrchestration::DependencyCycleError, "#{from} is already a dependency of #{to}" else add_dependency(from, to) end end end
nested_models(*models)
click to toggle source
Class method to declare nested models. This invokes instantiation of the models when the orchestration model is instantiated. The nested model can be declared by symbol, type or string.
class HoldingClass include ModelOrchestration::Base nested_models :user, :company end
# File lib/model_orchestration/base.rb, line 46 def nested_models(*models) models.each do |model| nested_model model end end