Class: RokuBuilder::ConfigManager
- Inherits:
-
Object
- Object
- RokuBuilder::ConfigManager
- Defined in:
- lib/roku_builder/config_manager.rb
Overview
Load and validate config files.
Class Method Summary collapse
-
.edit_config(config:, options:, logger:) ⇒ Boolean
Edit the roku config.
-
.get_config(config:, logger:) ⇒ Hash
Loads the roku config from file.
-
.load_config(options:, logger:) ⇒ Integer, Hash
Load config file and generate intermeidate configs.
-
.update_configs(configs:, options:) ⇒ Hash
Update the intermeidate configs.
Class Method Details
.edit_config(config:, options:, logger:) ⇒ Boolean
Edit the roku config
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/roku_builder/config_manager.rb', line 82 def self.edit_config(config:, options:, logger:) config_object = get_config(config: config, logger: logger) return false unless config_object project = [:project].to_sym if [:project] project = config_object[:projects][:default] unless [:project] device = [:device].to_sym if [:device] device = config_object[:devices][:default] unless [:device] stage = [:stage].to_sym if [:stage] stage = :production unless [:stage] state = { project: project, device: device, stage: stage } (config_object: config_object, options: [:edit_params], state: state) config_string = JSON.pretty_generate(config_object) file = File.open(config, "w") file.write(config_string) file.close return true end |
.get_config(config:, logger:) ⇒ Hash
Loads the roku config from file
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/roku_builder/config_manager.rb', line 47 def self.get_config(config:, logger:) begin config = JSON.parse(File.open(config).read, {symbolize_names: true}) config[:devices][:default] = config[:devices][:default].to_sym config[:projects][:default] = config[:projects][:default].to_sym config[:projects].each_pair do |key,value| next if key == :default if value[:stage_method] value[:stage_method] = value[:stage_method].to_sym end end config[:projects].each_pair do |key, value| unless key == :default if value[:parent] and config[:projects][value[:parent].to_sym] new_value = config[:projects][value[:parent].to_sym] new_value = new_value.deep_merge value config[:projects][key] = new_value end end end config rescue JSON::ParserError logger.fatal "Config file is not valid JSON" nil end end |
.load_config(options:, logger:) ⇒ Integer, Hash
Load config file and generate intermeidate configs
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/roku_builder/config_manager.rb', line 14 def self.load_config(options:, logger:) config_file = File.([:config]) return MISSING_CONFIG unless File.exist?(config_file) code = SUCCESS config = ConfigManager.get_config(config: config_file, logger: logger) return INVALID_CONFIG unless config codes = ConfigValidator.validate_config(config: config) fatal = false warning = false codes.each {|a_code| if a_code > 0 logger.fatal "Invalid Config: "+ ConfigValidator.error_codes()[a_code] fatal = true elsif a_code < 0 logger.warn "Depricated Config: "+ ConfigValidator.error_codes()[a_code] warning = true elsif a_code == 0 and [:validate] logger.info "Config Valid" end } return [INVALID_CONFIG, nil, nil] if fatal code = DEPRICATED_CONFIG if warning parse_code, configs = ConfigParser.parse_config(options: , config: config, logger: logger) unless parse_code == SUCCESS return [parse_code, nil, nil] end [code, config, configs] end |
.update_configs(configs:, options:) ⇒ Hash
Update the intermeidate configs
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/roku_builder/config_manager.rb', line 126 def self.update_configs(configs:, options:) if [:build_version] configs[:package_config][:app_name_version] = "#{configs[:project_config][:app_name]} - #{configs[:stage]} - #{[:build_version]}" if configs[:package_config] unless [:outfile] pathname = File.join([:out_folder], "#{configs[:project_config][:app_name]}_#{configs[:stage]}_#{[:build_version]}") configs[:package_config][:out_file] = pathname+".pkg" if configs[:package_config] configs[:build_config][:outfile] = pathname+".zip" if configs[:build_config] configs[:inspect_config][:pkg] = configs[:package_config][:out_file] if configs[:inspect_config] and configs[:package_config] end end return configs end |