$ show javan/whenever
Whenever is a Ruby gem and CLI tool that compiles a Ruby DSL into cron syntax and manages installation into the system crontab. In production it converts a project's config/schedule.rb into crontab entries: `whenever` prints generated cron, `whenever --update-crontab` inserts or replaces a marked block non-destructively, and `--clear-crontab` removes it. The DSL supports frequencies (`every 3.hours`), `at` times, raw cron strings, custom `job_type` templates, `MAILTO` settings, output redirection, role filtering for Capistrano, per-job descriptions, and chained job sequences. Architecturally it is a small library with two CLI entry points (`bin/whenever`, `bin/wheneverize`) and optional Capistrano v2/v3 integrations. The core flow reads config/schedule.rb and instance_eval's it inside `Whenever::JobList` (preceded by `lib/whenever/setup.rb` defaults), builds `Whenever::Job` objects, then renders cron lines through `Whenever::Output::Cron`. `Whenever::CommandLine` handles merging with the existing crontab by matching generated `# Begin Whenever...` / `# End Whenever...` blocks. The only hard runtime dependency is `chronic`; ActiveSupport support is optional and tested through an Appraisal matrix. The codebase is compact, readable, and unusually well tested: Minitest/Mocha tests cover unit behavior and functional output across Ruby 2.4-4.0 and ActiveSupport 5.0-8.1. It is a good reference for building cron-generating DSLs or shell-command template engines. Minor rough edges exist—`Numeric` is monkeypatched globally to provide `1.day` style helpers, and a couple of internal APIs have string/symbol option inconsistencies—but these do not undermine its usefulness.
The LLM identified 4 files worth highlighting for reuse:
Converts high-level schedules (frequencies in seconds, :day/:hour symbols, day names, at times, raw cron strings, and Ruby Range objects) into standard 5-field cron expressions. The non-obvious craft is in comma_separated_timing, which computes sparse cron field lists for frequencies, and in a strict regex that accepts raw cron (including month/day names) while rejecting invalid strings. Could be extracted into a standalone schedule-to-cron compiler with a small seconds helper.
Renders job templates by substituting :placeholders with values, applying quote-aware escaping for single or double quoted contexts, shell-escaping paths, and escaping percent signs for cron. Also supports wrapping the rendered command in a global job_template (e.g. `bash -l -c ':job'`). The pattern of context-sensitive interpolation is reusable in any shell-command generator.
Maps flexible output configuration—string log paths, hashes with :standard/:error keys, nil, or a Proc—into correct shell redirection fragments (`>>`, `2>>`, `/dev/null` variants). It is fully self-contained and demonstrates a clean declarative-to-shell translation useful for any tool that builds shell commands.
Implements non-destructive crontab updates: reads the existing crontab, locates a block delimited by generated `# Begin Whenever...` / `# End Whenever...` comments, replaces only that block, preserves unrelated entries, keeps backslashes during gsub, and falls back to appending when no block exists. This is a robust, reusable pattern for managing generated sections inside user-edited config files.