Class: RokuBuilder::ControllerCommands

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

Overview

Commands that the controller uses to interface with the rest of the gem.

Class Method Summary collapse

Class Method Details

.build(options:, configs:, logger:) ⇒ Integer

Run Build

Parameters:

  • options (Hash)

    user options

  • configs (Hash)

    parsed configs

  • logger (Logger)

    system logger

Returns:

  • (Integer)

    Success or Failure Code



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/roku_builder/controller_commands.rb', line 101

def self.build(options:, configs:, logger:)
  ### Build ###
  loader_config = configs[:device_config].dup
  loader_config[:init_params] = configs[:init_params][:loader]
  stager = Stager.new(**configs[:stage_config])
  loader = Loader.new(**loader_config)
  if stager.stage
    build_version = ManifestManager.build_version(**configs[:manifest_config])
    options[:build_version] = build_version
    configs = ConfigManager.update_configs(configs: configs, options: options)
    outfile = loader.build(**configs[:build_config])
    logger.info "Build: #{outfile}"
  end
  stager.unstage
  logger.info "App build; staged using #{stager.method}"
  SUCCESS
end

Run Deeplink

Parameters:

  • options (Hash)

    user options

  • configs (Hash)

    parsed configs

  • logger (Logger)

    system logger



138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/roku_builder/controller_commands.rb', line 138

def self.deeplink(options:, configs:, logger:)
  sources = options.keys & Controller.sources
  if sources.count > 0
    sideload(options: options, configs: configs, logger:logger)
  end

  linker = Linker.new(configs[:device_config])
  if linker.launch(configs[:deeplink_config])
    logger.info "Deeplinked into app"
    return SUCCESS
  else
    return FAILED_DEEPLINKING
  end
end

.dostage(configs:) ⇒ Object



166
167
168
169
# File 'lib/roku_builder/controller_commands.rb', line 166

def self.dostage(configs:)
  stager = Stager.new(**configs[:stage_config])
  stager.stage
end

.dounstage(configs:) ⇒ Object



171
172
173
174
# File 'lib/roku_builder/controller_commands.rb', line 171

def self.dounstage(configs:)
  stager = Stager.new(**configs[:stage_config])
  stager.unstage
end

.package(options:, configs:, logger:) ⇒ Integer

Run Package

Parameters:

  • options (Hash)

    user options

  • configs (Hash)

    parsed configs

  • logger (Logger)

    system logger

Returns:

  • (Integer)

    Success or Failure Code



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/roku_builder/controller_commands.rb', line 61

def self.package(options:, configs:, logger:)
  loader_config = configs[:device_config].dup
  loader_config[:init_params] = configs[:init_params][:loader]
  keyer = Keyer.new(**configs[:device_config])
  stager = Stager.new(**configs[:stage_config])
  loader = Loader.new(**loader_config)
  packager = Packager.new(**configs[:device_config])
  inspector = Inspector.new(**configs[:device_config])
  logger.warn "Packaging working directory" if options[:working]
  if stager.stage
    # Sideload #
    code, build_version = loader.sideload(**configs[:sideload_config])
    return code unless code = SUCCESS
    # Key #
    success = keyer.rekey(**configs[:key])
    logger.info "Key did not change" unless success
    # Package #
    options[:build_version] = build_version
    configs = ConfigManager.update_configs(configs: configs, options: options)
    success = packager.package(**configs[:package_config])
    logger.info "Signing Successful: #{configs[:package_config][:out_file]}" if success
    return FAILED_SIGNING unless success
    # Inspect #
    if options[:inspect]
      info = inspector.inspect(configs[:inspect_config])
      logger.unknown "App Name: #{info[:app_name]}"
      logger.unknown "Dev ID: #{info[:dev_id]}"
      logger.unknown "Creation Date: #{info[:creation_date]}"
      logger.unknown "dev.zip: #{info[:dev_zip]}"
    end
  end
  stager.unstage
  logger.info "App Packaged; staged using #{stager.method}"
  SUCCESS
end

Run Print

Parameters:

  • options (Hash)

    user options

  • configs (Hash)

    parsed configs



156
157
158
159
160
161
162
163
164
# File 'lib/roku_builder/controller_commands.rb', line 156

