Class: Seam::Effort

Inherits:
Object
  • Object
show all
Defined in:
lib/seam/effort.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Effort

Returns a new instance of Effort.



41
42
43
44
45
46
# File 'lib/seam/effort.rb', line 41

def initialize(args = {})
  @completed_steps = []
  @history         = []
  @complete        = false
  args.each { |k, v| self.send "#{k}=".to_sym, v }
end

Instance Attribute Details

#completeObject

Returns the value of attribute complete.



5
6
7
# File 'lib/seam/effort.rb', line 5

def complete
  @complete
end

#completed_atObject

Returns the value of attribute completed_at.



6
7
8
# File 'lib/seam/effort.rb', line 6

def completed_at
  @completed_at
end

#completed_stepsObject

Returns the value of attribute completed_steps.



3
4
5
# File 'lib/seam/effort.rb', line 3

def completed_steps
  @completed_steps
end

#created_atObject

Returns the value of attribute created_at.



4
5
6
# File 'lib/seam/effort.rb', line 4

def created_at
  @created_at
end

#dataObject

Returns the value of attribute data.



11
12
13
# File 'lib/seam/effort.rb', line 11

def data
  @data
end

#flowObject

Returns the value of attribute flow.



10
11
12
# File 'lib/seam/effort.rb', line 10

def flow
  @flow
end

#historyObject

Returns the value of attribute history.



12
13
14
# File 'lib/seam/effort.rb', line 12

def history
  @history
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/seam/effort.rb', line 7

def id
  @id
end

#next_execute_atObject

Returns the value of attribute next_execute_at.



8
9
10
# File 'lib/seam/effort.rb', line 8

def next_execute_at
  @next_execute_at
end

#next_stepObject

Returns the value of attribute next_step.



9
10
11
# File 'lib/seam/effort.rb', line 9

def next_step
  @next_step
end

Class Method Details

.create(args) ⇒ Object



48
49
50
51
52
# File 'lib/seam/effort.rb', line 48

def self.create args
  effort = Seam::Effort.new args
  effort.save
  effort
end

.find(effort_id) ⇒ Object



16
17
18
# File 'lib/seam/effort.rb', line 16

def find effort_id
  Seam::Persistence.find_by_effort_id effort_id
end

.find_all_by_step(step) ⇒ Object



20
21
22
# File 'lib/seam/effort.rb', line 20

def find_all_by_step step
  Seam::Persistence.find_all_pending_executions_by_step step
end

.parse(document) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/seam/effort.rb', line 24

def parse document
  Effort.new( {
                id:              document['id'],
                created_at:      Time.parse(document['created_at'].to_s),
                next_execute_at: document['next_execute_at'],
                next_step:       document['next_step'],
                flow:            HashWithIndifferentAccess.new(document['flow']),
                data:            HashWithIndifferentAccess.new(document['data']),
                history:         document['history'].map { |x| HashWithIndifferentAccess.new x },
                completed_steps: document['completed_steps'],
                complete:        document['complete'],
                completed_at:    document['completed_at']
              } )
end

Instance Method Details

#cloneObject



82
83
84
# File 'lib/seam/effort.rb', line 82

def clone
  Seam::Effort.parse HashWithIndifferentAccess.new(self.to_hash)
end

#complete?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/seam/effort.rb', line 63

def complete?
  complete
end

#saveObject



54
55
56
57
58
59
60
61
# File 'lib/seam/effort.rb', line 54

def save
  existing_record = Seam::Effort.find self.id
  if existing_record
    Seam::Persistence.save self
  else
    Seam::Persistence.create self
  end
end

#to_hashObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/seam/effort.rb', line 67

def to_hash
  {
    id:              self.id,
    created_at:      self.created_at,
    completed_steps: self.completed_steps,
    completed_at:    self.completed_at,
    next_execute_at: self.next_execute_at,
    next_step:       self.next_step,
    flow:            self.flow,
    data:            self.data,
    history:         self.history,
    complete:        self.complete,
  }
end