Module: Trailblazer::Operation::Contract::Validate
- Defined in:
- lib/trailblazer/operation/validate.rb
Class Method Summary collapse
-
.Call(name: "default", representer: false, params_path: nil) ⇒ Object
Macro: Validates contract ‘:name`.
-
.Extract(key: nil, params_path: nil) ⇒ Object
Macro: extract the contract’s input from params by reading ‘:key`.
- .validate!(options, name: nil, representer: false, from: "document", params_path: nil) ⇒ Object
Class Method Details
.Call(name: "default", representer: false, params_path: nil) ⇒ Object
Macro: Validates contract ‘:name`.
38 39 40 41 42 43 44 45 46 |
# File 'lib/trailblazer/operation/validate.rb', line 38 def self.Call(name:"default", representer:false, params_path:nil) step = ->(input, ) { validate!(, name: name, representer: ["representer.#{name}.class"], params_path: params_path) } step = Pipetree::Step.new( step, "representer.#{name}.class" => representer ) [ step, name: "contract.#{name}.call" ] end |
.Extract(key: nil, params_path: nil) ⇒ Object
Macro: extract the contract’s input from params by reading ‘:key`.
28 29 30 31 32 33 34 35 |
# File 'lib/trailblazer/operation/validate.rb', line 28 def self.Extract(key:nil, params_path:nil) # TODO: introduce nested pipes and pass composed input instead. step = ->(input, ) do [params_path] = key ? ["params"][key] : ["params"] end [ step, name: params_path ] end |
.validate!(options, name: nil, representer: false, from: "document", params_path: nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/trailblazer/operation/validate.rb', line 48 def self.validate!(, name:nil, representer:false, from: "document", params_path:nil) path = "contract.#{name}" contract = [path] # this is for 1.1-style compatibility and should be removed once we have Deserializer in place: ["result.#{path}"] = result = if representer # use "document" as the body and let the representer deserialize to the contract. # this will be simplified once we have Deserializer. # translates to contract.("{document: bla}") { MyRepresenter.new(contract).from_json .. } contract.([from]) { |document| representer.new(contract).parse(document) } else # let Reform handle the deserialization. contract.([params_path]) end result.success? end |