Sha256: 1cc12ee00b721179540abcd9f13110a70070cac05c46a69c830b869a929845c2

Contents?: true

Size: 1.36 KB

Versions: 23

Compression:

Stored size: 1.36 KB

Contents

---
title: Operations
weight: 4
layout: guides
---

Each ledger defines operations that can be performed on specific resources (e.g. `Customer::Operations::Update`, `Payment::Operations::Create`).  The operation defines two key things:

- a `Contract` class which is used to validate the resource using the `dry-validation` gem
- a `perform` instance method, which handles the actual API requests and response/error handling.

<div class="note"><strong>Note:</strong>
  Ledgers may support different operations for each resource type.
</div>

## Contracts

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:

```ruby
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

```

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
ledger_sync-3.0.0 documentation/site/guides/architecture/operations.md
ledger_sync-2.6.0 documentation/site/guides/architecture/operations.md
ledger_sync-2.5.0 documentation/site/guides/architecture/operations.md
ledger_sync-2.4.4 documentation/site/guides/architecture/operations.md
ledger_sync-2.3.1 documentation/site/guides/architecture/operations.md
ledger_sync-2.2.3 documentation/site/guides/architecture/operations.md
ledger_sync-2.2.1 documentation/site/guides/architecture/operations.md
ledger_sync-2.2.0 documentation/site/guides/architecture/operations.md
ledger_sync-2.0.2 documentation/site/guides/architecture/operations.md
ledger_sync-2.0.1 documentation/site/guides/architecture/operations.md
ledger_sync-2.0.0 documentation/site/guides/architecture/operations.md
ledger_sync-2.0.0.pre.1 documentation/site/guides/architecture/operations.md
ledger_sync-1.8.1 documentation/site/guides/architecture/operations.md
ledger_sync-1.8.0 documentation/site/guides/architecture/operations.md
ledger_sync-1.7.0 documentation/site/guides/architecture/operations.md
ledger_sync-1.6.0 documentation/site/guides/architecture/operations.md
ledger_sync-1.5.2 documentation/site/guides/architecture/operations.md
ledger_sync-1.5.1 documentation/site/guides/architecture/operations.md
ledger_sync-1.5.0 documentation/site/guides/architecture/operations.md
ledger_sync-1.4.4 documentation/site/guides/architecture/operations.md