Skip to content

Input contracts #22

@rkolesnev-vineti

Description

@rkolesnev-vineti

Works like OutputContract plugin but also checks argument structure. Transformations are applied.

Draft DSL:

class BusinessOperation
  include Flows::Result::Helpers
  include Flows::Plugin::InputContract

  input do
    arg :username, Contract
    arg :realname { either(String, Symbol) } # block works like Contract.make
    rest_args :rest_of_the_names { array(String) }

    kwarg :new_status, OtherContract
    rest_kwargs :rest_of_the_kwargs { hash(Symbol, String) }
  end

  # skip_input_contract

  def call(username, realname,  *rest_of_the_name, new_status:, **rest_of_the_kwargs)
  end
end

Challenges here: it'd be ideal to check the existing method argument structure and raise an error (at least on instance initialization) if the contract defines a different structure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions