Class: LLMed::Application::Snapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/llmed/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(snapshot_file) ⇒ Snapshot

Returns a new instance of Snapshot.



84
85
86
87
# File 'lib/llmed/application.rb', line 84

def initialize(snapshot_file)
  @snapshot_file = snapshot_file
  @contexts = []
end

Instance Attribute Details

#snapshot_file ⇒ Object (readonly)

Returns the value of attribute snapshot_file.



82
83
84
# File 'lib/llmed/application.rb', line 82

def snapshot_file
  @snapshot_file
end

Instance Method Details

#diff(other_contexts) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/llmed/application.rb', line 99

def diff(other_contexts)
  diffs = {}
  other_contexts.each do |other_ctx|
    current_ctx = @contexts[other_ctx.name]
    result = if current_ctx.nil?
               other_ctx.raw.split("\n").map { |line| ["+:", line] }
             else
               line_diff(current_ctx['message'], other_ctx.raw)
             end
    if !result.all? { |op, line| op == '=:' }
      diffs[other_ctx.name] = result
    end
  end

  diffs
end

#refresh(contexts) ⇒ Object



94
95
96
97
# File 'lib/llmed/application.rb', line 94

def refresh(contexts)
  @contexts = contexts.map { |ctx| [ctx.name, { 'name' => ctx.name, 'message' => ctx.raw }] }.to_h
  dump
end

#sync(default) ⇒ Object



89
90
91
92
# File 'lib/llmed/application.rb', line 89

def sync(default)
  load(default)
  dump
end