class Thor::Actions::CreateFile

:nodoc:
ERB, it gets the content from the user.
CreateFile is a subset of Template, which instead of rendering a file with

def force_on_collision?


Shows the file collision menu to the user and gets the result.
def force_on_collision?
  base.shell.file_collision(destination) { render }
end

def force_or_skip_or_conflict(force, skip, &block)


returns true, force it, otherwise skip.
skipped. If both are false, show the file_collision menu, if the menu
If force is true, run the action, otherwise check if it's not being
def force_or_skip_or_conflict(force, skip, &block)
  if force
    say_status :force, :yellow
    yield unless pretend?
  elsif skip
    say_status :skip, :yellow
  else
    say_status :conflict, :red
    force_or_skip_or_conflict(force_on_collision?, true, &block)
  end
end

def identical?


Boolean:: true if it is identical, false otherwise.
==== Returns

Checks if the content of the file at the destination is identical to the rendered result.
def identical?
  exists? && File.binread(destination) == render
end

def initialize(base, destination, data, config = {})

def initialize(base, destination, data, config = {})
  @data = data
  super(base, destination, config)
end

def invoke!

def invoke!
  invoke_with_conflict_check do
    require "fileutils"
    FileUtils.mkdir_p(File.dirname(destination))
    File.open(destination, "wb") { |f| f.write render }
  end
  given_destination
end

def on_conflict_behavior(&block)


Now on conflict we check if the file is identical or not.
def on_conflict_behavior(&block)
  if identical?
    say_status :identical, :blue
  else
    options = base.options.merge(config)
    force_or_skip_or_conflict(options[:force], options[:skip], &block)
  end
end

def render


Holds the content to be added to the file.
def render
  @render ||= if data.is_a?(Proc)
    data.call
  else
    data
  end
end