Skip to content

chore: small consistency and documentation fixes#60

Open
erimicel wants to merge 2 commits intotypesense:masterfrom
OLIOEX:small-fixes
Open

chore: small consistency and documentation fixes#60
erimicel wants to merge 2 commits intotypesense:masterfrom
OLIOEX:small-fixes

Conversation

@erimicel
Copy link
Copy Markdown
Contributor

@erimicel erimicel commented Apr 27, 2026

A handful of unrelated small fixes that don't really warrant individual PRs.

AnalyticsRules#[] and CurationSets#[] now memoize

Every other resource collection in the gem caches its proxy on first [] access — Collections, Documents, Aliases, Keys, Presets, Synonyms, SynonymSets, NlSearchModels, StemmingDictionaries, Overrides, CurationSetItems, AnalyticsRulesV1. AnalyticsRules and CurationSets were the only two that built a fresh wrapper on every call.

client.curation_sets['x'].equal?(client.curation_sets['x'])
# before: false
# after:  true

This is purely a consistency fix — there was no shared mutable state on the proxies, so the previous behaviour wasn't a bug, just surprising.

Drop unreachable || 3 fallback in Configuration#num_retries

@num_retries = options[:num_retries] || (@nodes.length + (@nearest_node.nil? ? 0 : 1)) || 3

The LHS is always a positive integer — validate! raises before we get here if @nodes is empty — so || 3 can never fire. Just deletes the dead tail.

Drop node.send(:[], attr) in node_missing_parameters?

%i[protocol host port].any? { |attr| node.send(:[], attr).nil? }
# →
%i[protocol host port].any? { |attr| node[attr].nil? }

Same behaviour, less indirection.

README: document Typesense::Error#data

Typesense::Error exposes a .data reader that holds the underlying Faraday response, but the README didn't mention it. Adds a short error-handling section showing how to pull the status / body off a raised exception, plus the list of status-code-to-class mappings.

Tests

  • bundle exec rspec spec/typesense/configuration_spec.rb spec/typesense/analytics_rules_spec.rb spec/typesense/curation_sets_spec.rb — all green.
  • bundle exec rubocop on the touched files — no offences.

PR Checklist

- AnalyticsRules and CurationSets now memoize their resource proxies in
  `[]`, matching the pattern every other collection class already uses
  (Collections, Documents, Aliases, Keys, Presets, SynonymSets, etc).
  Calls like `client.curation_sets['x']` now return the same instance
  across calls, which is the documented contract elsewhere.
- Remove an unreachable `|| 3` fallback from `Configuration#num_retries`:
  the LHS is always an integer because `validate!` rejects empty `nodes`.
- Replace `node.send(:[], attr)` with `node[attr]` in
  `Configuration#node_missing_parameters?` — same behaviour, less
  indirection.
- Document `Typesense::Error#data` in the README so callers know how to
  read the HTTP status and body from a raised exception.
@tharropoulos
Copy link
Copy Markdown
Contributor

Looks like some tests are failing

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