Skip to content

Move demo implementation to examples/demo.rb#14

Closed
swhitt wants to merge 3 commits intodevelopfrom
refactor/move-demo-to-examples
Closed

Move demo implementation to examples/demo.rb#14
swhitt wants to merge 3 commits intodevelopfrom
refactor/move-demo-to-examples

Conversation

@swhitt
Copy link
Copy Markdown
Owner

@swhitt swhitt commented Jan 23, 2026

Extract demo code from lib/clack.rb to examples/demo.rb, add proxy method.

Extract demo code from lib/clack.rb to examples/demo.rb, add proxy method.
@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Jan 23, 2026

Greptile Overview

Greptile Summary

Extracted the demo implementation from lib/clack.rb into a standalone examples/demo.rb file, replacing it with a proxy method that loads and executes the demo.

Major changes:

  • Moved 170+ lines of demo code from lib/clack.rb to examples/demo.rb
  • Added proxy demo method in lib/clack.rb that loads the example file via File.expand_path("../examples/demo.rb", __dir__) and calls run_demo
  • Updated clack.gemspec to include examples/**/* in distributed gem files
  • Excluded examples directory from Reek code smell analysis in .reek.yml and lefthook.yml

The refactor improves code organization by separating demo/example code from the library implementation while maintaining backward compatibility with the existing Clack.demo API.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are a straightforward refactoring that extracts demo code into a separate file. The implementation correctly preserves the public API through a proxy method, includes the examples directory in the gem distribution, and appropriately excludes it from code quality checks. No logic changes were made to the demo itself beyond moving it.
  • No files require special attention

Important Files Changed

Filename Overview
clack.gemspec Added examples directory to gem files for distribution
lib/clack.rb Replaced inline demo implementation with proxy method that loads examples/demo.rb
examples/demo.rb Extracted demo code from lib/clack.rb into standalone, executable example file

Sequence Diagram

sequenceDiagram
    participant User
    participant ClackDemo as clack-demo (exe)
    participant ClackModule as Clack module (lib/clack.rb)
    participant DemoFile as examples/demo.rb
    participant Prompts as Clack Prompts

    User->>ClackDemo: Execute clack-demo
    ClackDemo->>ClackModule: Clack.demo()
    ClackModule->>ClackModule: File.expand_path("../examples/demo.rb", __dir__)
    ClackModule->>DemoFile: load demo_path
    DemoFile->>DemoFile: Define run_demo function
    ClackModule->>DemoFile: run_demo()
    DemoFile->>Prompts: Clack.intro("clack-demo")
    DemoFile->>Prompts: Clack.group(on_cancel: ...) { ... }
    Prompts-->>User: Display prompts (name, directory, template, etc.)
    User-->>Prompts: Provide responses
    Prompts-->>DemoFile: Return result hash
    DemoFile->>DemoFile: Check if Clack.cancel?(result)
    DemoFile->>Prompts: Clack.autocomplete(...)
    DemoFile->>Prompts: Clack.select_key(...)
    DemoFile->>Prompts: Clack.path(...)
    DemoFile->>Prompts: Clack.group_multiselect(...)
    DemoFile->>Prompts: Clack.progress(...)
    DemoFile->>Prompts: Clack.tasks(...)
    DemoFile->>Prompts: Clack.spinner()
    DemoFile->>Prompts: Clack.log.step(...)
    DemoFile->>Prompts: Clack.note(...)
    DemoFile->>Prompts: Clack.outro("Happy coding!")
    DemoFile-->>ClackModule: Demo complete
    ClackModule-->>ClackDemo: Return
    ClackDemo-->>User: Exit
Loading

Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@claude
Copy link
Copy Markdown

claude bot commented Jan 23, 2026

Code Review

I found one critical issue that needs to be addressed:

Missing examples directory in gem package

The Clack.demo method at lib/clack.rb:431-435 will fail with a LoadError when the gem is installed from RubyGems.

The method tries to load examples/demo.rb:

def demo
  demo_path = File.expand_path("../examples/demo.rb", __dir__)
  load demo_path
  run_demo
end

However, the gemspec at clack.gemspec:26 does not include the examples directory:

spec.files = Dir["lib/**/*", "LICENSE", "README.md", "CHANGELOG.md"]

When users install the gem via gem install clack or Bundler, the examples/ directory will not be present, causing Clack.demo to fail at runtime.

Suggested fix: Update clack.gemspec to include the examples directory:

spec.files = Dir["lib/**/*", "examples/**/*", "LICENSE", "README.md", "CHANGELOG.md"]

Use handle_cancel instead of cancel? to show cancellation messages.
Include examples directory in gem files.
@swhitt
Copy link
Copy Markdown
Owner Author

swhitt commented Jan 23, 2026

@claude @greptileai re-review plz

@claude
Copy link
Copy Markdown

claude bot commented Jan 23, 2026

Claude finished @swhitt's task in 46s —— View job


Re-review Complete ✅

  • Read clack.gemspec to verify examples directory is included
  • Review examples/demo.rb implementation
  • Review lib/clack.rb proxy method
  • Check other configuration changes
  • Provide comprehensive review feedback

Review Summary

Great work addressing the previous critical issue! The gemspec now correctly includes the examples directory at clack.gemspec:26:

spec.files = Dir["lib/**/*", "examples/**/*", "LICENSE", "README.md", "CHANGELOG.md"]

This means Clack.demo will work correctly when the gem is installed from RubyGems. ✅

Inconsistent Cancel Handling

However, there's one inconsistency in the cancel handling within examples/demo.rb:

Line 83 uses handle_cancel(color):

return if Clack.handle_cancel(color)

But line 76 uses cancel?(result):

return if Clack.cancel?(result)

Impact: When using cancel?, no cancellation message is displayed to the user. With handle_cancel, a "Cancelled" message is shown before exiting.

Recommendation: For consistency and better UX, use Clack.handle_cancel() consistently throughout the demo, or use cancel? consistently if you prefer silent cancellation. The current mix is confusing.

Lines affected: examples/demo.rb:76, 83, 94, 101, 134

Other Changes Look Good

  • .reek.yml properly excludes examples directory at .reek.yml:75
  • lefthook.yml properly excludes examples from reek checks at lefthook.yml:10
  • ✅ Proxy method at lib/clack.rb:431-435 correctly uses File.expand_path for path resolution
  • ✅ Demo implementation is clean and showcases all features properly

Verdict

The critical issue has been resolved ✅. The only remaining concern is the minor inconsistency in cancel handling, which affects UX but not functionality. This is optional to fix but recommended for polish.


Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@swhitt swhitt deleted the branch develop January 24, 2026 04:19
@swhitt swhitt closed this Jan 24, 2026
@claude
Copy link
Copy Markdown

claude bot commented Jan 24, 2026


Code review

No issues found. Checked for bugs and CLAUDE.md compliance.


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