Class: Smooth::Backends::File

Inherits:
Base
  • Object
show all
Defined in:
lib/smooth/backends/file.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#create, #destroy, #index, #maximum_updated_at, #query, #records, #show, #update

Constructor Details

#initialize(options = {}) ⇒ File

Returns a new instance of File.



17
18
19
20
21
22
23
24
# File 'lib/smooth/backends/file.rb', line 17

def initialize options={}
  super

  @data_directory       = options[:data_directory]
  restore if ::File.exists?(storage_path)

  setup_periodic_flushing
end

Class Attribute Details

.data_directoryObject

Returns the value of attribute data_directory.



6
7
8
# File 'lib/smooth/backends/file.rb', line 6

def data_directory
  @data_directory
end

.flush_thresholdObject

Returns the value of attribute flush_threshold.



6
7
8
# File 'lib/smooth/backends/file.rb', line 6

def flush_threshold
  @flush_threshold
end

Instance Attribute Details

#namespaceObject

Returns the value of attribute namespace.



14
15
16
# File 'lib/smooth/backends/file.rb', line 14

def namespace
  @namespace
end

#storageObject

Returns the value of attribute storage.



14
15
16
# File 'lib/smooth/backends/file.rb', line 14

def storage
  @storage
end

Instance Method Details

#killObject



36
37
38
# File 'lib/smooth/backends/file.rb', line 36

def kill
  @periodic_flusher && @periodic_flusher.kill
end

#setup_periodic_flushingObject



40
41
42
43
44
45
46
47
# File 'lib/smooth/backends/file.rb', line 40

def setup_periodic_flushing
  @periodic_flusher ||= Thread.new do
    while true
      flush
      sleep 20
    end
  end
end

#storage_pathObject



27
28
29
# File 'lib/smooth/backends/file.rb', line 27

def storage_path
  ::File.join(data_directory, "#{namespace}.json")
end

#urlObject



31
32
33
# File 'lib/smooth/backends/file.rb', line 31

def url
  "file://#{ storage_path }"
end