Class: Consumer::Controls::PositionStore::File

Inherits:
Object
  • Object
show all
Includes:
PositionStore, Initializer
Defined in:
lib/consumer/controls/position_store/file.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(identifier: nil) ⇒ Object



10
11
12
13
14
# File 'lib/consumer/controls/position_store/file.rb', line 10

def self.build(identifier: nil)
  instance = new(identifier)
  instance.configure
  instance
end

Instance Method Details

#getObject



16
17
18
19
20
21
# File 'lib/consumer/controls/position_store/file.rb', line 16

def get
  return 0 unless ::File.exist?(path)

  text = ::File.read(path)
  text.to_i
end

#pathObject



27
28
29
30
31
32
33
34
35
# File 'lib/consumer/controls/position_store/file.rb', line 27

def path
  path = ::File.join('tmp', 'local_file_position_store')

  unless identifier.nil?
    path << "-#{identifier}"
  end

  path
end

#put(position) ⇒ Object



23
24
25
# File 'lib/consumer/controls/position_store/file.rb', line 23

def put(position)
  ::File.write(path, position)
end