def self.print(options:, configs:)
  stager = Stager.new(**configs[:stage_config])
  code = nil
  if stager.stage
    code = Scripter.print(attribute: options[:print].to_sym, configs: configs)
  end
  stager.unstage
  code
end

.sideload(options:, configs:, logger:) ⇒ Integer

Run Sideload

Parameters:

  • options (Hash)

    user options

  • configs (Hash)

    parsed configs

  • logger (Logger)

    system logger

Returns:

  • (Integer)

    Success or Failure Code



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/roku_builder/controller_commands.rb', line 41

def self.sideload(options:, configs:, logger:)
  config = configs[:device_config].dup
  config[:init_params] = configs[:init_params][:loader]
  stager = Stager.new(**configs[:stage_config])
  success = nil
  if stager.stage
    loader = Loader.new(**config)
    success = loader.sideload(**configs[:sideload_config])[0]
  end
  stager.unstage
  unless success == FAILED_SIDELOAD
    logger.info "App Sideloaded; staged using #{stager.method}"
  end
  success
end

.simple_command(klass:, method:, config_key: nil, configs:, failure: nil, logger:) ⇒ Integer

Run a simple command

Parameters:

  • klass (Class)

    class of object to create

  • method (Symbol)

    methog to run on klass

  • config_key (Symbol) (defaults to: nil)

    config to send from configs if not nil

  • configs (Hash)

    parsed roku config

  • failure (Integer) (defaults to: nil)

    failure code to return on failure if not nil

  • logger (Logger)

    system logger

Returns:

  • (Integer)

    Success of failure code



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/roku_builder/controller_commands.rb', line 184

def self.simple_command(klass:, method:, config_key: nil, configs:, failure: nil, logger:)
  config = configs[:device_config].dup
  key = klass.to_s.split("::")[-1].underscore.to_sym
  if configs[:init_params][key]
    config[:init_params] = configs[:init_params][key]
  end
  instance = klass.new(**config)
  if config_key
    success = instance.send(method, configs[config_key])
  else
    success = instance.send(method)
  end
  return failure unless failure.nil? or success
  logger.info "#{klass} call #{method} successfully"
  SUCCESS
end

.simple_commandsHash

Provides a hash of all of the options needed to run simple commands via the simple_command method

Returns:

  • (Hash)

    options to run simple commands



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/roku_builder/controller_commands.rb', line 11

def self.simple_commands
  {
    delete: { klass: Loader, method: :unload },
    monitor: { klass: Monitor, method: :monitor,
      config_key: :monitor_config },
    navigate: { klass: Navigator, method: :nav, config_key: :navigate_config,
      failure: FAILED_NAVIGATING },
    screen: { klass: Navigator, method: :screen, config_key: :screen_config,
      failure: FAILED_NAVIGATING },
    key: { klass: Keyer, method: :rekey, config_key: :key },
    screens: { klass: Navigator, method: :screens },
    text: { klass: Navigator, method: :type, config_key: :text_config },
    test: { klass: Tester, method: :run_tests, config_key: :test_config },
    screencapture: { klass: Inspector, method: :screencapture, config_key: :screencapture_config,
      failure: FAILED_SCREENCAPTURE },
    applist: {klass: Linker, method: :list}
  }
end

.update(configs:, logger:) ⇒ Integer

Run update

Parameters:

  • configs (Hash)

    parsed configs

  • logger (Logger)

    system logger

Returns:

  • (Integer)

    Success or Failure Code



122
123
124
125
126
127
128
129
130
131
132
# File 'lib/roku_builder/controller_commands.rb', line 122

def self.update(configs:, logger:)
  ### Update ###
  stager = Stager.new(**configs[:stage_config])
  if stager.stage
    old_version = ManifestManager.build_version(**configs[:manifest_config])
    new_version = ManifestManager.update_build(**configs[:manifest_config])
    logger.info "Update build version from:\n#{old_version}\nto:\n#{new_version}"
  end
  stager.unstage
  SUCCESS
end

.validate(logger:) ⇒ Integer

Validate Config

Parameters:

  • logger (Logger)

    system logger

Returns:

  • (Integer)

    Success or Failure Code



32
33
34
35
# File 'lib/roku_builder/controller_commands.rb', line 32

def self.validate(logger:)
  logger.info "Config validated"
  SUCCESS
end