Class: YamlArgMunger
- Inherits:
-
Object
- Object
- YamlArgMunger
- Defined in:
- lib/cl/magic/dk/yaml_arg_munger.rb
Instance Method Summary collapse
- #dk_merge_and_remove(compose_hash, yml_hash) ⇒ Object
- #get_base_compose_parts_and_make_hashes ⇒ Object
-
#initialize(working_dir, world_settings) ⇒ YamlArgMunger
constructor
A new instance of YamlArgMunger.
- #save_yaml_and_adjust_args(compose_hash, args) ⇒ Object
Constructor Details
#initialize(working_dir, world_settings) ⇒ YamlArgMunger
Returns a new instance of YamlArgMunger.
5 6 7 8 9 |
# File 'lib/cl/magic/dk/yaml_arg_munger.rb', line 5 def initialize(working_dir, world_settings) @working_dir = working_dir @world_path = world_settings.get_world_path_from_settings() @dk_proj_path = world_settings.get_world_project_path() end |
Instance Method Details
#dk_merge_and_remove(compose_hash, yml_hash) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/cl/magic/dk/yaml_arg_munger.rb', line 22 def dk_merge_and_remove(compose_hash, yml_hash) # remove help & merge clean_yml = yml_hash.clone clean_yml.delete('help') return compose_hash.dk_merge(clean_yml).dk_reject! { |k, v| v=='<dk-remove>' } end |
#get_base_compose_parts_and_make_hashes ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/cl/magic/dk/yaml_arg_munger.rb', line 11 def get_base_compose_parts_and_make_hashes() compose_hash = get_base_compose_hash() dk_parts_hash = {} dk_make_hash = {} compose_hash = merge_world_files(compose_hash, show_help=ARGV.include?("--help")) dk_parts_hash = compose_hash['x-dk-parts'] ? compose_hash.delete('x-dk-parts') : {} dk_make_hash = compose_hash['x-dk-make'] ? compose_hash.delete('x-dk-make') : {} return compose_hash, dk_parts_hash, dk_make_hash end |
#save_yaml_and_adjust_args(compose_hash, args) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cl/magic/dk/yaml_arg_munger.rb', line 29 def save_yaml_and_adjust_args(compose_hash, args) # generate final compose file tempfile = File.new(File.join(@working_dir, ".cl-dk.yml"), 'w') tempfile.write(compose_hash.to_yaml) # write it to the tempfile # remove existing '-f' flag, if needed file_flag_index = args.index('-f') if file_flag_index==0 args.delete_at(file_flag_index) args.delete_at(file_flag_index) end args.unshift('-f', tempfile.path) # add new '-f' flag tempfile.close return args end |