Class: Clowne::Planner
- Inherits:
-
Object
- Object
- Clowne::Planner
- Defined in:
- lib/clowne/planner.rb
Overview
:nodoc: all
Class Method Summary collapse
-
.compile(adapter, cloner, traits: nil) ⇒ Object
Compile plan for cloner with traits.
-
.enhance(plan, block) ⇒ Object
Extend previously compiled plan with an arbitrary block NOTE: It doesn’t modify the plan itself but return a copy.
- .filter_declarations(plan, only) ⇒ Object
Class Method Details
.compile(adapter, cloner, traits: nil) ⇒ Object
Compile plan for cloner with traits
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/clowne/planner.rb', line 9 def compile(adapter, cloner, traits: nil) declarations = cloner.declarations.dup declarations += compile_traits(cloner, traits) unless traits.nil? declarations.each_with_object( Utils::Plan.new(adapter.registry) ) do |declaration, plan| declaration.compile(plan) end end |
.enhance(plan, block) ⇒ Object
Extend previously compiled plan with an arbitrary block NOTE: It doesn’t modify the plan itself but return a copy
23 24 25 26 27 28 29 |
# File 'lib/clowne/planner.rb', line 23 def enhance(plan, block) trait = Clowne::Declarations::Trait.new.tap { |t| t.extend_with(block) } trait.compiled.each_with_object(plan.dup) do |declaration, new_plan| declaration.compile(new_plan) end end |
.filter_declarations(plan, only) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/clowne/planner.rb', line 31 def filter_declarations(plan, only) return plan if only.nil? plan.dup.tap do |new_plan| new_plan.declarations.reject! do |(type, declaration)| !only.key?(type) || !declaration.matches?(only[type]) end end end |