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_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 ---.
-
.extract_branch_ticket(branch) ⇒ Object
Extract a ticket identifier from a branch name.
-
.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
- .sort ⇒ Object
- .truthy?(value) ⇒ Boolean
- .verb ⇒ Object
-
.view ⇒ Object
--- Compound: RBW_VIEW ---.
- .view_calendar? ⇒ Boolean
- .view_tables? ⇒ Boolean
Class Method Details
.author_format ⇒ Object
144 145 146 |
# File 'lib/railbow/params.rb', line 144 def ENV["RBW_AUTHOR_FORMAT"] || Config.load["author_format"] || "short" end |
.calendar ⇒ Object
--- Compound: RBW_CALENDAR ---
215 216 217 |
# File 'lib/railbow/params.rb', line 215 def calendar parse_compound(ENV["RBW_CALENDAR"] || Config.load["calendar"]) end |
.calendar_label ⇒ Object
225 226 227 |
# File 'lib/railbow/params.rb', line 225 def calendar_label calendar["label"] || "%b %Y W%V" end |
.calendar_wticks? ⇒ Boolean
219 220 221 222 223 |
# File 'lib/railbow/params.rb', line 219 def calendar_wticks? return false unless view_calendar? calendar["wticks"] == true end |
.compact ⇒ Object
--- Compound: RBW_COMPACT ---
84 85 86 |
# File 'lib/railbow/params.rb', line 84 def compact parse_compound(ENV["RBW_COMPACT"] || Config.load["compact"]) end |
.compact_dense? ⇒ Boolean
96 97 98 |
# File 'lib/railbow/params.rb', line 96 def compact_dense? compact["dense"] == true end |
.compact_hidden_columns ⇒ Object
109 110 111 112 113 |
# File 'lib/railbow/params.rb', line 109 def compact_hidden_columns val = compact["hide"] return [] if val.nil? Array(val) end |
.compact_maxw ⇒ Object
104 105 106 107 |
# File 'lib/railbow/params.rb', line 104 def compact_maxw val = compact["maxw"] val.is_a?(String) ? val.to_i : nil end |
.compact_noheader? ⇒ Boolean
100 101 102 |
# File 'lib/railbow/params.rb', line 100 def compact_noheader? compact["noheader"] == true end |
.compact_oneline? ⇒ Boolean
88 89 90 |
# File 'lib/railbow/params.rb', line 88 def compact_oneline? compact["oneline"] == true end |
.compact_options ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/railbow/params.rb', line 115 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
92 93 94 |
# File 'lib/railbow/params.rb', line 92 def compact_strip_format? compact["strip-format"] == true end |
.date_format ⇒ Object
--- RBW_DATE ---
188 189 190 191 192 193 |
# File 'lib/railbow/params.rb', line 188 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 |
.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.
181 182 183 184 |
# File 'lib/railbow/params.rb', line 181 def extract_branch_ticket(branch) m = branch.match(TICKET_RE) m ? m[1] : branch 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").
151 152 153 |
# File 'lib/railbow/params.rb', line 151 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.
157 158 159 |
# File 'lib/railbow/params.rb', line 157 def (names) NameCollisionResolver.resolve(names, ) end |
.git ⇒ Object
--- Compound: RBW_GIT ---
134 135 136 |
# File 'lib/railbow/params.rb', line 134 def git parse_compound(ENV["RBW_GIT"] || Config.load["git"]) end |
.git_author ⇒ Object
138 139 140 141 142 |
# File 'lib/railbow/params.rb', line 138 def val = git["author"] return "off" if val.nil? (val == true) ? "all" : val.strip.downcase end |
.git_base ⇒ Object
165 166 167 168 |
# File 'lib/railbow/params.rb', line 165 def git_base val = git["base"] val.is_a?(String) ? val : "" end |
.git_diff? ⇒ Boolean
161 162 163 |
# File 'lib/railbow/params.rb', line 161 def git_diff? git["diff"] == true end |
.git_mask ⇒ Object
170 171 172 173 |
# File 'lib/railbow/params.rb', line 170 def git_mask val = git["mask"] val.is_a?(String) ? val : "" end |
.help? ⇒ Boolean
--- Global accessors ---
66 67 68 |
# File 'lib/railbow/params.rb', line 66 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"] }
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/railbow/params.rb', line 16 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.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/railbow/params.rb', line 43 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
70 71 72 |
# File 'lib/railbow/params.rb', line 70 def plain? truthy?(ENV["RBW_PLAIN"]) end |
.since ⇒ Object
74 75 76 |
# File 'lib/railbow/params.rb', line 74 def since (ENV["RBW_SINCE"] || Config.load["since"] || "all").strip.downcase end |
.sort ⇒ Object
78 79 80 |
# File 'lib/railbow/params.rb', line 78 def sort (ENV["RBW_SORT"] || Config.load["sort"] || "file").strip.downcase end |
.truthy?(value) ⇒ Boolean
37 38 39 |
# File 'lib/railbow/params.rb', line 37 def truthy?(value) %w[1 true yes on].include?(value.to_s.strip.downcase) end |
.verb ⇒ Object
128 129 130 |
# File 'lib/railbow/params.rb', line 128 def verb ENV["RBW_VERB"] || Config.load["verb"] end |
.view ⇒ Object
--- Compound: RBW_VIEW ---
197 198 199 |
# File 'lib/railbow/params.rb', line 197 def view parse_compound(ENV["RBW_VIEW"] || Config.load["view"]) end |
.view_calendar? ⇒ Boolean
201 202 203 |
# File 'lib/railbow/params.rb', line 201 def view_calendar? view["calendar"] == true end |
.view_tables? ⇒ Boolean
205 206 207 208 209 210 211 |
# File 'lib/railbow/params.rb', line 205 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 |