Class: GitWorkflow::Configuration::Convention

Inherits:
Object
  • Object
show all
Includes:
Git
Defined in:
lib/git_workflow/configuration.rb

Defined Under Namespace

Classes: StoryWrapper

Constant Summary collapse

REGEXP_STORY_ID =
/\$\{\s*number\s*\}/
REGEXP_EVALUATION =
/\$\{(number|name)\}/

Instance Method Summary collapse

Methods included from Git

#checkout_or_create_branch, #get_config_value_for, #get_config_value_for!, #in_git_branch, #merge_branch, #repository, #set_config_value

Constructor Details

#initialize(convention) ⇒ Convention

Returns a new instance of Convention.

Raises:

  • (StandardError)


15
16
17
18
19
# File 'lib/git_workflow/configuration.rb', line 15

def initialize(convention)
  raise StandardError, "Convention '#{ convention }' has no story ID" unless convention =~ REGEXP_STORY_ID
  @to_convention   = convention.gsub(REGEXP_EVALUATION, '#{\1}')
  @from_convention = Regexp.new(convention.sub(REGEXP_STORY_ID, '(\d+)').gsub(REGEXP_EVALUATION, '.+'))
end

Instance Method Details

#from(branch) ⇒ Object

Raises:

  • (StandardError)


25
26
27
28
29
# File 'lib/git_workflow/configuration.rb', line 25

def from(branch)
  match = branch.match(@from_convention)
  raise StandardError, "Branch '#{ branch }' does not appear to conform to local convention" if match.nil?
  match[ 1 ].to_i
end

#to(story) ⇒ Object



21
22
23
# File 'lib/git_workflow/configuration.rb', line 21

def to(story)
  use_existing_branch_for(story) || generate_new_branch_name_for(story)
end