Module: Railbow::Init

Defined in:
lib/railbow/init.rb

Constant Summary collapse

TEMPLATE =
<<~YAML
  # Railbow configuration
  # https://github.com/amberpixels/railbow
  #
  # Config layers (each overrides the previous):
  #   1. Gem defaults (built-in)
  #   2. Global:  ~/.config/railbow/config.yml
  #   3. Project: .railbow.yml        (commit to git)
  #   4. Local:   .railbow.local.yml  (gitignored, personal overrides)
  #
  # Every key can also be overridden via RBW_* environment variables.

  # Time window for migrations to display (e.g. 30d, 2mo, 1y, all)
  since: "70d"

  # Never show fewer than this many migrations, however old they are.
  # The window above is a soft limit: a database with five migrations shows
  # all five rather than reporting an empty period. 0 disables the floor.
  since_min: 10

  # Sort order: file (by filename/version) or date (by timestamp)
  # sort: "file"

  # Git integration (comma-separated compound value):
  #   author       - add Author column (same as author:all)
  #   author:me    - highlight your own migrations
  #   author:all   - show all authors
  #   diff         - tag migrations by git origin branch
  #   base:<branch> - base branch for diff (default: auto-detected)
  #   mask:auto    - auto-extract ticket id from branch name
  #   mask:<re>    - custom regex to extract branch label, e.g. mask:(WS-[^/]+)/
  git: "author:all,diff,mask:auto"

  # Author display format - preset or custom pattern (FF L, FFF LL, etc.):
  #   initials (J D), short (Jo D), first_name (John), last_name (Doe),
  #   full_name (John Doe), full_name_short (John D.)
  author_format: "short"

  # View mode (comma-separated): calendar, tables
  view: "calendar,tables"

  # Calendar options (comma-separated), all require view: calendar.
  # Leave empty ("") for month separators only, with no week markers.
  #   wticks       - week tick marks on the date column
  #   wdividers    - a separator row per ISO week
  #   counts       - append "· N migrations" to separator rows (per section)
  #   label:<fmt>  - strftime for month separators (default: %b %Y   W%V)
  #   wlabel:<fmt> - strftime for week separators (default: same as label)
  calendar: "wticks"

  # Date format: full, rel, short, or custom(%b %d, %Y)
  # date: "full"

  # Multi-database runs (comma-separated). Leave empty ("") to expand every
  # database into its own section, in database.yml order; a database with
  # nothing in the time window collapses to a one-line summary either way.
  #   focus       - expand only the first database, summarizing the rest.
  #                 A database with migrations pending is always expanded
  #   only:<name> - render only this database (repeatable)
  #   skip:<name> - drop this database (repeatable)
  #   full        - draw every database in full, overriding focus
  #   inline      - one merged table ordered by version, with a Db column
  db: "focus"

  # Compact mode (comma-separated):
  #   oneline       - one line per migration
  #   dense         - reduce padding
  #   noheader      - hide table headers
  #   maxw:<N>      - max column width
  #   hide:<col>    - hide a column (repeatable)
  # compact: ""

  # Rename column headers and cell values in table output
  aliases:
    columns:
      Status: Live
    values:
      Status:
        up: "↑↑"
        down: "↓↓"
      # Verb:
      #   GET: G
      #   POST: P
YAML

Class Method Summary collapse

Class Method Details

.global_pathObject



95
96
97
# File 'lib/railbow/init.rb', line 95

def global_path
  File.join(Config.global_dir, "config.yml")
end

.project_pathObject



99
100
101
# File 'lib/railbow/init.rb', line 99

def project_path
  File.join(Config.root, ".railbow.yml")
end

.run(input: $stdin, output: $stdout) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/railbow/init.rb', line 103

def run(input: $stdin, output: $stdout)
  output.puts "  Where should the config be created?"
  output.puts ""
  output.puts "    1) Global:  #{global_path}"
  output.puts "    2) Project: #{project_path}"
  output.puts "    3) Cancel"
  output.puts ""
  output.print "  Choose [1/2/3]: "
  output.flush

  choice = input.gets&.strip
  target = case choice
  when "1" then global_path
  when "2" then project_path
  else
    output.puts "  Cancelled."
    return
  end

  if File.exist?(target)
    output.puts "  Already exists: #{target}"
    output.puts "  Remove it first if you want to regenerate."
    return
  end

  FileUtils.mkdir_p(File.dirname(target))
  File.write(target, TEMPLATE)
  output.puts ""
  output.puts "  Created: #{target}"
end