Class: Railbow::Status::GitData
- Inherits:
-
Object
- Object
- Railbow::Status::GitData
- Defined in:
- lib/railbow/status/git_data.rb
Overview
Every git lookup db:migrate:status makes about a migrations directory: who wrote each migration, when it landed on the mainline, which branch introduced it, and what is still uncommitted.
One instance per migrations directory. Multi-database runs reuse the
instance across databases that share a directory, which is what keeps
git log from running once per database.
Constant Summary collapse
- EMPTY_AUTHORS =
{names: {}, emails: {}}.freeze
Instance Attribute Summary collapse
-
#author_emails ⇒ Object
readonly
Returns the value of attribute author_emails.
-
#author_names ⇒ Object
readonly
Returns the value of attribute author_names.
-
#branch_origins ⇒ Object
readonly
Returns the value of attribute branch_origins.
-
#git_email ⇒ Object
readonly
Returns the value of attribute git_email.
-
#git_name ⇒ Object
readonly
Returns the value of attribute git_name.
-
#incoming_merge_files ⇒ Object
readonly
Returns the value of attribute incoming_merge_files.
-
#landed_dates ⇒ Object
readonly
Returns the value of attribute landed_dates.
-
#merge_source_label ⇒ Object
readonly
Returns the value of attribute merge_source_label.
-
#migrate_dir ⇒ Object
readonly
Returns the value of attribute migrate_dir.
-
#uncommitted_files ⇒ Object
readonly
Returns the value of attribute uncommitted_files.
Class Method Summary collapse
-
.apply_branch_mask(branch, branch_mask) ⇒ Object
Extracts a display label from a branch name.
-
.for(migrate_dir:, **opts) ⇒ Object
Shares one instance per migrations directory across a multi-database run.
Instance Method Summary collapse
-
#initialize(migrate_dir:, author_enabled:, diff_enabled:, base_override: "", branch_mask: "") ⇒ GitData
constructor
migrate_dir is nil when no migration file could be located, in which case every file-scoped lookup is skipped and the accessors stay empty.
Constructor Details
#initialize(migrate_dir:, author_enabled:, diff_enabled:, base_override: "", branch_mask: "") ⇒ GitData
migrate_dir is nil when no migration file could be located, in which case every file-scoped lookup is skipped and the accessors stay empty.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/railbow/status/git_data.rb', line 26 def initialize(migrate_dir:, author_enabled:, diff_enabled:, base_override: "", branch_mask: "") @migrate_dir = migrate_dir @author_names = {} @author_emails = {} @landed_dates = {} @branch_origins = {} @uncommitted_files = Set.new @incoming_merge_files = Set.new @merge_source_label = nil () load_diff(branch_mask, base_override) if diff_enabled && migrate_dir end |
Instance Attribute Details
#author_emails ⇒ Object (readonly)
Returns the value of attribute author_emails.
20 21 22 |
# File 'lib/railbow/status/git_data.rb', line 20 def @author_emails end |
#author_names ⇒ Object (readonly)
Returns the value of attribute author_names.
20 21 22 |
# File 'lib/railbow/status/git_data.rb', line 20 def @author_names end |
#branch_origins ⇒ Object (readonly)
Returns the value of attribute branch_origins.
20 21 22 |
# File 'lib/railbow/status/git_data.rb', line 20 def branch_origins @branch_origins end |
#git_email ⇒ Object (readonly)
Returns the value of attribute git_email.
20 21 22 |
# File 'lib/railbow/status/git_data.rb', line 20 def git_email @git_email end |
#git_name ⇒ Object (readonly)
Returns the value of attribute git_name.
20 21 22 |
# File 'lib/railbow/status/git_data.rb', line 20 def git_name @git_name end |
#incoming_merge_files ⇒ Object (readonly)
Returns the value of attribute incoming_merge_files.
20 21 22 |
# File 'lib/railbow/status/git_data.rb', line 20 def incoming_merge_files @incoming_merge_files end |
#landed_dates ⇒ Object (readonly)
Returns the value of attribute landed_dates.
20 21 22 |
# File 'lib/railbow/status/git_data.rb', line 20 def landed_dates @landed_dates end |
#merge_source_label ⇒ Object (readonly)
Returns the value of attribute merge_source_label.
20 21 22 |
# File 'lib/railbow/status/git_data.rb', line 20 def merge_source_label @merge_source_label end |
#migrate_dir ⇒ Object (readonly)
Returns the value of attribute migrate_dir.
20 21 22 |
# File 'lib/railbow/status/git_data.rb', line 20 def migrate_dir @migrate_dir end |
#uncommitted_files ⇒ Object (readonly)
Returns the value of attribute uncommitted_files.
20 21 22 |
# File 'lib/railbow/status/git_data.rb', line 20 def uncommitted_files @uncommitted_files end |
Class Method Details
.apply_branch_mask(branch, branch_mask) ⇒ Object
Extracts a display label from a branch name. "auto" uses the built-in ticket pattern; anything else is a regex whose first capture wins.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/railbow/status/git_data.rb', line 53 def self.apply_branch_mask(branch, branch_mask) return branch if branch_mask.empty? return Railbow::Params.extract_branch_ticket(branch) if branch_mask == "auto" re = begin Regexp.new(branch_mask, Regexp::IGNORECASE) rescue RegexpError return branch end m = branch.match(re) (m && m[1]) ? m[1] : branch end |
.for(migrate_dir:, **opts) ⇒ Object
Shares one instance per migrations directory across a multi-database
run. Databases that share a directory (shards) or a run that renders
several databases would otherwise repeat the same full-history
git log once per database.
44 45 46 47 48 49 |
# File 'lib/railbow/status/git_data.rb', line 44 def self.for(migrate_dir:, **opts) cache = Railbow::MultiDb.current&.git_cache return new(migrate_dir: migrate_dir, **opts) unless cache cache[[migrate_dir, opts]] ||= new(migrate_dir: migrate_dir, **opts) end |