Class: Smooth::Backends::File
Class Attribute Summary collapse
-
.data_directory ⇒ Object
Returns the value of attribute data_directory.
-
.flush_threshold ⇒ Object
Returns the value of attribute flush_threshold.
Instance Attribute Summary collapse
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#storage ⇒ Object
Returns the value of attribute storage.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ File
constructor
A new instance of File.
- #kill ⇒ Object
- #setup_periodic_flushing ⇒ Object
- #storage_path ⇒ Object
- #url ⇒ Object
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 ={} super @data_directory = [:data_directory] restore if ::File.exists?(storage_path) setup_periodic_flushing end |
Class Attribute Details
.data_directory ⇒ Object
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_threshold ⇒ Object
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
#namespace ⇒ Object
Returns the value of attribute namespace.
14 15 16 |
# File 'lib/smooth/backends/file.rb', line 14 def namespace @namespace end |
#storage ⇒ Object
Returns the value of attribute storage.
14 15 16 |
# File 'lib/smooth/backends/file.rb', line 14 def storage @storage end |
Instance Method Details
#kill ⇒ Object
36 37 38 |
# File 'lib/smooth/backends/file.rb', line 36 def kill @periodic_flusher && @periodic_flusher.kill end |
#setup_periodic_flushing ⇒ Object
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_path ⇒ Object
27 28 29 |
# File 'lib/smooth/backends/file.rb', line 27 def storage_path ::File.join(data_directory, "#{namespace}.json") end |
#url ⇒ Object
31 32 33 |
# File 'lib/smooth/backends/file.rb', line 31 def url "file://#{ storage_path }" end |