diff --git a/AGENTS.md b/AGENTS.md index aa8e64d..1acca8b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -74,6 +74,31 @@ When adding a new wrapper, follow this structure: body(result: Float) { |res| res.result } ``` + +## Organizing wrappers with `draw` + +Use `draw` to keep large wrappers readable by splitting DSL declarations into +smaller files. + +```ruby +# clients/payments/client.rb +class Payments::Client < Purple::Client + domain 'https://api.example.com' + + draw 'paths/invoices' + draw 'paths/refunds.rb' +end + +# clients/payments/paths/invoices.rb +path :invoices do + response :ok do + body :default + end + + root_method :invoices +end +``` + ## DO / DON'T (for LLMs) **DO** diff --git a/README.md b/README.md index 01318f1..9a19a95 100644 --- a/README.md +++ b/README.md @@ -351,6 +351,36 @@ end MessagesClient.send_message ``` +### Splitting large wrappers with `draw` + +If a wrapper gets too long, you can move parts of the DSL into separate files +and load them with `draw`. + +`draw` resolves paths relative to the file where it is called. If you omit the +extension, `.rb` is added automatically. + +```ruby +# clients/payments/client.rb +class Payments::Client < Purple::Client + domain 'https://api.example.com' + + draw 'paths/invoices' + draw 'paths/refunds.rb' +end + +# clients/payments/paths/invoices.rb +path :invoices do + response :ok do + body :default + end + root_method :invoices +end +``` + +Use `draw` only to organize DSL definitions (`path`, `params`, `response`, +`root_method`) into smaller files. Keep wrapper behavior declarative and avoid +adding non-DSL business logic in drawn files. + ## How to build a wrapper client (5 steps) 1. **Define a `domain`** for the API host.