seam 0.0.6 → 0.0.7

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/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .DS_Store
data/lib/seam.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'active_support/all'
2
2
  require 'active_support/time'
3
3
  require 'securerandom'
4
- require 'moped'
5
4
  require 'json'
6
5
  Dir[File.dirname(__FILE__) + '/seam/*.rb'].each {|file| require file }
7
6
 
data/lib/seam/effort.rb CHANGED
@@ -3,6 +3,7 @@ module Seam
3
3
  attr_accessor :completed_steps
4
4
  attr_accessor :created_at
5
5
  attr_accessor :complete
6
+ attr_accessor :completed_at
6
7
  attr_accessor :id
7
8
  attr_accessor :next_execute_at
8
9
  attr_accessor :next_step
@@ -31,6 +32,7 @@ module Seam
31
32
  effort.history = document['history'].map { |x| HashWithIndifferentAccess.new x }
32
33
  effort.completed_steps = document['completed_steps']
33
34
  effort.complete = document['complete']
35
+ effort.completed_at = document['completed_at']
34
36
  effort
35
37
  end
36
38
 
@@ -60,6 +62,7 @@ module Seam
60
62
  id: self.id,
61
63
  created_at: self.created_at,
62
64
  completed_steps: self.completed_steps,
65
+ completed_at: self.completed_at,
63
66
  next_execute_at: self.next_execute_at,
64
67
  next_step: self.next_step,
65
68
  flow: self.flow,
@@ -68,5 +71,9 @@ module Seam
68
71
  complete: self.complete,
69
72
  }
70
73
  end
74
+
75
+ def clone
76
+ Seam::Effort.parse HashWithIndifferentAccess.new(self.to_hash)
77
+ end
71
78
  end
72
79
  end
@@ -0,0 +1,13 @@
1
+ module Seam
2
+ module InMemory
3
+ class << self
4
+ def records
5
+ @records ||= []
6
+ end
7
+
8
+ def records=(records)
9
+ @records = records
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,24 +1,44 @@
1
1
  module Seam
2
2
  module Persistence
3
3
  def self.find_by_effort_id effort_id
4
- document = Seam::MongoDb.collection.find( { id: effort_id } ).first
5
- return nil unless document
6
- Seam::Effort.parse document
4
+ effort = Seam::InMemory.records.select { |x| x.id == effort_id }.first
5
+ return nil unless effort
6
+ effort.clone
7
+ #document = Seam::MongoDb.collection.find( { id: effort_id } ).first
8
+ #return nil unless document
9
+ #Seam::Effort.parse document
7
10
  end
8
11
 
9
12
  def self.find_all_pending_executions_by_step step
10
- Seam::MongoDb.collection
11
- .find( { next_step: step, next_execute_at: { '$lte' => Time.now } } )
12
- .map { |x| Seam::Effort.parse x }
13
+ Seam::InMemory.records
14
+ .select { |x| x.next_step == step && x.next_execute_at <= Time.now }
15
+ .map { |x| x.clone }
16
+ #Seam::MongoDb.collection
17
+ #.find( { next_step: step, next_execute_at: { '$lte' => Time.now } } )
18
+ #.map { |x| Seam::Effort.parse x }
13
19
  end
14
20
 
15
21
  def self.save effort
16
- Seam::MongoDb.collection.find( { id: effort.id } )
17
- .update("$set" => effort.to_hash)
22
+ old_record = find_by_effort_id effort.id
23
+ if old_record
24
+ Seam::InMemory.records = Seam::InMemory.records.select { |x| x.id != effort.id }.to_a
25
+ end
26
+ create effort
27
+ #Seam::MongoDb.collection.find( { id: effort.id } )
28
+ # .update("$set" => effort.to_hash)
18
29
  end
19
30
 
20
31
  def self.create effort
21
- Seam::MongoDb.collection.insert(effort.to_hash)
32
+ Seam::InMemory.records = [Seam::InMemory.records, effort].flatten
33
+ #Seam::MongoDb.collection.insert(effort.to_hash)
34
+ end
35
+
36
+ def self.all
37
+ Seam::InMemory.records.to_a
38
+ end
39
+
40
+ def self.destroy
41
+ Seam::InMemory.records = []
22
42
  end
23
43
  end
24
44
  end
data/lib/seam/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Seam
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/seam/worker.rb CHANGED
@@ -34,8 +34,9 @@ module Seam
34
34
 
35
35
  def eject
36
36
  history[:result] = "eject"
37
- effort.complete = true
38
- effort.next_step = nil
37
+ effort.complete = true
38
+ effort.completed_at = Time.now
39
+ effort.next_step = nil
39
40
  effort.save
