Class: LogTail::FileStateStore

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

Overview

This is the default implementation of StateStore, which stores the state in a file ( by default in /tmp with a static name although this is configurable).

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#path_to_fileObject

Provides the path to the file that is used to store the state ( unless a custom StateStore is used).



70
71
72
# File 'lib/apache_log_tail.rb', line 70

def path_to_file
  @path_to_file ||= "/tmp/.apache_log_tail-state.yml"
end

Instance Method Details

#recallHash

Retrieves the state from the store.

Returns:

  • (Hash)


80
81
82
83
84
85
86
# File 'lib/apache_log_tail.rb', line 80

def recall
  if not File.exists? path_to_file
    {}
  else
    YAML.load File.read( path_to_file)
  end
end

#remember(state) ⇒ Object

Stores the supplied state.

Parameters:

  • state (Hash)


91
92
93
94
95
# File 'lib/apache_log_tail.rb', line 91

def remember state
  File.open  path_to_file, "w" do |file|
    file.write  state.to_yaml
  end
end