Class: Steep::Server::InlineSourceChangeDetector::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/server/inline_source_change_detector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Source

Returns a new instance of Source.



9
10
11
12
13
# File 'lib/steep/server/inline_source_change_detector.rb', line 9

def initialize(content)
  @content = content
  @changes = []
  update_fingerprint!
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.



6
7
8
# File 'lib/steep/server/inline_source_change_detector.rb', line 6

def changes
  @changes
end

#contentObject (readonly)

Returns the value of attribute content.



5
6
7
# File 'lib/steep/server/inline_source_change_detector.rb', line 5

def content
  @content
end

#last_fingerprintObject (readonly)

Returns the value of attribute last_fingerprint.



7
8
9
# File 'lib/steep/server/inline_source_change_detector.rb', line 7

def last_fingerprint
  @last_fingerprint
end

Instance Method Details

#<<(changes) ⇒ Object



15
16
17
# File 'lib/steep/server/inline_source_change_detector.rb', line 15

def <<(changes)
  @changes << changes
end

#clearObject



50
51
52
# File 'lib/steep/server/inline_source_change_detector.rb', line 50

def clear
  @changes.clear
end

#update_fingerprint!Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/steep/server/inline_source_change_detector.rb', line 38

def update_fingerprint!
  buffer = RBS::Buffer.new(name: Pathname("test.rb"), content: content)
  prism = Prism.parse(content)
  result = RBS::InlineParser.parse(buffer, prism)

  new_fingerprint = result.type_fingerprint

  (new_fingerprint != last_fingerprint).tap do
    @last_fingerprint = new_fingerprint
  end
end

#updated?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/steep/server/inline_source_change_detector.rb', line 19

def updated?
  if changes.empty?
    return false
  end

  updated_content = changes.inject(content) do |current_content, change|
    change.apply_to(current_content)
  end
  changes.clear

  if updated_content == content
    return false
  end

  @content = updated_content

  update_fingerprint!
end