40
41
  end
41
42
 
data/seam.gemspec CHANGED
@@ -21,7 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_runtime_dependency "json"
22
22
  spec.add_runtime_dependency "activesupport", "~> 3.2"
23
23
  spec.add_runtime_dependency "i18n"
24
- spec.add_runtime_dependency "moped"
25
24
  spec.add_runtime_dependency "json"
26
25
  spec.add_development_dependency "bundler", "~> 1.3"
27
26
  spec.add_development_dependency "rake"
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe Seam::Effort do
4
4
  before do
5
- test_moped_session['efforts'].drop
5
+ Seam::Persistence.destroy
6
6
  end
7
7
 
8
8
  let(:flow) do
@@ -15,14 +15,14 @@ describe Seam::Effort do
15
15
  describe "updating an effort" do
16
16
  it "should not create another document in the collection" do
17
17
  first_effort = flow.start
18
- test_moped_session['efforts'].find.count.must_equal 1
18
+ Seam::Persistence.all.count.must_equal 1
19
19
  first_effort.save
20
- test_moped_session['efforts'].find.count.must_equal 1
20
+ Seam::Persistence.all.count.must_equal 1
21
21
 
22
22
  second_effort = flow.start
23
- test_moped_session['efforts'].find.count.must_equal 2
23
+ Seam::Persistence.all.count.must_equal 2
24
24
  second_effort.save
25
- test_moped_session['efforts'].find.count.must_equal 2
25
+ Seam::Persistence.all.count.must_equal 2
26
26
  end
27
27
 
28
28
  it "should update the information" do
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe "flow" do
4
4
  before do
5
- test_moped_session['efforts'].drop
5
+ Seam::Persistence.destroy
6
6
  end
7
7
 
8
8
  after do
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  describe "worker" do
4
4
 
5
5
  before do
6
- test_moped_session['efforts'].drop
6
+ Seam::Persistence.destroy
7
7
  end
8
8
 
9
9
  after do
@@ -271,6 +271,7 @@ describe "worker" do
271
271
  effort.data['hit 3'].must_equal 1
272
272
 
273
273
  effort.complete?.must_equal true
274
+ #effort.completed_at.must_equal Time.now
274
275
 
275
276
  # FUTURE WAVES
276
277
  send_postcard_if_necessary_worker.execute_all
data/spec/spec_helper.rb CHANGED
@@ -6,10 +6,3 @@ require 'subtle'
6
6
  require 'timecop'
7
7
  require 'contrast'
8
8
  require 'mocha/setup'
9
-
10
- def test_moped_session
11
- session = Moped::Session.new([ "127.0.0.1:27017" ])
12
- session.use "seam_test"
13
- end
14
-
15
- Seam::MongoDb.set_collection test_moped_session['efforts']
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.6
4
+ version: 0.0.7
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-07 00:00:00.000000000 Z
12
+ date: 2013-08-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -59,22 +59,6 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: moped
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :runtime
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
62
  - !ruby/object:Gem::Dependency
79
63
  name: json
80
64
  requirement: !ruby/object:Gem::Requirement
@@ -218,7 +202,7 @@ files:
218
202
  - lib/seam.rb
219
203
  - lib/seam/effort.rb
220
204
  - lib/seam/flow.rb
221
- - lib/seam/mongo_db.rb
205
+ - lib/seam/in_memory.rb
222
206
  - lib/seam/persistence.rb
223
207
  - lib/seam/step.rb
224
208
  - lib/seam/version.rb
@@ -243,7 +227,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
243
227
  version: '0'
244
228
  segments:
245
229
  - 0
246
- hash: 2124052534046503851
230
+ hash: -1708529221048095917
247
231
  required_rubygems_version: !ruby/object:Gem::Requirement
248
232
  none: false
249
233
  requirements:
@@ -252,10 +236,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
236
  version: '0'
253
237
  segments:
254
238
  - 0
255
- hash: 2124052534046503851
239
+ hash: -1708529221048095917
256
240
  requirements: []
257
241
  rubyforge_project:
258
- rubygems_version: 1.8.25
242
+ rubygems_version: 1.8.24
259
243
  signing_key:
260
244
  specification_version: 3
261
245
  summary: Simple workflows
data/lib/seam/mongo_db.rb DELETED
@@ -1,12 +0,0 @@
1
- module Seam
2
- module MongoDb
3
-
4
- def self.collection
5
- @collection
6
- end
7
-
8
- def self.set_collection collection
9
- @collection = collection
10
- end
11
- end
12
- end