Class: SourceMonitor::Setup::GemfileEditor
- Inherits:
-
Object
- Object
- SourceMonitor::Setup::GemfileEditor
- Defined in:
- lib/source_monitor/setup/gemfile_editor.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #ensure_entry ⇒ Object
-
#initialize(path: "Gemfile") ⇒ GemfileEditor
constructor
A new instance of GemfileEditor.
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
#path ⇒ Object (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_entry ⇒ Object
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 |