Sha256: fa7d2d38077fbe8ab5bbd9525283d9e8e4f715d605f3783d290c9f9f150f0908
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 KB
Contents
# frozen_string_literal: true require 'clowne/plan' module Clowne class Planner # :nodoc: all class << self # Compile plan for cloner with traits def compile(cloner, traits: nil) declarations = cloner.declarations.dup declarations += compile_traits(cloner, traits) unless traits.nil? declarations.each_with_object(Plan.new(cloner.adapter.registry)) do |declaration, plan| declaration.compile(plan) end end # Extend previously compiled plan with an arbitrary block # NOTE: It doesn't modify the plan itself but return a copy 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 private def compile_traits(cloner, traits) traits.map do |id| trait = cloner.traits[id] raise ConfigurationError, "Trait not found: #{id}" if trait.nil? trait.compiled end.flatten end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
clowne-0.1.0 | lib/clowne/planner.rb |
clowne-0.1.0.beta1 | lib/clowne/planner.rb |