Each ledger defines operations that can be performed on specific resources (e.g.
Payment::Operations::Create). The operation defines two key things:
Contractclass which is used to validate the resource using the
performinstance method, which handles the actual API requests and response/error handling.
Contracts are dry-validation schemas, which determine if an operation can be performed. You can create custom schemas and pass them to operations. Assuming you have an
operation_class variable and
foo is an attribute of a
custom_resource (see above) that is required to be a string, you can implement it with the following:
class CustomContract < LedgerSync::Ledgers::Contract params do required(:foo).filled(:string) end end # A valid case custom_resource = CustomResource.new(foo: 'asdf') op = operation_class.new( client: client, resource: resource, validation_contract: CustomContract ) op.valid? # => true # An invalid case custom_resource = CustomResource.new(foo: nil) operation_class.new( client: client, resource: resource, validation_contract: CustomContract ) op.valid? # => false