Class: SourceMonitor::Setup::GemfileEditor

Inherits:
Object
  • Object
show all
Defined in:
lib/source_monitor/setup/gemfile_editor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: "Gemfile") ⇒ GemfileEditor

Returns a new instance of GemfileEditor.



10
11
12
# File 'lib/source_monitor/setup/gemfile_editor.rb', line 10

def initialize(path: "Gemfile")
  @path = Pathname.new(path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/source_monitor/setup/gemfile_editor.rb', line 8

def path
  @path
end

Instance Method Details

#ensure_entryObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/source_monitor/setup/gemfile_editor.rb', line 14

def ensure_entry
  return false unless path.exist?

  contents = path.read
  return false if contents.match?(/gem\s+['"]source_monitor['"]/)

  path.open("a") do |file|
    file.write(<<~RUBY)

      gem "source_monitor"
    RUBY
  end

  true
end