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



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

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



135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/roku_builder/controller_commands.rb', line 135

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.link(configs[:deeplink_config])
    logger.info "Deeplinked into app"
    return SUCCESS
  else
    return FAILED_DEEPLINKING
  end
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



58
59
60
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
# File 'lib/roku_builder/controller_commands.rb', line 58

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

.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



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/roku_builder/controller_commands.rb', line 38

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, version = loader.sideload(**configs[:sideload_config])
  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



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/roku_builder/controller_commands.rb', line 158

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 ()
  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



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

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 }
  }
end

.update(configs:, logger:) ⇒ Integer

Run update

Parameters:

  • configs (Hash)

    parsed configs

  • logger (Logger)

    system logger

Returns:

  • (Integer)

    Success or Failure Code



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/roku_builder/controller_commands.rb', line 119

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



29
30
31
32
# File 'lib/roku_builder/controller_commands.rb', line 29

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