Class: EY::DeployConfig::Ref

Inherits:
Object
  • Object
show all
Defined in:
lib/engineyard/deploy_config/ref.rb

Instance Method Summary collapse

Constructor Details

#initialize(cli_opts, env_config, repo, ui) ⇒ Ref

Returns a new instance of Ref.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/engineyard/deploy_config/ref.rb', line 7

def initialize(cli_opts, env_config, repo, ui)
  @cli_opts  = cli_opts
  @default   = env_config.branch
  @repo      = repo
  @force_ref = @cli_opts.fetch('force_ref', false)
  @ui        = ui

  if @force_ref.kind_of?(String)
    @ref, @force_ref = @force_ref, true
  else
    @ref = @cli_opts.fetch('ref', nil)
    @ref = nil if @ref == ''
  end
end

Instance Method Details

#use_current_branchObject



39
40
41
42
43
44
# File 'lib/engineyard/deploy_config/ref.rb', line 39

def use_current_branch
  if current = @repo.current_branch
    @ui.say "Using current HEAD branch #{current.inspect}."
    current
  end
end

#use_defaultObject



32
33
34
35
36
37
# File 'lib/engineyard/deploy_config/ref.rb', line 32

def use_default
  if @default
    @ui.say "Using default branch #{@default.inspect} from ey.yml."
    @default
  end
end

#when_inside_repoObject



22
23
24
25
26
27
28
29
30
# File 'lib/engineyard/deploy_config/ref.rb', line 22

def when_inside_repo
  if !@force_ref && @ref && @default && @ref != @default
    raise BranchMismatchError.new(@default, @ref)
  elsif @force_ref && @ref && @default
    @ui.say "Default ref overridden with #{@ref.inspect}."
  end

  @ref || use_default || use_current_branch || raise(RefRequired.new(@cli_opts))
end

#when_outside_repoObject

a.k.a. not in the correct repo

returns the ref if it was passed in the cli opts. or raise



50
51
52
# File 'lib/engineyard/deploy_config/ref.rb', line 50

def when_outside_repo
  @ref or raise RefAndMigrateRequiredOutsideRepo.new(@cli_opts)
end