Class: Siding::Staleness::Events

Inherits:
Object
  • Object
show all
Defined in:
lib/siding/staleness.rb

Defined Under Namespace

Classes: Event

Constant Summary collapse

LIMIT =
50
COMPACT_AT =

When the file is rewritten rather than appended to. Rewriting on every record would turn a short append into a full read-modify-write for no benefit.

LIMIT * 4

Instance Method Summary collapse

Constructor Details

#initialize(limit: LIMIT, path: nil) ⇒ Events

Returns a new instance of Events.



135
136
137
138
139
140
# File 'lib/siding/staleness.rb', line 135

def initialize(limit: LIMIT, path: nil)
  @limit = limit
  @path = path
  @events = load_recorded
  @mutex = Mutex.new
end

Instance Method Details

#lastObject



156
# File 'lib/siding/staleness.rb', line 156

def last = @mutex.synchronize { @events.last }

#record(verdict, resolution: nil, developer_wait: nil, at: Time.now) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/siding/staleness.rb', line 142

def record(verdict, resolution: nil, developer_wait: nil, at: Time.now)
  event = Event.new(at: at, reason: verdict.reasons.first,
                    trigger_paths: verdict.trigger_paths,
                    resolution: resolution || verdict.resolution,
                    developer_wait: developer_wait)
  @mutex.synchronize do
    @events << event
    @events.shift while @events.size > @limit
  end
  persist(event)
  event
end

#sizeObject



157
# File 'lib/siding/staleness.rb', line 157

def size = @mutex.synchronize { @events.size }

#to_aObject



155
# File 'lib/siding/staleness.rb', line 155

def to_a = @mutex.synchronize { @events.dup }