seam 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/seam/effort.rb CHANGED
@@ -22,26 +22,33 @@ module Seam
22
22
  end
23
23
 
24
24
  def parse document
25
- effort = Effort.new
26
- effort.id = document['id']
27
- effort.created_at = Time.parse(document['created_at'].to_s)
28
- effort.next_execute_at = document['next_execute_at']
29
- effort.next_step = document['next_step']
30
- effort.flow = HashWithIndifferentAccess.new document['flow']
31
- effort.data = HashWithIndifferentAccess.new document['data']
32
- effort.history = document['history'].map { |x| HashWithIndifferentAccess.new x }
33
- effort.completed_steps = document['completed_steps']
34
- effort.complete = document['complete']
35
- effort.completed_at = document['completed_at']
36
- effort
25
+ Effort.new( {
26
+ id: document['id'],
27
+ created_at: Time.parse(document['created_at'].to_s),
28
+ next_execute_at: document['next_execute_at'],
29
+ next_step: document['next_step'],
30
+ flow: HashWithIndifferentAccess.new(document['flow']),
31
+ data: HashWithIndifferentAccess.new(document['data']),
32
+ history: document['history'].map { |x| HashWithIndifferentAccess.new x },
33
+ completed_steps: document['completed_steps'],
34
+ complete: document['complete'],
35
+ completed_at: document['completed_at']
36
+ } )
37
37
  end
38
38
 
39
39
  end
40
40
 
41
- def initialize
41
+ def initialize(args = {})
42
42
  @completed_steps = []
43
43
  @history = []
44
44
  @complete = false
45
+ args.each { |k, v| self.send "#{k}=".to_sym, v }
46
+ end
47
+
48
+ def self.create args
49
+ effort = Seam::Effort.new args
50
+ effort.save
51
+ effort
45
52
  end
46
53
 
47
54
  def save
data/lib/seam/flow.rb CHANGED
@@ -2,42 +2,37 @@ module Seam
2
2
  class Flow
3
3
 
4
4
  def initialize
5
- @steps = []
5
+ @steps = {}
6
6
  end
7
7
 
8
8
  def method_missing(meth, *args, &blk)
9
- @steps << [meth.to_s, args]
9
+ meth = meth.to_s
10
+ return false if @steps[meth]
11
+ @steps[meth] = args
12
+ true
10
13
  end
11
14
 
12
15
  def start(data = {})
13
- effort = Seam::Effort.new
14
- effort.id = SecureRandom.uuid.to_s
15
- effort.created_at = Time.parse(Time.now.to_s)
16
- effort.next_execute_at = Time.parse(Time.now.to_s)
17
- effort.next_step = self.steps.first.name.to_s
18
- effort.flow = ActiveSupport::HashWithIndifferentAccess.new self.to_hash
19
- effort.data = ActiveSupport::HashWithIndifferentAccess.new data
20
- effort.save
21
- effort
16
+ Seam::Effort.create( {
17
+ id: SecureRandom.uuid.to_s,
18
+ created_at: Time.parse(Time.now.to_s),
19
+ next_execute_at: Time.parse(Time.now.to_s),
20
+ next_step: self.steps.first.name.to_s,
21
+ flow: ActiveSupport::HashWithIndifferentAccess.new(self.to_hash),
22
+ data: ActiveSupport::HashWithIndifferentAccess.new(data)
23
+ } )
22
24
  end
23
25
 
24
26
  def to_hash
25
- {
26
- steps: self.steps.map { |x| x.to_hash }
27
- }
27
+ { steps: self.steps.map { |x| x.to_hash } }
28
28
  end
29
29
 
30
30
  def steps
31
- @steps.map do |x|
32
- step = Seam::Step.new
33
- step.name = x[0]
34
- step.type = "do"
35
- step.arguments = x[1]
36
- if step.name.index('branch_on')
37
- step.name += "_#{x[1][0]}"
38
- step.type = "branch"
39
- end
40
- step
31
+ @steps.each.map do |name, arguments|
32
+ Seam::Step.new( { name: name,
33
+ type: 'do',
34
+ arguments: arguments } )
35
+
41
36
  end
42
37
  end
43
38
  end
data/lib/seam/step.rb CHANGED
@@ -4,10 +4,14 @@ module Seam
4
4
  attr_accessor :type
5
5
  attr_accessor :arguments
6
6
 
7
+ def initialize(args = {})
8
+ args.each { |k, v| self.send "#{k}=".to_sym, v }
9
+ end
10
+
7
11
  def to_hash
8
12
  {
9
- name: name,
10
- type: type,
13
+ name: name,
14
+ type: type,
11
15
  arguments: HashWithIndifferentAccess.new(arguments || {})
12
16
  }
13
17
  end
data/lib/seam/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Seam
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -94,4 +94,24 @@ describe "flow" do
94
94
  end
95
95
  end
96
96
  end
97
+
98
+ describe "adding steps" do
99
+ describe "new steps" do
100
+ it "should return true" do
101
+ flow = Seam::Flow.new
102
+ flow.do_something.must_equal true
103
+ flow.do_something_else.must_equal true
104
+ end
105
+ end
106
+
107
+ describe "repeating steps" do
108
+ it "should only add the step once" do
109
+ flow = Seam::Flow.new
110
+ flow.do_something.must_equal true
111
+ flow.steps.count.must_equal 1
112
+ flow.do_something.must_equal false
113
+ flow.steps.count.must_equal 1
114
+ end
115
+ end
116
+ end
97
117
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-12 00:00:00.000000000 Z
12
+ date: 2013-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -227,7 +227,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
227
227
  version: '0'
228
228
  segments:
229
229
  - 0
230
- hash: -2272473425204476348
230
+ hash: -1805101925636728224
231
231
  required_rubygems_version: !ruby/object:Gem::Requirement
232
232
  none: false
233
233
  requirements:
@@ -236,10 +236,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
236
  version: '0'
237
237
  segments:
238
238
  - 0
239
- hash: -2272473425204476348
239
+ hash: -1805101925636728224
240
240
  requirements: []
241
241
  rubyforge_project:
242
- rubygems_version: 1.8.24
242
+ rubygems_version: 1.8.25
243
243
  signing_key:
244
244
  specification_version: 3
245
245
  summary: Simple workflows