Class: CarthageCacheRes::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/carthage_cache_res/configurator.rb

Constant Summary collapse

CONFIG_FILE_NAME =
".carthage_cache_res.yml"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(terminal, project_path, base_config = {}) ⇒ Configurator

Returns a new instance of Configurator.



13
14
15
16
17
# File 'lib/carthage_cache_res/configurator.rb', line 13

def initialize(terminal, project_path, base_config = {})
  @config_file_path = File.join(project_path, CONFIG_FILE_NAME)
  @base_config = merge_config(base_config)
  @terminal = terminal
end

Instance Attribute Details

#base_configObject (readonly)

Returns the value of attribute base_config.



10
11
12
# File 'lib/carthage_cache_res/configurator.rb', line 10

def base_config
  @base_config
end

#config_file_pathObject (readonly)

Returns the value of attribute config_file_path.



9
10
11
# File 'lib/carthage_cache_res/configurator.rb', line 9

def config_file_path
  @config_file_path
end

#terminalObject (readonly)

Returns the value of attribute terminal.



11
12
13
# File 'lib/carthage_cache_res/configurator.rb', line 11

def terminal
  @terminal
end

Instance Method Details

#configObject



19
20
21
# File 'lib/carthage_cache_res/configurator.rb', line 19

def config
  @config ||= load_config!
end

#save_config(config) ⇒ Object



23
24
25
26
# File 'lib/carthage_cache_res/configurator.rb', line 23

def save_config(config)
  raise "Invalid configuration" unless config.valid?
  File.open(config_file_path, 'w') { |f| f.write config.to_yaml }
end