Sha256: ced1f36a19580b84ad36e974d1dc20f87da5a20677f7542f31b11b6343cdfb65
Contents?: true
Size: 1.41 KB
Versions: 2
Compression:
Stored size: 1.41 KB
Contents
module Blueprints # Class for actual blueprints. Allows building itself by executing block passed against current context. class Plan < Buildable # Initializes blueprint by name and block def initialize(name, &block) super(name) @block = block end # Builds plan and adds it to executed plan hash. Setups instance variable with same name as plan if it is not defined yet. def build_self(build_once = true) if build_once and Namespace.root.executed_plans.include?(path) Blueprints.warn("Building with options, but blueprint was already built", @name) if Namespace.root.context.options.present? else surface_errors do if @block @result = Namespace.root.context.instance_eval(&@block) Namespace.root.add_variable(path, @result) end end end Namespace.root.executed_plans << path @result end # Changes blueprint block to build another blueprint by passing additional options to it. Usually used to dry up # blueprints that are often built with some options. def extends(parent, options) attributes(options) @block = Proc.new { build parent => attributes } end private def surface_errors yield rescue StandardError => error puts "\n=> There was an error building scenario '#{@name}'", error.inspect, '', error.backtrace raise error end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
blueprints-0.6.3 | lib/blueprints/plan.rb |
blueprints-0.6.2 | lib/blueprints/plan.rb |