Skip to content

refactor(zendesk): template-method init for collections#313

Open
christophebrun-forest wants to merge 1 commit into
mainfrom
refactor/zendesk-collection-template-method
Open

refactor(zendesk): template-method init for collections#313
christophebrun-forest wants to merge 1 commit into
mainfrom
refactor/zendesk-collection-template-method

Conversation

@christophebrun-forest
Copy link
Copy Markdown
Member

@christophebrun-forest christophebrun-forest commented May 22, 2026

Summary

  • Hoist the Zendesk collection setup (define_schema → define_relations → add_custom_fields → enable_search → enable_count) into BaseCollection#initialize. The ordering becomes an invariant of the base class instead of a discipline the subclass author has to remember — a follow-up to fix(zendesk): warn on custom-field name collisions #312, where the custom-field collision check silently depended on schema+relations being added first.
  • Subclass initializers shrink to one line: super(datasource, 'ZendeskX', custom_fields: custom_fields).
  • define_schema / define_relations now raise NotImplementedError with the subclass name when omitted — explicit contract instead of NoMethodError.
  • searchable: / countable: kwargs (default true) let a future subclass opt out via super(..., searchable: false) without re-defining the whole initializer.
  • native_driver is propagated to the toolkit Collection constructor.

Test plan

  • bundle exec rspec — 242 examples, 0 failures (4 new specs in base_collection_spec.rb lock the NotImplementedError contract and the search/count opt-out).
  • bundle exec rubocop lib/ spec/ — clean.
  • .rubocop.yml: Metrics/ParameterLists and Metrics/ClassLength exclude this file (same pattern as forest_admin_datasource_snowflake/collection.rb).

🤖 Generated with Claude Code

Note

Refactor Zendesk collection init to use template-method pattern in BaseCollection

  • Moves the initialization lifecycle (schema definition, relations, custom fields, search/count flags) into BaseCollection#initialize, replacing repeated boilerplate in Organization, Ticket, and User.
  • Adds abstract define_schema and define_relations hook methods that raise NotImplementedError if not implemented by a subclass.
  • searchable and countable default to true and can be opted out via keyword arguments.
  • attr_reader :custom_fields is now provided by BaseCollection and removed from each subclass.

Macroscope summarized f17ae58.

Move define_schema/define_relations/add_custom_fields/enable_search/
enable_count orchestration into BaseCollection#initialize. Subclasses
shrink to one super call and can opt out of search/count via the
searchable: / countable: kwargs. define_schema and define_relations now
raise NotImplementedError when a subclass omits them; native_driver is
propagated through.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@qltysh
Copy link
Copy Markdown

qltysh Bot commented May 22, 2026

1 new issue

Tool Category Rule Count
qlty Structure Function with many parameters (count = 6): initialize 1

# are always evaluated against the final native schema. A subclass can
# opt out of search/count by passing `searchable: false` / `countable:
# false` through `super`.
def initialize(datasource, name, custom_fields: [], searchable: true, countable: true, native_driver: nil)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function with many parameters (count = 6): initialize [qlty:function-parameters]

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