Class: FluidFeatures::Persistence::Buckets

Inherits:
Storage
  • Object
show all
Defined in:
lib/fluidfeatures/persistence/buckets.rb

Instance Attribute Summary collapse

Attributes inherited from Storage

#dir, #file_name, #logger, #store

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Storage

#file_size, #path

Constructor Details

#initialize(config, logger = nil) ⇒ Buckets

Returns a new instance of Buckets.



11
12
13
14
# File 'lib/fluidfeatures/persistence/buckets.rb', line 11

def initialize(config, logger=nil)
  self.limit = config["limit"]
  super
end

Instance Attribute Details

#limitObject

Returns the value of attribute limit.



4
5
6
# File 'lib/fluidfeatures/persistence/buckets.rb', line 4

def limit
  @limit
end

Class Method Details

.create(config, logger = nil) ⇒ Object



6
7
8
9
# File 'lib/fluidfeatures/persistence/buckets.rb', line 6

def self.create(config, logger=nil)
  return NullBuckets.new unless config && config["dir"] && config["enable"] && config["limit"] > 0
  new(config, logger)
end

Instance Method Details

#append(buckets) ⇒ Object



27
28
29
30
31
# File 'lib/fluidfeatures/persistence/buckets.rb', line 27

def append(buckets)
  transaction do
    store["buckets"] += buckets
  end
end

#append_one(bucket) ⇒ Object



33
34
35
36
37
# File 'lib/fluidfeatures/persistence/buckets.rb', line 33

def append_one(bucket)
  transaction do
    store["buckets"].push(bucket)
  end
end

#empty?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
# File 'lib/fluidfeatures/persistence/buckets.rb', line 39

def empty?
  store.transaction(true) do
    return true unless store["buckets"]
    return store["buckets"].empty?
  end
end

#fetch(n = 1) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/fluidfeatures/persistence/buckets.rb', line 16

def fetch(n = 1)
  ret = []
  store.transaction do
    return [] unless store && store["buckets"] && !store["buckets"].empty?
    n = store["buckets"].size if n > store["buckets"].size
    ret = store["buckets"].slice!(0, n)
    store.commit
  end
  return ret
end