Module: Trailblazer::Operation::Contract::DSL

Defined in:
lib/trailblazer/operation/contract.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(extender) ⇒ Object



40
41
42
43
# File 'lib/trailblazer/operation/contract.rb', line 40

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.


50
51
52
53
54
55
56
57
58
59
# File 'lib/trailblazer/operation/contract.rb', line 50

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