Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Singletons: Default collection_name to singleton_name #418

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

seanpdoyle
Copy link

When declaring a resource as a "singleton" (through including the ActiveResource::Singleton module), ensure that subsequent calls to class-level custom methods (through the get, post, put, patch, and delete class and instance methods) use the singleton name by default.

Inventory.get(:report, product_id: 1)   # => GET /products/1/inventory/report.json
Inventory.delete(:reset, product_id: 1) # => DELETE /products/1/inventory/reset.json

Similarly, instance-level custom methods (through the same get, post, put, patch, and delete style methods) use the singleton name and omit the resource ID from the path.

inventory = Inventory.find(params: { product_id: 1 }) # => GET /products/1/inventory.json

inventory.get(:report)    # => GET /products/1/inventory/report.json
inventory.delete(:reset)  # => DELETE /products/1/inventory/reset.json

When a collection_name is explicitly configured, use that value instead of the singleton_name default.

When declaring a resource as a "singleton" (through including the
`ActiveResource::Singleton` module), ensure that subsequent calls to
class-level custom methods (through the `get`, `post`, `put`, `patch`,
and `delete` class and instance methods) use the singleton name by
default.

```ruby
Inventory.get(:report, product_id: 1)   # => GET /products/1/inventory/report.json
Inventory.delete(:reset, product_id: 1) # => DELETE /products/1/inventory/reset.json
```

Similarly, instance-level custom methods (through the same `get`,
`post`, `put`, `patch`, and `delete` style methods) use the singleton
name **and** omit the resource ID from the path.

```ruby
inventory = Inventory.find(params: { product_id: 1 }) # => GET /products/1/inventory.json

inventory.get(:report)    # => GET /products/1/inventory/report.json
inventory.delete(:reset)  # => DELETE /products/1/inventory/reset.json
```

When a `collection_name` is explicitly configured, use that value
instead of the `singleton_name` default.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant