Class: Clickatell::Catcher::Rack::SharedArray

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/clickatell/catcher/rack/shared_array.rb

Instance Method Summary collapse

Constructor Details

#initializeSharedArray

Returns a new instance of SharedArray.



9
10
11
12
13
14
# File 'lib/clickatell/catcher/rack/shared_array.rb', line 9

def initialize
  @store = YAML::Store.new(store_patch)
  @store.transaction do |store|
    store[:data] ||= []
  end
end

Instance Method Details

#<<(item) ⇒ Object



34
35
36
37
38
39
# File 'lib/clickatell/catcher/rack/shared_array.rb', line 34

def <<(item)
  @store.transaction do |store|
    store[:data].unshift(item)
    store[:data].pop if store[:data].size > 25
  end
end

#clearObject



28
29
30
31
32
# File 'lib/clickatell/catcher/rack/shared_array.rb', line 28

def clear
  @store.transaction do |store|
    store[:data] = []
  end
end

#eachObject



41
42
43
44
45
46
# File 'lib/clickatell/catcher/rack/shared_array.rb', line 41

def each
  data = @store.transaction { @store[:data] }
  data.each do |item|
    yield(item)
  end
end

#sizeObject



48
49
50
# File 'lib/clickatell/catcher/rack/shared_array.rb', line 48

def size
  @store.transaction { @store[:data] }.size
end