Module: Trailblazer::Macro::Contract::DSL

Defined in:
lib/trailblazer/macro/contract/build.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(extender) ⇒ Object



44
45
46
47
# File 'lib/trailblazer/macro/contract/build.rb', line 44

def self.extended(extender)
  extender.extend(ClassDependencies)
  warn "[Trailblazer] Using `contract do...end` is deprecated. Please use a form class and the Builder( constant: <Form> ) option."
end

Instance Method Details

#contract(name = :default, constant = nil, base: Reform::Form, &block) ⇒ Object

This is the class level DSL method.

Op.contract #=> returns contract class
Op.contract do .. end # defines contract
Op.contract CommentForm # copies (and subclasses) external contract.
Op.contract CommentForm do .. end # copies and extends contract.


54
55
56
57
58
59
60
61
62
63
# File 'lib/trailblazer/macro/contract/build.rb', line 54

def contract(name = :default, constant = nil, base: Reform::Form, &block)
  heritage.record(:contract, name, constant, &block)

  path, form_class = Trailblazer::DSL::Build.new.(
    {prefix: :contract, class: base, container: self},
    name, constant, block
  )

  self[path] = form_class
end