Class: Restforce::DB::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/restforce/db/tracker.rb

Overview

Restforce::DB::Tracker encapsulates a minimal API to track and configure synchronization runtimes. It allows Restforce::DB to persist a “last successful sync” timestamp.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Tracker

Public: Initialize a Restforce::DB::Tracker. Sets a last_run timestamp on Restforce::DB if the supplied tracking file already contains a stamp.

file_path - The Path to the tracking file.



16
17
18
19
20
21
22
23
24
# File 'lib/restforce/db/tracker.rb', line 16

def initialize(file_path)
  @file_path = file_path

  timestamp = File.open(@file_path, "a+") { |file| file.read }
  return if timestamp.empty?

  @last_run = Time.parse(timestamp)
  Restforce::DB.last_run = @last_run
end

Instance Attribute Details

#last_runObject (readonly)

Returns the value of attribute last_run.



10
11
12
# File 'lib/restforce/db/tracker.rb', line 10

def last_run
  @last_run
end

Instance Method Details

#track(time) ⇒ Object

Public: Persist the passed time in the tracker file.

time - A Time object.

Returns nothing.



31
32
33
34
# File 'lib/restforce/db/tracker.rb', line 31

def track(time)
  @last_run = time
  File.open(@file_path, "w") { |file| file.write(time.utc.iso8601) }
end