Class: Specwrk::PendingStore

Inherits:
Store
  • Object
show all
Defined in:
lib/specwrk/store/pending_store.rb

Constant Summary collapse

RUN_TIME_BUCKET_MAXIMUM_KEY =
:____run_time_bucket_maximum
MAX_RETRIES_KEY =
:____max_retries
BUCKET_IDS_KEY =
:____bucket_ids

Instance Method Summary collapse

Methods inherited from Store

#[], #[]=, adapter_klass, #any?, #delete, #empty?, #initialize, #inspect, #multi_read, #to_h, with_lock

Constructor Details

This class inherits a constructor from Specwrk::Store

Instance Method Details

#bucket_idsObject



40
41
42
# File 'lib/specwrk/store/pending_store.rb', line 40

def bucket_ids
  @bucket_ids ||= self[BUCKET_IDS_KEY] || []
end

#bucket_ids=(val) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/specwrk/store/pending_store.rb', line 30

def bucket_ids=(val)
  @bucket_ids = nil

  self[BUCKET_IDS_KEY] = if val.nil? || val.length.zero?
    nil
  else
    val
  end
end

#bucket_store_for(bucket_id) ⇒ Object



83
84
85
# File 'lib/specwrk/store/pending_store.rb', line 83

def bucket_store_for(bucket_id)
  BucketStore.new(uri.to_s, File.join(scope, "buckets", bucket_id))
end

#clearObject



54
55
56
57
58
59
# File 'lib/specwrk/store/pending_store.rb', line 54

def clear
  bucket_ids.each { |bucket_id| delete_bucket(bucket_id) }
  @bucket_ids = nil

  super
end

#delete_bucket(bucket_id) ⇒ Object



87
88
89
# File 'lib/specwrk/store/pending_store.rb', line 87

def delete_bucket(bucket_id)
  bucket_store_for(bucket_id).clear
end

#keysObject



91
92
93
# File 'lib/specwrk/store/pending_store.rb', line 91

def keys
  bucket_ids
end

#lengthObject



95
96
97
# File 'lib/specwrk/store/pending_store.rb', line 95

def length
  bucket_ids.length
end

#max_retriesObject



26
27
28
# File 'lib/specwrk/store/pending_store.rb', line 26

def max_retries
  @max_retries ||= self[MAX_RETRIES_KEY] || 0
end

#max_retries=(val) ⇒ Object



22
23
24
# File 'lib/specwrk/store/pending_store.rb', line 22

def max_retries=(val)
  @max_retries = self[MAX_RETRIES_KEY] = val
end

#merge!(hash) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/specwrk/store/pending_store.rb', line 44

def merge!(hash)
  return self if hash.nil? || hash.empty?

  buckets = grouped_examples(hash.values)
  new_bucket_ids = buckets.map { |examples| write_bucket(examples) }

  self.bucket_ids = bucket_ids + new_bucket_ids
  self
end

#push_examples(examples) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/specwrk/store/pending_store.rb', line 75

def push_examples(examples)
  return self if examples.nil? || examples.empty?

  new_bucket_id = write_bucket(examples)
  self.bucket_ids = bucket_ids + [new_bucket_id]
  self
end

#reloadObject



61
62
63
64
65
# File 'lib/specwrk/store/pending_store.rb', line 61

def reload
  @max_retries = nil
  @bucket_ids = nil
  super
end

#run_time_bucket_maximumObject



18
19
20
# File 'lib/specwrk/store/pending_store.rb', line 18

def run_time_bucket_maximum
  @run_time_bucket_maximum ||= self[RUN_TIME_BUCKET_MAXIMUM_KEY]
end

#run_time_bucket_maximum=(val) ⇒ Object



14
15
16
# File 'lib/specwrk/store/pending_store.rb', line 14

def run_time_bucket_maximum=(val)
  @run_time_bucket_maximum = self[RUN_TIME_BUCKET_MAXIMUM_KEY] = val
end

#shift_bucketObject



67
68
69
70
71
72
73
# File 'lib/specwrk/store/pending_store.rb', line 67

def shift_bucket
  return nil if bucket_ids.empty?

  bucket_id = bucket_ids.first
  self.bucket_ids = bucket_ids.drop(1)
  bucket_id
end