Module: Seam::Persistence

Defined in:
lib/seam/persistence.rb

Class Method Summary collapse

Class Method Details

.allObject



35
36
37
# File 'lib/seam/persistence.rb', line 35

def self.all
  Seam::InMemory.records.to_a
end

.create(effort) ⇒ Object



31
32
33
# File 'lib/seam/persistence.rb', line 31

def self.create effort
  Seam::InMemory.records = [Seam::InMemory.records, effort].flatten
end

.destroyObject



39
40
41
# File 'lib/seam/persistence.rb', line 39

def self.destroy
  Seam::InMemory.records = []
end

.find_all_pending_executions_by_step(step) ⇒ Object



9
10
11
12
13
# File 'lib/seam/persistence.rb', line 9

def self.find_all_pending_executions_by_step step
  Seam::InMemory.records
    .select { |x| x.next_step == step && x.next_execute_at <= Time.now }
    .map { |x| x.clone }
end

.find_by_effort_id(effort_id) ⇒ Object



3
4
5
6
7
# File 'lib/seam/persistence.rb', line 3

def self.find_by_effort_id effort_id
  effort = Seam::InMemory.records.select { |x| x.id == effort_id }.first
  return nil unless effort
  effort.clone
end

.find_something_to_doObject



15
16
17
18
19
20
21
# File 'lib/seam/persistence.rb', line 15

def self.find_something_to_do
  Seam::InMemory.records
    .select { |x| x.complete.nil? || x.complete == false }
    .select { |x| x.next_execute_at <= Time.now }
    .select { |x| x.next_step != nil }
    .map    { |x| x.clone }
end

.save(effort) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/seam/persistence.rb', line 23

def self.save effort
  old_record = find_by_effort_id effort.id
  if old_record
    Seam::InMemory.records = Seam::InMemory.records.select { |x| x.id != effort.id }.to_a
  end
  create effort
end