Class: Trailblazer::DSL::Build
- Inherits:
-
Object
- Object
- Trailblazer::DSL::Build
- Defined in:
- lib/trailblazer/dsl.rb
Overview
Boring DSL code that allows to set a skill class, or define it ad-hoc using a block. passing a constant always wipes out the existing class.
Used in Contract, Representer, Callback, ..
Instance Method Summary collapse
-
#call(options, name = nil, constant = nil, dsl_block, &block) ⇒ Object
Currently, adds .class only to classes.
Instance Method Details
#call(options, name = nil, constant = nil, dsl_block, &block) ⇒ Object
Currently, adds .class only to classes. this could break builder instances?
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/trailblazer/dsl.rb', line 14 def call(, name=nil, constant=nil, dsl_block, &block) # contract MyForm if name.is_a?(Class) constant = name name = :default end is_instance = !(constant.kind_of?(Class) || dsl_block) # i don't like this magic too much, but since it's the only DSL method in TRB, it should be ok. # DISCUSS: options[:is_instance] path = path_name([:prefix], name, is_instance ? nil : "class") # "contract.default.class" if is_instance skill = constant else extended = [:container][path] # Operation["contract.default.class"] extended = yield extended if extended && block_given? # only extend an existing skill class when NO constant was passed. constant = (extended || [:class]) if constant.nil?# && block_given? skill = Class.new(constant) skill.class_eval(&dsl_block) if dsl_block end [path, skill] end |