Skip to content

Conversation

@seanpdoyle
Copy link
Contributor

@seanpdoyle seanpdoyle commented Oct 25, 2025

When the Singleton module was originally introduced in #4, there was a suggestion about the implementation for .find that used the :one modifier option with the :from keyword argument.

class Account < ActiveResource::Base
  def self.find_singleton
    find :one, from: '/account.xml'
  end
end

This commit modifies the Singleton.find method by inlining the private find_singleton method. By doing so, the implementation can invoke super, and rely on the built-in instantiate_record call provided by Base.

This reduces the amount of duplication involved in transforming a response payload into a resource instance.

Since the Singleton.find_singleton method was private, this commit removes the test suite coverage that exercised the method through private message sending.

@seanpdoyle seanpdoyle force-pushed the singleton-inline-find-singleton branch from 7254e25 to 55248a1 Compare October 25, 2025 12:32
@seanpdoyle seanpdoyle changed the title Singleton: Inline find_singleton back into find Singletons: Inline find_singleton back into find Oct 25, 2025
When the Singleton module was originally introduced in [rails#4][], there was
a suggestion about the implementation for `.find` that used the `:one`
modifier option with the `:from` keyword argument.

```ruby
class Account < ActiveResource::Base
  def self.find_singleton
    find :one, from: '/account.xml'
  end
end
```

This commit modifies the `Singleton.find` method by inlining the private
`find_singleton` method. By doing so, the implementation can invoke
`super`, and rely on the built-in `instantiate_record` call provided by
`Base`.

This reduces the amount of duplication involved in transforming a
response payload into a resource instance.

[rails#4]: rails#4
[rails#4]: rails#4 (comment)
@seanpdoyle seanpdoyle force-pushed the singleton-inline-find-singleton branch from 55248a1 to 7139ba3 Compare October 26, 2025 13:24
@rafaelfranca rafaelfranca merged commit ea22c4a into rails:main Oct 27, 2025
19 checks passed
@seanpdoyle seanpdoyle deleted the singleton-inline-find-singleton branch October 27, 2025 21:18
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.

2 participants