Module: Trailblazer::Operation::Contract
- Defined in:
- lib/trailblazer/operation/persist.rb,
lib/trailblazer/operation/contract.rb,
lib/trailblazer/operation/validate.rb
Defined Under Namespace
Modules: Build, DSL Classes: Validate
Class Method Summary collapse
- .Build(name: "default", constant: nil, builder: nil) ⇒ Object
- .Persist(method: :save, name: "default") ⇒ Object
-
.Validate(skip_extract: false, name: "default", representer: false, key: nil, constant: nil) ⇒ Object
result.contract = .. result.contract.errors = .. Deviate to left track if optional key is not found in params.
Class Method Details
.Build(name: "default", constant: nil, builder: nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/trailblazer/operation/contract.rb', line 4 def self.Build(name: "default", constant: nil, builder: nil) task = lambda do |(, ), **| result = Build.(, , name: name, constant: constant, builder: builder) return Activity::TaskBuilder.binary_signal_for(result, Activity::Right, Activity::Left), [, ] end {task: task, id: "contract.build"} end |
.Persist(method: :save, name: "default") ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/trailblazer/operation/persist.rb', line 4 def self.Persist(method: :save, name: "default") path = :"contract.#{name}" step = ->(, **) { [path].send(method) } task = Activity::TaskBuilder::Binary(step) {task: task, id: "persist.save"} end |
.Validate(skip_extract: false, name: "default", representer: false, key: nil, constant: nil) ⇒ Object
result.contract = .. result.contract.errors = .. Deviate to left track if optional key is not found in params. Deviate to left if validation result falsey.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/trailblazer/operation/validate.rb', line 8 def self.Validate(skip_extract: false, name: "default", representer: false, key: nil, constant: nil) # DISCUSS: should we introduce something like Validate::Deserializer? params_path = :"contract.#{name}.params" # extract_params! save extracted params here. extract = Validate::Extract.new(key: key, params_path: params_path).freeze validate = Validate.new(name: name, representer: representer, params_path: params_path, constant: constant).freeze # Build a simple Railway {Activity} for the internal flow. activity = Class.new(Activity::Railway(name: "Contract::Validate")) do step extract, id: "#{params_path}_extract", Output(:failure) => End(:extract_failure) unless skip_extract# || representer step validate, id: "contract.#{name}.call" end = activity.Subprocess(activity) = .merge(id: "contract.#{name}.validate") # Deviate End.extract_failure to the standard failure track as a default. This can be changed from the user side. = .merge(activity.Output(:extract_failure) => activity.Track(:failure)) unless skip_extract end |