Class: Foobara::Generators::RackConnectorGenerator::Generators::GemfileGenerator

Inherits:
Foobara::Generators::RackConnectorGenerator show all
Defined in:
foobara-rack-connector-generator-0.0.11/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

Instance Method Details

#generate(_elements_to_generate) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'src/generators/gemfile_generator.rb', line 17

def generate(_elements_to_generate)
  contents = File.read(template_path)

  match = contents.match(/^gem /)

  if match
    new_entry = [
      'gem "foobara-rack-connector"',
      'gem "rackup"',
      'gem "rerun"',
      'gem "puma"'
    ].join("\n")

    "#{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 rack_connector into the Gemfile"
    # :nocov:
  end
end

#target_path ⇒ Object



13
14
15
# File 'src/generators/gemfile_generator.rb', line 13

def target_path
  "Gemfile"
end

#template_path ⇒ Object



9
10
11
# File 'src/generators/gemfile_generator.rb', line 9

def template_path
  "Gemfile"
end