How to use puts_info method of Copyable Package

Best Howitzer_ruby code snippet using Copyable.puts_info


Source:base_generator.rb Github


Full Screen

...26 end27 def print_info(data)28 logger.print " #{data}"29 end30 def puts_info(data)31 logger.puts " #{data}"32 end33 def puts_error(data)34 logger.puts " ERROR: #{data}"35 end36 end37 # This module combines methods for copying files and templates38 module Copyable39 def self.included(base)40 class << base41 attr_accessor :destination42 end43 end44 def initialize(_options)45 super()46 manifest.each do |type, list|47 case type48 when :files49 copy_files(list)50 when :templates51 copy_templates(list)52 else nil53 end54 end55 end56 def manifest; end57 protected58 def copy_files(list)59 list.each do |data|60 source_file = source_path(data[:source])61 File.exist?(source_file) ? copy_with_path(data) : puts_error("File '#{source_file}' was not found.")62 end63 end64 def copy_templates(list)65 list.each do |data|66 destination_path = dest_path(data[:destination])67 source_path = source_path(data[:source])68 if File.exist?(destination_path)69 copy_templates_file_exist(data, destination_path, source_path)70 else71 write_template(destination_path, source_path)72 puts_info "Added template '#{data[:source]}' with params '#{@options}' to destination '#{data[:destination]}'"73 end74 end75 end76 def source_path(file_name)77 base_name ='Generator', '').sub('Howitzer::', '').downcase78 File.expand_path(file_name, File.join(File.dirname(__FILE__), base_name, 'templates'))79 end80 def dest_path(path)81 File.expand_path(File.join(destination, path))82 end83 def copy_with_path(data)84 src = source_path(data[:source])85 dst = dest_path(data[:destination])86 FileUtils.mkdir_p(File.dirname(dst))87 if File.exist?(dst)88 copy_with_path_file_exist(data, src, dst)89 else90 FileUtils.cp(src, dst)91 puts_info("Added '#{data[:destination]}' file")92 end93 rescue => e94 puts_error("Impossible to create '#{data[:destination]}' file. Reason: #{e.message}")95 end96 def write_template(dest_path, source_path)97, 'w+') do |f|98 f.write(, 'r').read).result( { binding }))99 end100 end101 private102 def copy_templates_file_exist(data, destination_path, source_path)103 puts_info("Conflict with '#{data[:destination]}' template")104 print_info(" Overwrite '#{data[:destination]}' template? [Yn]:")105 copy_templates_overwrite(gets.strip.downcase, data, destination_path, source_path)106 end107 def copy_with_path_file_exist(data, source, destination)108 if FileUtils.identical?(source, destination)109 puts_info("Identical '#{data[:destination]}' file")110 else111 puts_info("Conflict with '#{data[:destination]}' file")112 print_info(" Overwrite '#{data[:destination]}' file? [Yn]:")113 copy_with_path_overwrite(gets.strip.downcase, data, source, destination)114 end115 end116 def copy_templates_overwrite(answer, data, destination_path, source_path)117 case answer118 when 'y'119 write_template(destination_path, source_path)120 puts_info(" Forced '#{data[:destination]}' template")121 when 'n'122 puts_info(" Skipped '#{data[:destination]}' template")123 else nil124 end125 end126 def copy_with_path_overwrite(answer, data, source, destination)127 case answer128 when 'y'129 FileUtils.cp(source, destination)130 puts_info(" Forced '#{data[:destination]}' file")131 when 'n' then132 puts_info(" Skipped '#{data[:destination]}' file")133 else nil134 end135 end136 end137 # Parent class for all generators138 class BaseGenerator139 attr_reader :options140 include Outputable141 include Copyable142 def initialize(options)143 @options = options.symbolize_keys144 super145 end146 end...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?