Class: Solargraph::Source::Updater

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/source/updater.rb

Overview

Updaters contain changes to be applied to a source. The source applies the update via the Source#synchronize method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, version, changes) ⇒ Updater

Returns a new instance of Updater

Parameters:

  • filename (String)

    The file to update.

  • version (Integer)

    A version number associated with this update.

  • changes (Array<Solargraph::Source::Change>)

    The changes.


19
20
21
22
23
24
25
26
# File 'lib/solargraph/source/updater.rb', line 19

def initialize filename, version, changes
  @filename = filename
  @version = version
  @changes = changes
  @input = nil
  @did_nullify = nil
  @output = nil
end

Instance Attribute Details

#changesArray<Change> (readonly)

Returns:


14
15
16
# File 'lib/solargraph/source/updater.rb', line 14

def changes
  @changes
end

#filenameString (readonly)

Returns:

  • (String)

8
9
10
# File 'lib/solargraph/source/updater.rb', line 8

def filename
  @filename
end

#versionInteger (readonly)

Returns:

  • (Integer)

11
12
13
# File 'lib/solargraph/source/updater.rb', line 11

def version
  @version
end

Instance Method Details

#repair(text) ⇒ String

Returns:

  • (String)

42
43
44
45
46
47
# File 'lib/solargraph/source/updater.rb', line 42

def repair text
  changes.each do |ch|
    text = ch.repair(text)
  end
  text
end

#write(text, nullable = false) ⇒ String

Returns:

  • (String)

29
30
31
32
33
34
35
36
37
38
39
# File 'lib/solargraph/source/updater.rb', line 29

def write text, nullable = false
  can_nullify = (nullable and changes.length == 1)
  return @output if @input == text and can_nullify == @did_nullify
  @input = text
  @output = text
  @did_nullify = can_nullify
  changes.each do |ch|
    @output = ch.write(@output, can_nullify)
  end
  @output
end