Class: Guard::Guardfile::Generator
- Inherits:
-
Object
- Object
- Guard::Guardfile::Generator
- Defined in:
- lib/guard/guardfile/generator.rb
Overview
This class is responsible for generating the Guardfile and adding Guard' plugins' templates into it.
Defined Under Namespace
Classes: NoSuchPlugin
Instance Method Summary collapse
-
#create_guardfile ⇒ Object
Creates the initial Guardfile template when it does not already exist.
-
#initialize_all_templates ⇒ Object
Adds the templates of all installed Guard implementations to an existing Guardfile.
-
#initialize_template(plugin_name) ⇒ Object
Adds the Guardfile template of a Guard plugin to an existing Guardfile.
Instance Method Details
#create_guardfile ⇒ Object
Creates the initial Guardfile template when it does not already exist.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/guard/guardfile/generator.rb', line 58 def create_guardfile path = Pathname.new("Guardfile"). 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 |
#initialize_all_templates ⇒ Object
Adds the templates of all installed Guard implementations to an existing Guardfile.
101 102 103 |
# File 'lib/guard/guardfile/generator.rb', line 101 def initialize_all_templates PluginUtil.plugin_names.each { |g| initialize_template(g) } end |
#initialize_template(plugin_name) ⇒ Object
Adds the Guardfile template of a Guard plugin to an existing Guardfile.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/guard/guardfile/generator.rb', line 73 def initialize_template(plugin_name) guardfile = Pathname.new("Guardfile") plugin_util = PluginUtil.new(plugin_name) if plugin_util.valid? begin plugin_util.add_to_guardfile rescue Errno::ENOENT => e UI.error("Found class #{plugin_util.plugin_class} but loading its template failed.") UI.error("Error is: #{e}") return end return end template_code = (HOME_TEMPLATES + plugin_name).read guardfile.binwrite(format("\n%<template>s\n", template: template_code), open_args: ["a"]) UI.info(format(INFO_TEMPLATE_ADDED, plugin_name)) rescue Errno::ENOENT fail NoSuchPlugin, plugin_name.downcase end |