Module: Railbow::Params
- Defined in:
- lib/railbow/params.rb
Constant Summary collapse
- TICKET_RE =
Built-in regex for extracting ticket/task identifiers from branch names. Matches patterns like: ws-123, 123, abc123, ab-123-456, feat/ws-1234, feat/123-some-feature
/(?:^|\/)([a-z]{1,5}-?\d+(?:-\d+)*|\d+(?:-\d+)*)/i
Class Method Summary collapse
- .author_format ⇒ Object
-
.calendar ⇒ Object
--- Compound: RBW_CALENDAR ---.
-
.calendar_counts? ⇒ Boolean
Append "· N migrations" to every separator row: how many it introduces.
- .calendar_label ⇒ Object
-
.calendar_wdividers? ⇒ Boolean
A separator row per ISO week, the fuller counterpart to wticks.
- .calendar_week_label ⇒ Object
- .calendar_wticks? ⇒ Boolean
-
.compact ⇒ Object
--- Compound: RBW_COMPACT ---.
- .compact_dense? ⇒ Boolean
- .compact_hidden_columns ⇒ Object
- .compact_maxw ⇒ Object
- .compact_noheader? ⇒ Boolean
- .compact_oneline? ⇒ Boolean
- .compact_options ⇒ Object
- .compact_strip_format? ⇒ Boolean
-
.date_format ⇒ Object
--- RBW_DATE ---.
-
.db ⇒ Object
--- Compound: RBW_DB ---.
-
.db_focus? ⇒ Boolean
Expand only the first database, summarizing the rest in a line each - but never at the cost of hiding work: a database holding pending migrations is always drawn in full, since that is the one thing you may need to act on.
-
.db_full? ⇒ Boolean
Draw the full table for every database, including the quiet ones that would otherwise collapse to a summary line.
-
.db_included?(name) ⇒ Boolean
Whether a database, by its database.yml name, is part of this run.
-
.db_inline? ⇒ Boolean
Render every database in one time-ordered table instead of a section each.
- .db_only ⇒ Object
- .db_skip ⇒ Object
-
.extract_branch_ticket(branch) ⇒ Object
Extract a ticket identifier from a branch name.
- .force? ⇒ Boolean
-
.format_author(name) ⇒ Object
Format an author name using NameFormatter.
-
.format_authors(names) ⇒ Object
Format a batch of author names with collision resolution.
-
.git ⇒ Object
--- Compound: RBW_GIT ---.
- .git_author ⇒ Object
- .git_base ⇒ Object
- .git_diff? ⇒ Boolean
- .git_mask ⇒ Object
-
.help? ⇒ Boolean
--- Global accessors ---.
-
.parse_compound(value) ⇒ Object
Parse compound ENV value: "author:me,diff,base:develop" → { "author" => "me", "diff" => true, "base" => "develop" } Repeated keys collect into arrays: "hide:date,hide:author" → { "hide" => ["date", "author"] }.
-
.parse_since(value, context: nil) ⇒ Object
Parse SINCE value like "2mo", "30d", "1w", "1y" into a Date cutoff.
- .plain? ⇒ Boolean
- .since ⇒ Object
-
.since_min ⇒ Object
Floor on how many migrations survive the SINCE window.
- .sort ⇒ Object
- .truthy?(value) ⇒ Boolean
- .verb ⇒ Object
-
.view ⇒ Object
--- Compound: RBW_VIEW ---.
- .view_calendar? ⇒ Boolean
- .view_tables? ⇒ Boolean
Class Method Details
.author_format ⇒ Object
160 161 162 |
# File 'lib/railbow/params.rb', line 160 def ENV["RBW_AUTHOR_FORMAT"] || Config.load["author_format"] || "short" end |
.calendar ⇒ Object
--- Compound: RBW_CALENDAR ---
274 275 276 |
# File 'lib/railbow/params.rb', line 274 def calendar parse_compound(ENV["RBW_CALENDAR"] || Config.load["calendar"]) end |
.calendar_counts? ⇒ Boolean
Append "· N migrations" to every separator row: how many it introduces.
292 293 294 295 296 |
# File 'lib/railbow/params.rb', line 292 def calendar_counts? return false unless view_calendar? calendar["counts"] == true end |
.calendar_label ⇒ Object
298 299 300 |
# File 'lib/railbow/params.rb', line 298 def calendar_label calendar["label"] || Calendar::DEFAULT_MONTH_LABEL end |
.calendar_wdividers? ⇒ Boolean
A separator row per ISO week, the fuller counterpart to wticks.
285 286 287 288 289 |
# File 'lib/railbow/params.rb', line 285 def calendar_wdividers? return false unless view_calendar? calendar["wdividers"] == true end |
.calendar_week_label ⇒ Object
302 303 304 |
# File 'lib/railbow/params.rb', line 302 def calendar_week_label calendar["wlabel"] || Calendar::DEFAULT_WEEK_LABEL end |
.calendar_wticks? ⇒ Boolean
278 279 280 281 282 |
# File 'lib/railbow/params.rb', line 278 def calendar_wticks? return false unless view_calendar? calendar["wticks"] == true end |
.compact ⇒ Object
--- Compound: RBW_COMPACT ---
100 101 102 |
# File 'lib/railbow/params.rb', line 100 def compact parse_compound(ENV["RBW_COMPACT"] || Config.load["compact"]) end |
.compact_dense? ⇒ Boolean
112 113 114 |
# File 'lib/railbow/params.rb', line 112 def compact_dense? compact["dense"] == true end |
.compact_hidden_columns ⇒ Object
125 126 127 128 129 |
# File 'lib/railbow/params.rb', line 125 def compact_hidden_columns val = compact["hide"] return [] if val.nil? Array(val) end |
.compact_maxw ⇒ Object
120 121 122 123 |
# File 'lib/railbow/params.rb', line 120 def compact_maxw val = compact["maxw"] val.is_a?(String) ? val.to_i : nil end |
.compact_noheader? ⇒ Boolean
116 117 118 |
# File 'lib/railbow/params.rb', line 116 def compact_noheader? compact["noheader"] == true end |
.compact_oneline? ⇒ Boolean
104 105 106 |
# File 'lib/railbow/params.rb', line 104 def compact_oneline? compact["oneline"] == true end |
.compact_options ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/railbow/params.rb', line 131 def c = compact maxw_val = c["maxw"] hide_val = c["hide"] { oneline: c["oneline"] == true, dense: c["dense"] == true, noheader: c["noheader"] == true, maxw: maxw_val.is_a?(String) ? maxw_val.to_i : nil, hidden_columns: hide_val.nil? ? [] : Array(hide_val) } end |
.compact_strip_format? ⇒ Boolean
108 109 110 |
# File 'lib/railbow/params.rb', line 108 def compact_strip_format? compact["strip-format"] == true end |
.date_format ⇒ Object
--- RBW_DATE ---
204 205 206 207 208 209 |
# File 'lib/railbow/params.rb', line 204 def date_format val = ENV["RBW_DATE"] || Config.load["date"] return "full" if val.nil? || val.to_s.strip.empty? val.to_s.strip end |
.db ⇒ Object
--- Compound: RBW_DB ---
231 232 233 |
# File 'lib/railbow/params.rb', line 231 def db parse_compound(ENV["RBW_DB"] || Config.load["db"]) end |
.db_focus? ⇒ Boolean
Expand only the first database, summarizing the rest in a line each - but never at the cost of hiding work: a database holding pending migrations is always drawn in full, since that is the one thing you may need to act on. RBW_DB=full overrides it, and it does not apply to inline runs.
251 252 253 |
# File 'lib/railbow/params.rb', line 251 def db_focus? db["focus"] == true end |
.db_full? ⇒ Boolean
Draw the full table for every database, including the quiet ones that would otherwise collapse to a summary line.
243 244 245 |
# File 'lib/railbow/params.rb', line 243 def db_full? db["full"] == true end |
.db_included?(name) ⇒ Boolean
Whether a database, by its database.yml name, is part of this run.
264 265 266 267 268 269 270 |
# File 'lib/railbow/params.rb', line 264 def db_included?(name) name = name.to_s only = db_only return only.include?(name) if only.any? !db_skip.include?(name) end |
.db_inline? ⇒ Boolean
Render every database in one time-ordered table instead of a section each. Only meaningful when the databases keep separate migration sets.
237 238 239 |
# File 'lib/railbow/params.rb', line 237 def db_inline? db["inline"] == true end |
.db_only ⇒ Object
255 256 257 |
# File 'lib/railbow/params.rb', line 255 def db_only Array(db["only"]).select { |v| v.is_a?(String) } end |
.db_skip ⇒ Object
259 260 261 |
# File 'lib/railbow/params.rb', line 259 def db_skip Array(db["skip"]).select { |v| v.is_a?(String) } end |
.extract_branch_ticket(branch) ⇒ Object
Extract a ticket identifier from a branch name. Returns the matched identifier or the original branch name if no match.
197 198 199 200 |
# File 'lib/railbow/params.rb', line 197 def extract_branch_ticket(branch) m = branch.match(TICKET_RE) m ? m[1] : branch end |
.force? ⇒ Boolean
75 76 77 |
# File 'lib/railbow/params.rb', line 75 def force? truthy?(ENV["RBW_FORCE"]) end |
.format_author(name) ⇒ Object
Format an author name using NameFormatter. Accepts preset names ("initials", "first_name", etc.) or custom patterns ("FF L", "FFFF L.", "LLLL, FFFF").
167 168 169 |
# File 'lib/railbow/params.rb', line 167 def (name) NameFormatter.format(name, ) end |
.format_authors(names) ⇒ Object
Format a batch of author names with collision resolution. Returns Hash=> String mapping raw names to disambiguated formatted names.
173 174 175 |
# File 'lib/railbow/params.rb', line 173 def (names) NameCollisionResolver.resolve(names, ) end |
.git ⇒ Object
--- Compound: RBW_GIT ---
150 151 152 |
# File 'lib/railbow/params.rb', line 150 def git parse_compound(ENV["RBW_GIT"] || Config.load["git"]) end |
.git_author ⇒ Object
154 155 156 157 158 |
# File 'lib/railbow/params.rb', line 154 def val = git["author"] return "off" if val.nil? (val == true) ? "all" : val.strip.downcase end |
.git_base ⇒ Object
181 182 183 184 |
# File 'lib/railbow/params.rb', line 181 def git_base val = git["base"] val.is_a?(String) ? val : "" end |
.git_diff? ⇒ Boolean
177 178 179 |
# File 'lib/railbow/params.rb', line 177 def git_diff? git["diff"] == true end |
.git_mask ⇒ Object
186 187 188 189 |
# File 'lib/railbow/params.rb', line 186 def git_mask val = git["mask"] val.is_a?(String) ? val : "" end |
.help? ⇒ Boolean
--- Global accessors ---
67 68 69 |
# File 'lib/railbow/params.rb', line 67 def help? truthy?(ENV["RBW_HELP"]) end |
.parse_compound(value) ⇒ Object
Parse compound ENV value: "author:me,diff,base:develop" → { "author" => "me", "diff" => true, "base" => "develop" } Repeated keys collect into arrays: "hide:date,hide:author" → { "hide" => ["date", "author"] }
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/railbow/params.rb', line 17 def parse_compound(value) return {} if value.nil? || value.strip.empty? result = {} value.strip.split(",").each do |token| token = token.strip next if token.empty? key, val = token.split(":", 2) key = key.strip val = val ? val.strip : true result[key] = if result.key?(key) Array(result[key]) << val else val end end result end |
.parse_since(value, context: nil) ⇒ Object
Parse SINCE value like "2mo", "30d", "1w", "1y" into a Date cutoff. Returns nil for "all" or unrecognized values.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/railbow/params.rb', line 44 def parse_since(value, context: nil) return nil if value.nil? || value.strip.downcase == "all" match = value.strip.match(/^(\d+)(d|w|mo|m|y)$/i) unless match label = context ? " for #{context}" : "" warn " Warning: unrecognized RBW_SINCE=#{value}#{label}, showing all" return nil end amount = match[1].to_i unit = match[2].downcase case unit when "d" then Date.today - amount when "w" then Date.today - (amount * 7) when "mo", "m" then Date.today.prev_month(amount) when "y" then Date.today.prev_year(amount) end end |
.plain? ⇒ Boolean
71 72 73 |
# File 'lib/railbow/params.rb', line 71 def plain? truthy?(ENV["RBW_PLAIN"]) end |
.since ⇒ Object
79 80 81 |
# File 'lib/railbow/params.rb', line 79 def since (ENV["RBW_SINCE"] || Config.load["since"] || "all").strip.downcase end |
.since_min ⇒ Object
Floor on how many migrations survive the SINCE window. The window is a soft limit: when it leaves fewer rows than this, the oldest ones are pulled back in until the count is met. 0 disables the floor.
Deliberately a knob of its own rather than a token inside RBW_SINCE, so
an ad-hoc RBW_SINCE=2mo keeps the floor instead of silently dropping it.
89 90 91 92 |
# File 'lib/railbow/params.rb', line 89 def since_min value = ENV["RBW_SINCE_MIN"] || Config.load["since_min"] || 0 [value.to_i, 0].max end |
.sort ⇒ Object
94 95 96 |
# File 'lib/railbow/params.rb', line 94 def sort (ENV["RBW_SORT"] || Config.load["sort"] || "file").strip.downcase end |
.truthy?(value) ⇒ Boolean
38 39 40 |
# File 'lib/railbow/params.rb', line 38 def truthy?(value) %w[1 true yes on].include?(value.to_s.strip.downcase) end |
.verb ⇒ Object
144 145 146 |
# File 'lib/railbow/params.rb', line 144 def verb ENV["RBW_VERB"] || Config.load["verb"] end |
.view ⇒ Object
--- Compound: RBW_VIEW ---
213 214 215 |
# File 'lib/railbow/params.rb', line 213 def view parse_compound(ENV["RBW_VIEW"] || Config.load["view"]) end |
.view_calendar? ⇒ Boolean
217 218 219 |
# File 'lib/railbow/params.rb', line 217 def view_calendar? view["calendar"] == true end |
.view_tables? ⇒ Boolean
221 222 223 224 225 226 227 |
# File 'lib/railbow/params.rb', line 221 def view_tables? val = view["tables"] if val == "nowrap" warn " Warning: RBW_VIEW=tables:nowrap is deprecated. Use RBW_COMPACT=oneline instead." end !val.nil? end |