Class: PartsMerger
- Inherits:
-
Object
- Object
- PartsMerger
- Defined in:
- lib/cl/magic/dk/parts_merger.rb
Instance Method Summary collapse
- #get_saved_parts(dk_parts_hash) ⇒ Object
-
#initialize(working_dir, yaml_arg_munger, help_printer, logger) ⇒ PartsMerger
constructor
A new instance of PartsMerger.
- #merge_parts(compose_hash, dk_parts_hash, args) ⇒ Object
Constructor Details
#initialize(working_dir, yaml_arg_munger, help_printer, logger) ⇒ PartsMerger
Returns a new instance of PartsMerger.
6 7 8 9 10 11 |
# File 'lib/cl/magic/dk/parts_merger.rb', line 6 def initialize(working_dir, yaml_arg_munger, help_printer, logger) @working_dir = working_dir @yaml_arg_munger = yaml_arg_munger @help_printer = help_printer @logger = logger end |
Instance Method Details
#get_saved_parts(dk_parts_hash) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/cl/magic/dk/parts_merger.rb', line 45 def get_saved_parts(dk_parts_hash) # get saved parts cmd = "cd #{@working_dir} && cl dk parts list" out, err = TTY::Command.new(:printer => :null).run("#{cmd}") return out.split("\n") end |
#merge_parts(compose_hash, dk_parts_hash, args) ⇒ Object
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 |
# File 'lib/cl/magic/dk/parts_merger.rb', line 13 def merge_parts(compose_hash, dk_parts_hash, args) selected_part_keys = [] # merge: saved parts saved_part_keys = get_saved_parts(dk_parts_hash) saved_part_keys.each do |potential_part_key| dk_part = dk_parts_hash.fetch(potential_part_key, nil) # yml detail if dk_part compose_hash = print_and_merge_part(potential_part_key, dk_part, compose_hash) selected_part_keys << potential_part_key end end # merge: arg parts while true potential_part_key = args.first dk_part = dk_parts_hash.fetch(potential_part_key, nil) # yml detail if dk_part unless selected_part_keys.include?(potential_part_key) compose_hash = print_and_merge_part(potential_part_key, dk_part, compose_hash) selected_part_keys << potential_part_key end args.shift # remove part arg else break end end @logger.puts "" if $stdout.isatty # tailing line break return compose_hash, selected_part_keys, args end |