Skip to content

Deduplicate column argument parsing between extractors - #174

Open
eitoball wants to merge 1 commit into
masterfrom
refactor/162-dedupe-extractor-column-parsing
Open

Deduplicate column argument parsing between extractors#174
eitoball wants to merge 1 commit into
masterfrom
refactor/162-dedupe-extractor-column-parsing

Conversation

@eitoball

Copy link
Copy Markdown
Contributor

What

Move the shared column-argument branching logic out of DataExtractor#method_missing and HeaderExtractor#method_missing and into a single implementation on Comma::Extractor.

Why

Both extractors implemented nearly identical branching over argument shapes (none / String / Symbol / Hash), differing only in how each column is resolved (extract a value vs. build a header label). This duplication meant bug fixes and new column types required parallel changes in two places.

Changes

  • lib/comma/extractor.rb: method_missing now owns the argument-shape branching (blank / Hash / Symbol / String) and delegates per-column resolution to an extract_column hook, using column_kind for error messages.
  • lib/comma/data_extractor.rb: removed the duplicated method_missing; now only implements extract_column (resolves a value via ExtractValueFromInstance/ExtractValueFromAssociationOfInstance) and column_kind.
  • lib/comma/header_extractor.rb: removed the duplicated method_missing; now only implements extract_column (resolves a label via value_humanizer) and column_kind.
  • .rubocop_todo.yml: updated Style/MissingRespondToMissing exclusions to reflect method_missing moving to extractor.rb (still excluded on data_extractor.rb for its unrelated null_association helper).

No change to the public DSL. All existing specs in data_extractor_spec.rb, header_extractor_spec.rb, and comma_spec.rb pass unchanged.

Fixes #162

Copilot AI lite review requested due to automatic review settings August 29, 2026 08:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors Comma’s CSV DSL execution by centralizing the column-argument shape parsing ((none), String, Symbol, Hash) into Comma::Extractor#method_missing, while leaving per-column resolution (data vs. header) to subclass hooks. This reduces duplicated branching logic between the data and header extractors without changing the public DSL.

Changes:

  • Moved argument-shape branching for column definitions into lib/comma/extractor.rb and delegated resolution via an extract_column hook.
  • Simplified DataExtractor and HeaderExtractor to implement extract_column + column_kind (and removed their duplicated method_missing).
  • Updated .rubocop_todo.yml exclusions to reflect method_missing relocating to Extractor.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
lib/comma/extractor.rb Centralizes column argument parsing in method_missing and delegates resolution via extract_column.
lib/comma/data_extractor.rb Removes duplicated method_missing; adds extract_column implementation for value extraction.
lib/comma/header_extractor.rb Removes duplicated method_missing; adds extract_column implementation for header humanization.
.rubocop_todo.yml Updates Style/MissingRespondToMissing excludes to match the new method_missing location.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/comma/extractor.rb
DataExtractor#method_missing and HeaderExtractor#method_missing
implemented identical branching over argument shapes (none/String/
Symbol/Hash). Move that branching into Extractor#method_missing and
have each subclass supply only an extract_column hook (value vs.
label resolution) and a column_kind label for error messages.

Fixes #162
@eitoball
eitoball force-pushed the refactor/162-dedupe-extractor-column-parsing branch from e9c0c75 to 22603ed Compare August 29, 2026 10:31
Copilot AI review requested due to automatic review settings August 29, 2026 10:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

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.

Deduplicate column argument parsing between extractors

2 participants