Class: GemfileLocker::FileEditor

Inherits:
Object
  • Object
show all
Defined in:
lib/gemfile_locker/file_editor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, processor) ⇒ FileEditor

Returns a new instance of FileEditor.



5
6
7
8
# File 'lib/gemfile_locker/file_editor.rb', line 5

def initialize(path, processor)
  @path = path
  @processor = processor
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/gemfile_locker/file_editor.rb', line 3

def path
  @path
end

#processorObject (readonly)

Returns the value of attribute processor.



3
4
5
# File 'lib/gemfile_locker/file_editor.rb', line 3

def processor
  @processor
end

Instance Method Details

#resultObject



18
19
20
# File 'lib/gemfile_locker/file_editor.rb', line 18

def result
  @result ||= processor.call(source)
end

#runObject



10
11
12
# File 'lib/gemfile_locker/file_editor.rb', line 10

def run
  write
end

#sourceObject



14
15
16
# File 'lib/gemfile_locker/file_editor.rb', line 14

def source
  @source ||= File.read(path)
end

#writeObject



22
23
24
# File 'lib/gemfile_locker/file_editor.rb', line 22

def write
  File.write(path, result)
end