Class: Pokotarou::RegistrationConfigMaker::PresetOptionSetter

Inherits:
Object
  • Object
show all
Defined in:
lib/pokotarou/registration_config_maker/preset_option_setter.rb

Class Method Summary collapse

Class Method Details

.set(all_content) ⇒ Object



7
8
9
10
11
12
13
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
43
44
45
46
47
# File 'lib/pokotarou/registration_config_maker/preset_option_setter.rb', line 7

def set all_content
  new_preset_config = {}
  preset_path = []
  all_content[:"preset_path'"].each do |path|
    YAML.load_file(path).deep_symbolize_keys!.each do |preset|
      if :"preset_path'" == preset.first
        preset_path.concat(preset.second)
      else
        new_preset_config[preset.first] = preset.second
      end
    end
  end

  # preset_pathを更新
  all_content.delete(:"preset_path'")
  if preset_path.size != 0
    preset_path.uniq!
    all_content[:"preset_path'"] = preset_path
  end

  # hashの順番を更新するために一度全てのKeyを消す
  copy_config = {}
  all_content.each do |config|
    key = config.first
    value = config.second
    copy_config[key] = value

    all_content.delete(key)
  end
  
  # presetを先に展開する必要があるので、再代入して順番を変更する
  merge(all_content, new_preset_config)
  merge(all_content, copy_config)

  # presetを展開してpresetが入っていた場合には再度展開する
  if all_content.has_key?(:"preset_path'")
    set(all_content)
  end

  all_content
end