Class: Branchy::Branch

Inherits:
Object
  • Object
show all
Defined in:
lib/branchy/branch.rb

Overview

A class for getting a branch’s database name

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#scmObject (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

#nameObject

Returns the name of the current branch



41
42
43
# File 'lib/branchy/branch.rb', line 41

def name
  scm.branch
end