Module: Rails::Generators::Hyperdrive::GitignoreSupport
- Included in:
- DiscoverGenerator, InstallGenerator
- Defined in:
- lib/generators/hyperdrive/gitignore_support.rb
Overview
Included as a module so its methods are not registered as Thor commands — Thor's method_added hook fires only for methods defined directly on the generator class.
Constant Summary collapse
- GITIGNORE =
".gitignore".freeze
Instance Method Summary collapse
-
#ensure_gitignored(rule) ⇒ Object
The rule must name a specific file, never a directory — the lockfile in the same directory stays tracked.
Instance Method Details
#ensure_gitignored(rule) ⇒ Object
The rule must name a specific file, never a directory — the lockfile in the same directory stays tracked.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/generators/hyperdrive/gitignore_support.rb', line 12 def ensure_gitignored(rule) abs = ::Rails.root.join(GITIGNORE) unless File.exist?(abs) create_file GITIGNORE, "#{rule}\n" return end body = File.read(abs) return if body.split("\n").any? { |line| line.strip == rule } prefix = body.end_with?("\n") || body.empty? ? "" : "\n" append_to_file GITIGNORE, "#{prefix}#{rule}\n" end |