Class: RokuBuilder::Config

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

Overview

Load and validate config files.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options:) ⇒ Config

Returns a new instance of Config.



10
11
12
13
14
15
# File 'lib/roku_builder/config.rb', line 10

def initialize(options:)
  @options = options
  @logger = Logger.instance
  @config = nil
  @parsed = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



73
74
75
# File 'lib/roku_builder/config.rb', line 73

def method_missing(method)
  @parsed[method]
end

Instance Attribute Details

#parsedObject (readonly)

Returns the value of attribute parsed.



8
9
10
# File 'lib/roku_builder/config.rb', line 8

def parsed
  @parsed
end

Instance Method Details

#configureObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/roku_builder/config.rb', line 47

def configure
  if @options[:configure]
    source_config = File.expand_path(File.join(File.dirname(__FILE__), "..", '..', 'config.json.example'))
    target_config = File.expand_path(@options[:config])
    if File.exist?(target_config)
      unless @options[:edit_params]
        raise InvalidOptions, "Not overwriting config. Add --edit options to do so."
      end
    end
    FileUtils.copy(source_config, target_config)
    edit if @options[:edit_params]
  end
end

#editObject



38
39
40
41
42
43
44
45
# File 'lib/roku_builder/config.rb', line 38

def edit
  load
  apply_options
  config_string = JSON.pretty_generate(@config)
  file = File.open(@options[:config], "w")
  file.write(config_string)
  file.close
end

#in=(new_in) ⇒ Object



65
66
67
# File 'lib/roku_builder/config.rb', line 65

def in=(new_in)
  @parsed[:in] = new_in
end

#loadObject



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

def load
  check_config_file
  load_config
end

#out=(new_out) ⇒ Object



69
70
71
# File 'lib/roku_builder/config.rb', line 69

def out=(new_out)
  @parsed[:out] = new_out
end

#parse(stage: nil, options: nil) ⇒ Object



26
27
28
29
30
# File 'lib/roku_builder/config.rb', line 26

def parse(stage: nil, options: nil)
  @options = options if options
  @options[:stage] = stage if stage
  @parsed = ConfigParser.parse(options: @options, config: @config)
end

#rawObject



17
18
19
# File 'lib/roku_builder/config.rb', line 17

def raw
  @config
end

#root_dir=(root_dir) ⇒ Object



61
62
63
# File 'lib/roku_builder/config.rb', line 61

def root_dir=(root_dir)
  @parsed[:root_dir] = root_dir
end

#validateObject

Raises:



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

def validate
  validator = ConfigValidator.new(config: @config)
  validator.print_errors
  raise InvalidConfig if validator.is_fatal?
end