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.



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

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:



16
17
18
# File 'lib/solargraph/source/updater.rb', line 16

def changes
  @changes
end

#filenameString (readonly)

Returns:

  • (String)


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

def filename
  @filename
end

#versionInteger (readonly)

Returns:

  • (Integer)


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

def version
  @version
end

Instance Method Details

#repair(text) ⇒ String

Returns:

  • (String)


46
47
48
49
50
51
# File 'lib/solargraph/source/updater.rb', line 46

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

#write(text, nullable = false) ⇒ String

Parameters:

  • text (String)
  • nullable (Boolean) (defaults to: false)

Returns:

  • (String)


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/solargraph/source/updater.rb', line 33

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