Class: Foobara::Generators::ResqueConnectorGenerator::Generators::GemfileGenerator
- Inherits:
-
Foobara::Generators::ResqueConnectorGenerator
- Object
- Foobara::Generators::ResqueConnectorGenerator
- Foobara::Generators::ResqueConnectorGenerator::Generators::GemfileGenerator
- Defined in:
- foobara-resque-connector-generator-0.0.2/src/generators/gemfile_generator.rb
Overview
Kind of tricky… for the first time we will be loading an existing file in the working directory and modifying it.
Instance Method Summary collapse
- #applicable? ⇒ Boolean
- #gemfile_contents ⇒ Object
- #generate(_elements_to_generate) ⇒ Object
- #target_path ⇒ Object
- #template_path ⇒ Object
Instance Method Details
#applicable? ⇒ Boolean
8 9 10 |
# File 'foobara-resque-connector-generator-0.0.2/src/generators/gemfile_generator.rb', line 8 def applicable? gemfile_contents !~ /^\s*gem\s*["']foobara-resque-connector\b/ end |
#gemfile_contents ⇒ Object
34 35 36 |
# File 'foobara-resque-connector-generator-0.0.2/src/generators/gemfile_generator.rb', line 34 def gemfile_contents File.read(template_path) end |
#generate(_elements_to_generate) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'foobara-resque-connector-generator-0.0.2/src/generators/gemfile_generator.rb', line 20 def generate(_elements_to_generate) match = gemfile_contents.match(/^gem /) if match new_entry = 'gem "foobara-resque-connector", github: "foobara/resque-connector"' "#{match.pre_match}\n#{new_entry}\n#{match}#{match.post_match}" else # TODO: maybe print a warning and return the original Gemfile # :nocov: raise "Not sure how to inject resque_connector into the Gemfile" # :nocov: end end |
#target_path ⇒ Object
16 17 18 |
# File 'foobara-resque-connector-generator-0.0.2/src/generators/gemfile_generator.rb', line 16 def target_path "Gemfile" end |
#template_path ⇒ Object
12 13 14 |
# File 'foobara-resque-connector-generator-0.0.2/src/generators/gemfile_generator.rb', line 12 def template_path "Gemfile" end |