Class: Steep::Server::InlineSourceChangeDetector

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

Defined Under Namespace

Classes: Source

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInlineSourceChangeDetector

Returns a new instance of InlineSourceChangeDetector.



57
58
59
# File 'lib/steep/server/inline_source_change_detector.rb', line 57

def initialize
  @sources = {}
end

Instance Attribute Details

#sourcesObject (readonly)

Returns the value of attribute sources.



55
56
57
# File 'lib/steep/server/inline_source_change_detector.rb', line 55

def sources
  @sources
end

Instance Method Details

#accumulate_change(file_path, changes) ⇒ Object



75
76
77
78
79
# File 'lib/steep/server/inline_source_change_detector.rb', line 75

def accumulate_change(file_path, changes)
  changes.each do |change|
    sources.fetch(file_path) << change
  end
end

#add_source(path, content) ⇒ Object



61
62
63
64
# File 'lib/steep/server/inline_source_change_detector.rb', line 61

def add_source(path, content)
  sources.key?(path) and raise "Source already exists for #{path}"
  sources[path] = Source.new(content)
end

#has_source?(path) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/steep/server/inline_source_change_detector.rb', line 85

def has_source?(path)
  sources.key?(path)
end

#replace_source(path, content) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/steep/server/inline_source_change_detector.rb', line 66

def replace_source(path, content)
  source = sources.fetch(path)
  if source.content == content
    source.clear
  else
    source << Services::ContentChange.string(content)
  end
end

#resetObject



89
90
91
# File 'lib/steep/server/inline_source_change_detector.rb', line 89

def reset
  sources.each_value { _1.updated? }
end

#type_updated_paths(paths) ⇒ Object



81
82
83
# File 'lib/steep/server/inline_source_change_detector.rb', line 81

def type_updated_paths(paths)
  paths.select { sources[_1]&.updated? }.to_set
end