Module: Chore::Store

Defined in:
lib/chore/store.rb

Overview

A semi-persistant store for all of our chore data. Right now it’s just a hash that won’t survive a server restart.

Class Method Summary collapse

Class Method Details

.expireObject

Remove anything that’s currently expired from the store.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/chore/store.rb', line 30

def self.expire
  expired_tasks = []
  
  Chore::Store.get.each_pair do |task, params|
    if params['expire_in']
      start_time = params['start_time'].to_i
      expire_in = params['expire_in'].to_i
      expire_time = start_time + expire_in
      
      if expire_time < Time.now().to_i
        expired_tasks << task
      end
    end
  end

  expired_tasks.each do |task|
    Chore::Store.get.delete(task)
  end
end

.get_chore(chore_name) ⇒ Object

get status of a single chore



51
52
53
54
55
56
57
58
# File 'lib/chore/store.rb', line 51

def self.get_chore chore_name
  chore_name = chore_name.to_s
  chore_data = Store.get[chore_name]

  return nil if chore_data.nil?
  
  build_status(chore_name, chore_data)
end

.iterate_statusesObject

Climb through the internal store and return a processed and abstracted list of tasks to the consumer.



62
63
64
65
66
67
# File 'lib/chore/store.rb', line 62

def self.iterate_statuses
  ret = []
  Store.get.keys.each do |chore_name|
    yield get_chore(chore_name)
  end
end

.update_chore(chore_info) ⇒ Object

Process data with a spawned process in the background



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/chore/store.rb', line 12

def self.update_chore chore_info
  state = chore_info[0]
  chore = chore_info[1]
  opts = chore_info[2]
  opts['status'] = state
  
  if state == "pop"
    Store.get.delete(chore)
  else
    if Store.get[chore].nil?
      Store.get[chore] = {}
    end

    Store.get[chore] = Store.get[chore].merge(opts)
  end
end