Class: RokuBuilder::Stager

Inherits:
Object
  • Object
show all
Defined in:
lib/roku_builder/stager.rb

Overview

Change stage of roku application

Instance Method Summary collapse

Constructor Details

#initialize(config:, options:) ⇒ Stager

Returns a new instance of Stager.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/roku_builder/stager.rb', line 8

def initialize(config:, options:)
  @config = config
  @options = options
  @method = get_method
  @ref = get_git_ref
  @scripts = get_scripts
  @root_dir = config.root_dir
  @logger = Logger.instance
  @stage_success = true
  @stash_key = "roku-builder-temp-stash"
end

Instance Method Details

#methodSymbol

Helper method to get the staging method being used

Returns:

  • (Symbol)

    staging method being used



22
23
24
# File 'lib/roku_builder/stager.rb', line 22

def method
  @method
end

#stageBoolean

Change the stage of the app depending on the method

Returns:

  • (Boolean)

    whether the staging was successful or not



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/roku_builder/stager.rb', line 29

def stage
  @orginal_directory = Dir.pwd
  case @method
  when :current, :in
    # Do Nothing
  when :working
    switch_directory
  when :git
    switch_directory
    begin
      git_switch_to(branch: @ref)
    rescue Git::GitExecuteError
      git_rescue
      @stage_success = false
    end
  when :script
    switch_directory
    RokuBuilder.system(command: @scripts[:stage])
  end
  @stage_success
end

#unstageBoolean

Revert the change that the stage method made

Returns:

  • (Boolean)

    whether the revert was successful or not



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/roku_builder/stager.rb', line 53

def unstage
  @orginal_directory ||= Dir.pwd
  unstage_success = true
  case @method
  when :current, :in, :working
    # Do Nothing
  when :git
    switch_directory
    begin
      git_switch_from(branch: @ref, checkout: @stage_success)
    rescue Git::GitExecuteError
      git_rescue
      unstage_success = false
    end
    switch_directory_back
  when :script
    switch_directory
    RokuBuilder.system(command: @scripts[:unstage])  if @scripts[:unstage]
    switch_directory_back
  end
  unstage_success
end