Class: RokuBuilder::ConfigParser

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

Overview

Contains methods that will parse the loaded config and generate intermeidate configs for each of the tools.

Class Method Summary collapse

Class Method Details

.parse_config(options:, config:, logger:) ⇒ Integer, Hash

Parse config and generate intermeidate configs



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/roku_builder/config_parser.rb', line 13

def self.parse_config(options:, config:, logger:)
  configs = {init_params: {}}
  #set device
  unless options[:device]
    options[:device] = config[:devices][:default]
  end
  #set project
  setup_project(config: config, options: options)
  #set outfile
  setup_outfile(options: options)
  # Create Device Config
  configs[:device_config] = config[:devices][options[:device].to_sym]
  return [UNKNOWN_DEVICE, nil, nil] unless configs[:device_config]
  configs[:device_config][:logger] = logger
  project_config = setup_project_config(config: config, options: options)
  return [project_config, nil, nil] unless project_config.class == Hash
  configs[:project_config] = project_config
  stage_config, stage = setup_stage_config(configs: configs, options: options, logger: logger)
  return [UNKNOWN_STAGE, nil, nil] unless stage
  setup_sideload_config(configs: configs, options: options)
  setup_package_config(configs: configs, options: options, stage: stage)
  setup_simple_configs(configs: configs, options: options, logger: logger)
  return [SUCCESS, configs]
end

.setup_stage_config(configs:, options:, logger:) ⇒ Hash

Setup the project stage config



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/roku_builder/config_parser.rb', line 113

def self.setup_stage_config(configs:, options:, logger:)
  stage_config = {logger: logger}
  stage = options[:stage].to_sym
  project_config = configs[:project_config]
  stage_config[:root_dir] = project_config[:directory]
  stage_config[:method] = project_config[:stage_method]
  stage_config[:method] ||= :git
  case stage_config[:method]
  when :git
    if options[:ref]
      stage_config[:key] = options[:ref]
    else
      return nil unless project_config[:stages][stage]
      stage_config[:key] = project_config[:stages][stage][:branch]
    end
  when :script
    return nil unless project_config[:stages][stage]
    stage_config[:key] = project_config[:stages][stage][:script]
  end
  configs[:stage_config] = stage_config
  configs[:stage] = stage
  [stage_config, stage]
end