module ECSUtil::Helpers
Public Instance Methods
array_hash(data = {}, key_name = :key, value_name = :value)
click to toggle source
# File lib/ecsutil/helpers.rb, line 35 def array_hash(data = {}, key_name = :key, value_name = :value) data.to_a.map do |k,v| { key_name.to_sym => k, value_name.to_sym => v } end end
confirm(title = nil, required = "Y")
click to toggle source
# File lib/ecsutil/helpers.rb, line 13 def confirm(title = nil, required = "Y") title ||= "Are you sure?" print "#{title} (Y/N): " if STDIN.gets.strip != required puts "Aborted" exit 1 end end
json_file(data)
click to toggle source
# File lib/ecsutil/helpers.rb, line 28 def json_file(data) f = Tempfile.new f.write(JSON.pretty_generate(data)) f.flush f.path end
parse_env_data(data)
click to toggle source
# File lib/ecsutil/helpers.rb, line 44 def parse_env_data(data) data. split("\n"). map(&:strip). reject { |l| l.start_with?("#") || l.empty? }. map { |l| l.split("=", 2) }. to_h end
step_info(message, *params)
click to toggle source
# File lib/ecsutil/helpers.rb, line 8 def step_info(message, *params) message = sprintf(message, *params) if params.any? puts "----> #{message}" end
terminate(message)
click to toggle source
# File lib/ecsutil/helpers.rb, line 23 def terminate(message) puts message exit 1 end