class Guard::Guardfile::Generator
@see Guard::CLI
plugins’ templates into it.
This class is responsible for generating the Guardfile and adding Guard’
def create_guardfile
- See: Guard::CLI#init -
def create_guardfile if !File.exist?('Guardfile') ::Guard::UI.info "Writing new Guardfile to #{ Dir.pwd }/Guardfile" FileUtils.cp(GUARDFILE_TEMPLATE, 'Guardfile') elsif options[:abort_on_existence] ::Guard::UI.error "Guardfile already exists at #{ Dir.pwd }/Guardfile" abort end end
def initialize(options = {})
(**options)
-
:abort_on_existence
(Boolean
) -- Whether to abort or not
Parameters:
-
options
(Hash
) -- The options for creating a Guardfile
def initialize(options = {}) @options = options end
def initialize_all_templates
- See: Guard::CLI#init -
def initialize_all_templates ::Guard::PluginUtil.plugin_names.each { |g| initialize_template(g) } end
def initialize_template(plugin_name)
-
plugin_name
(String
) -- the name of the Guard plugin or template to
Other tags:
- See: Guard::CLI#init -
def initialize_template(plugin_name) plugin_util = ::Guard::PluginUtil.new(plugin_name) if plugin_util.plugin_class(fail_gracefully: true) plugin_util.add_to_guardfile @options[:guardfile] = File.read('Guardfile') if File.exists?('Guardfile') elsif File.exist?(File.join(HOME_TEMPLATES, plugin_name)) content = File.read('Guardfile') File.open('Guardfile', 'wb') do |f| f.puts(content) f.puts('') f.puts(File.read(File.join(HOME_TEMPLATES, plugin_name))) end ::Guard::UI.info "#{ plugin_name } template added to Guardfile, feel free to edit it" else const_name = plugin_name.downcase.gsub('-', '') UI.error "Could not load 'guard/#{ plugin_name.downcase }' or '~/.guard/templates/#{ plugin_name.downcase }' or find class Guard::#{ const_name.capitalize }" end end