Class: Qspec::IPC::File

Inherits:
Qspec::IPC show all
Defined in:
lib/qspec/ipc/file.rb

Constant Summary collapse

DIRECTORY =
'tmp/qspec'

Instance Method Summary collapse

Methods inherited from Qspec::IPC

default, from_config

Constructor Details

#initializeFile

Returns a new instance of File.



8
9
10
# File 'lib/qspec/ipc/file.rb', line 8

def initialize
  FileUtils.mkdir_p(DIRECTORY) unless FileTest.exists?(DIRECTORY)
end

Instance Method Details

#del(key) ⇒ Object



12
13
14
# File 'lib/qspec/ipc/file.rb', line 12

def del(key)
  ::File.unlink(Qspec.path(key)) rescue nil
end

#llen(key) ⇒ Object



37
38
39
40
41
# File 'lib/qspec/ipc/file.rb', line 37

def llen(key)
  open(key, :r) do |f|
    safe_load(f).length
  end
end

#lpop(key) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/qspec/ipc/file.rb', line 16

def lpop(key)
  open(key, :rw) do |f|
    list = safe_load(f)
    f.truncate(0)
    f.rewind
    data = list.shift
    f.write(Marshal.dump(list))
    data
  end
end

#rpush(key, value) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/qspec/ipc/file.rb', line 27

def rpush(key, value)
  open(key, :rw) do |f|
    list = safe_load(f)
    f.truncate(0)
    f.rewind
    list.push(value)
    f.write(Marshal.dump(list))
  end
end