Class: Branchy::Branch
- Inherits:
-
Object
- Object
- Branchy::Branch
- Defined in:
- lib/branchy/branch.rb
Overview
A class for getting a branch’s database name
Instance Attribute Summary collapse
-
#scm ⇒ Object
readonly
The SCM driver.
Instance Method Summary collapse
-
#database(prefix) ⇒ Object
(also: #db)
Returns prefix + branch name (e.g. “my_project_development_my_branch”), replacing any db name unfriendly characthers with _.
-
#database_if_enabled(prefix) ⇒ Object
(also: #db_if_enabled)
Returns the prefix + branch name, but only if branched db has been enabled for this branch.
-
#disable! ⇒ Object
Disable a branched database for this branch.
-
#enable! ⇒ Object
Enable a branched database for this branch.
-
#initialize(driver) ⇒ Branch
constructor
Initializes a new Branchy with the specified SCM driver.
-
#name ⇒ Object
Returns the name of the current branch.
Constructor Details
#initialize(driver) ⇒ Branch
Initializes a new Branchy with the specified SCM driver
36 37 38 |
# File 'lib/branchy/branch.rb', line 36 def initialize(driver) @scm = driver end |
Instance Attribute Details
#scm ⇒ Object (readonly)
The SCM driver
33 34 35 |
# File 'lib/branchy/branch.rb', line 33 def scm @scm end |
Instance Method Details
#database(prefix) ⇒ Object Also known as: db
Returns prefix + branch name (e.g. “my_project_development_my_branch”), replacing any db name unfriendly characthers with _. If it’s the master/trunk/mainline branch only the prefix is returned.
48 49 50 51 |
# File 'lib/branchy/branch.rb', line 48 def database(prefix) db_name = scm.trunk? ? prefix : "#{prefix}_#{name}" db_name.gsub(/[^A-Za-z0-9_]+/, '_')[0, 63] end |
#database_if_enabled(prefix) ⇒ Object Also known as: db_if_enabled
Returns the prefix + branch name, but only if branched db has been enabled for this branch. Otherwise it just returns the prefix.
57 58 59 |
# File 'lib/branchy/branch.rb', line 57 def database_if_enabled(prefix) scm.enabled? ? database(prefix) : prefix end |
#disable! ⇒ Object
Disable a branched database for this branch
69 70 71 |
# File 'lib/branchy/branch.rb', line 69 def disable! scm.disable! end |
#enable! ⇒ Object
Enable a branched database for this branch
64 65 66 |
# File 'lib/branchy/branch.rb', line 64 def enable! scm.enable! end |
#name ⇒ Object
Returns the name of the current branch
41 42 43 |
# File 'lib/branchy/branch.rb', line 41 def name scm.branch end |