Class: Steep::Server::InlineSourceChangeDetector::Source
- Defined in:
- lib/steep/server/inline_source_change_detector.rb
Instance Attribute Summary collapse
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#last_fingerprint ⇒ Object
readonly
Returns the value of attribute last_fingerprint.
Instance Method Summary collapse
- #<<(changes) ⇒ Object
- #clear ⇒ Object
-
#initialize(content) ⇒ Source
constructor
A new instance of Source.
- #update_fingerprint! ⇒ Object
- #updated? ⇒ Boolean
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
#changes ⇒ Object (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 |
#content ⇒ Object (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_fingerprint ⇒ Object (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 |
#clear ⇒ Object
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
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 |