Module: LeapSalesforce::Generators::Appenders

Includes:
LeapSalesforce::Generator
Defined in:
lib/leap_salesforce_ui/generator/appenders.rb

Overview

Used for appending content onto existing files (or adding if not already present)

Instance Method Summary collapse

Instance Method Details

#append(filename, template_path) ⇒ Object

Create content in a file, adding to an existing file if present



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/leap_salesforce_ui/generator/appenders.rb', line 12

def append(filename, template_path)
  verb = "Appending to"
  unless File.exist? filename
    FileUtils.touch filename
    verb = "Creating"
  end
  content = read_template template_path, binding, folder: __dir__
  if File.read(filename).include?(content)
    puts "File '#{filename}' already has expected content, skipping...".colorize :red
  else
    puts "\u2713 #{verb} #{filename}".colorize :green
    open(filename, "a") { |f| f.puts content }
  end
end