Class: Clickatell::Catcher::Rack::SharedArray
- Inherits:
-
Object
- Object
- Clickatell::Catcher::Rack::SharedArray
- Includes:
- Enumerable
- Defined in:
- lib/clickatell/catcher/rack/shared_array.rb
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #clear ⇒ Object
- #each ⇒ Object
-
#initialize ⇒ SharedArray
constructor
A new instance of SharedArray.
- #size ⇒ Object
Constructor Details
#initialize ⇒ SharedArray
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 |
#clear ⇒ Object
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 |
#each ⇒ Object
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 |
#size ⇒ Object
48 49 50 |
# File 'lib/clickatell/catcher/rack/shared_array.rb', line 48 def size @store.transaction { @store[:data] }.size end |