class Guard::Guardfile::Generator
@see Guard::CLI
plugins’ templates into it.
This class is responsible for generating the Guardfile and adding Guard’
def _ui(*args)
def _ui(*args) UI.send(*args) end
def create_guardfile
- See: Guard::CLI#init -
def create_guardfile path = Pathname.new("Guardfile").expand_path if path.exist? _ui(:error, "Guardfile already exists at #{path}") abort end _ui(:info, "Writing new Guardfile to #{path}") FileUtils.cp(GUARDFILE_TEMPLATE, path.to_s) end
def initialize_all_templates
- See: Guard::CLI#init -
def initialize_all_templates 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) guardfile = Pathname.new("Guardfile") plugin_util = PluginUtil.new(plugin_name) # TODO: change to "valid?" method plugin_class = plugin_util.plugin_class(fail_gracefully: true) if plugin_class begin plugin_util.add_to_guardfile rescue Errno::ENOENT => error # TODO: refactor template = plugin_class.template(plugin_util.plugin_location) _ui(:error, "Found class #{plugin_class} but loading it's template"\ "failed: '#{template}'") _ui(:error, "Error is: #{error}") return end return end template_code = (HOME_TEMPLATES + plugin_name).read guardfile.binwrite(format("\n%s\n", template_code), open_args: ["a"]) _ui(:info, format(INFO_TEMPLATE_ADDED, plugin_name)) rescue Errno::ENOENT fail NoSuchPlugin, plugin_name.downcase end