refactor(zendesk): template-method init for collections#313
Open
christophebrun-forest wants to merge 1 commit into
Open
refactor(zendesk): template-method init for collections#313christophebrun-forest wants to merge 1 commit into
christophebrun-forest wants to merge 1 commit into
Conversation
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>
1 new issue
|
| # 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
define_schema → define_relations → add_custom_fields → enable_search → enable_count) intoBaseCollection#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.super(datasource, 'ZendeskX', custom_fields: custom_fields).define_schema/define_relationsnow raiseNotImplementedErrorwith the subclass name when omitted — explicit contract instead ofNoMethodError.searchable:/countable:kwargs (defaulttrue) let a future subclass opt out viasuper(..., searchable: false)without re-defining the whole initializer.native_driveris propagated to the toolkitCollectionconstructor.Test plan
bundle exec rspec— 242 examples, 0 failures (4 new specs inbase_collection_spec.rblock the NotImplementedError contract and the search/count opt-out).bundle exec rubocop lib/ spec/— clean..rubocop.yml:Metrics/ParameterListsandMetrics/ClassLengthexclude this file (same pattern asforest_admin_datasource_snowflake/collection.rb).🤖 Generated with Claude Code
Note
Refactor Zendesk collection init to use template-method pattern in
BaseCollectionBaseCollection#initialize, replacing repeated boilerplate inOrganization,Ticket, andUser.define_schemaanddefine_relationshook methods that raiseNotImplementedErrorif not implemented by a subclass.searchableandcountabledefault totrueand can be opted out via keyword arguments.attr_reader :custom_fieldsis now provided byBaseCollectionand removed from each subclass.Macroscope summarized f17ae58.