libis-workflow-mongoid 2.0.beta.14 → 2.0.beta.15

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab26385c0cb9336c38cbfdb6e3443eac39ed0e81
4
- data.tar.gz: 78fafdcac7388b0d26cc4c52a0891a31fe564fdc
3
+ metadata.gz: 257d09f473547c6a373ff1040d3ab93bd2a3c7f0
4
+ data.tar.gz: 57a636a4ecb6dd41c817b95ecc8b9d41df58d437
5
5
  SHA512:
6
- metadata.gz: 45571956f037710ef97cba6c63526ff1363083f4d6bed937c3f668809c255fe09a3e18f6f5f05c6b452a1d907d924892d5b188f404acdebff498dd588bddc04a
7
- data.tar.gz: 7ba8ca07a056b4997637091cba2fbb3d5bd0aaad8cec9ad3f15eeafd48d55380d8ebe193ea43ea34be408b943dade48c67b66b7b4b2230b3ebb6329bf7812fb8
6
+ metadata.gz: 68011bc0fe042fff0434fabbae544e3a0b0f8177e0f67c6230458fc46847d9d2c8b99acaaeecdafa279d2981c87a83a000eadbcdf04f1b0db3a3126ca3ee74ea
7
+ data.tar.gz: fb282a3b8f7cc371b6e338664541acc19353b575b753479ef3df05b019081841660fb6c7971612a7d55c92543cce180f16e5a51f872eb8145799e56d43db14d9
@@ -7,41 +7,31 @@ module Libis
7
7
  module Workflow
8
8
  module Mongoid
9
9
 
10
- module Job
10
+ class Job
11
11
 
12
- def self.included(klass)
13
- klass.class_eval do
14
- include ::Libis::Workflow::Base::Job
15
- include ::Libis::Workflow::Mongoid::Base
12
+ include ::Libis::Workflow::Base::Job
13
+ include ::Libis::Workflow::Mongoid::Base
16
14
 
17
- store_in collection: 'workflow_jobs'
15
+ store_in collection: 'workflow_jobs'
18
16
 
19
- field :name, type: String
20
- field :description, type: String
21
- field :input, type: Hash, default: -> { Hash.new }
22
- field :run_object, type: String
17
+ field :name, type: String
18
+ field :description, type: String
19
+ field :input, type: Hash, default: -> { Hash.new }
20
+ field :run_object, type: String
23
21
 
24
- index({name: 1}, {unique: 1})
22
+ index({name: 1}, {unique: 1})
25
23
 
26
- def klass.run_class(run_klass)
27
- has_many :runs, inverse_of: :job, class_name: run_klass.to_s,
28
- dependent: :destroy, autosave: true, order: :c_at.asc
29
- end
24
+ has_many :runs, as: :job, dependent: :destroy, autosave: true, order: :c_at.asc
30
25
 
31
- def klass.workflow_class(workflow_klass)
32
- belongs_to :workflow, inverse_of: :jobs, class_name: workflow_klass.to_s
33
- end
26
+ belongs_to :workflow, polymorphic: true
34
27
 
35
- # def create_run_object
36
- # # noinspection RubyResolve
37
- # self.runs.build
38
- # end
39
-
40
- end
41
-
42
- end
28
+ # def create_run_object
29
+ # # noinspection RubyResolve
30
+ # self.runs.build
31
+ # end
43
32
 
44
33
  end
34
+
45
35
  end
46
36
  end
47
37
  end
@@ -8,36 +8,24 @@ module Libis
8
8
  module Workflow
9
9
  module Mongoid
10
10
 
11
- module Run
12
- # extend ActiveSupport::Concern
11
+ class Run
13
12
 
14
- def self.included(klass)
15
- klass.class_eval do
16
- include ::Libis::Workflow::Base::Run
17
- include ::Libis::Workflow::Mongoid::WorkItemBase
13
+ include ::Libis::Workflow::Base::Run
14
+ include ::Libis::Workflow::Mongoid::WorkItemBase
15
+ # extend ActiveSupport::Concern
18
16
 
19
- store_in collection: 'workflow_runs'
17
+ store_in collection: 'workflow_runs'
20
18
 
21
- field :start_date, type: Time, default: -> { Time.now }
19
+ field :start_date, type: Time, default: -> { Time.now }
22
20
 
23
- set_callback(:destroy, :before) do |document|
24
- document.items.each { |item| item.destroy }
25
- wd = document.work_dir
26
- FileUtils.rmtree wd if wd && !wd.blank? && Dir.exist?(wd)
27
- end
21
+ set_callback(:destroy, :before) do |document|
22
+ wd = document.work_dir
23
+ FileUtils.rmtree wd if wd && !wd.blank? && Dir.exist?(wd)
24
+ end
28
25
 
29
- index start_date: 1
26
+ index start_date: 1
30
27
 
31
- def klass.job_class(job_klass)
32
- belongs_to :job, inverse_of: :runs, class_name: job_klass.to_s
33
- end
34
-
35
- def klass.item_class(item_klass)
36
- has_many :items, inverse_of: :run, class_name: item_klass.to_s,
37
- dependent: :destroy, autosave: true, order: :c_at.asc
38
- end
39
- end
40
- end
28
+ belongs_to :job, polymorphic: true
41
29
 
42
30
  def run
43
31
  self.tasks = []
@@ -46,25 +34,6 @@ module Libis
46
34
  super
47
35
  end
48
36
 
49
- # Add a child work item
50
- #
51
- # @param [Libis::Workflow::Mongoid::WorkItem] item to be added to the child list :items
52
- def add_item(item)
53
- # noinspection RubyResolve
54
- item.run = self
55
- super
56
- end
57
-
58
- alias_method :<<, :add_item
59
-
60
- def parent
61
- nil
62
- end
63
-
64
- def parent=(_)
65
- nil
66
- end
67
-
68
37
  end
69
38
 
70
39
  end
@@ -3,7 +3,7 @@
3
3
  module Libis
4
4
  module Workflow
5
5
  module Mongoid
6
- VERSION = '2.0.beta.14' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
6
+ VERSION = '2.0.beta.15' unless const_defined? :VERSION # the guard is against a redefinition warning that happens on Travis
7
7
  end
8
8
  end
9
9
  end
@@ -1,36 +1,15 @@
1
1
  # encoding: utf-8
2
- require 'libis/workflow/mongoid/work_item_base'
2
+ require 'libis-workflow'
3
+ require_relative 'dynamic'
3
4
 
4
5
  module Libis
5
6
  module Workflow
6
7
  module Mongoid
7
8
 
8
- module WorkItem
9
+ class WorkItem
9
10
 
10
- def self.included(klass)
11
- klass.class_eval do
12
- include Libis::Workflow::Mongoid::WorkItemBase
13
-
14
- store_in collection: 'workflow_items'
15
-
16
- has_many :items, inverse_of: :parent, class_name: klass.to_s,
17
- dependent: :destroy, autosave: true, order: :_id.asc
18
- belongs_to :parent, inverse_of: :items, class_name: klass.to_s
19
-
20
- set_callback(:destroy, :before) do |document|
21
- document.items.each { |item| item.destroy! }
22
- end
23
-
24
- def klass.run_class(run_klass)
25
- belongs_to :run, inverse_of: :items, class_name: run_klass.to_s
26
- end
27
-
28
- end
29
- end
30
-
31
- def get_parent
32
- self.parent || self.run
33
- end
11
+ include Libis::Workflow::Base::WorkItem
12
+ include Libis::Workflow::Mongoid::WorkItemBase
34
13
 
35
14
  end
36
15
 
@@ -10,17 +10,17 @@ module Libis
10
10
 
11
11
  class Options
12
12
  include Libis::Workflow::Mongoid::Dynamic
13
- embedded_in :work_item, class_name: Libis::Workflow::Mongoid::WorkItemBase.to_s
13
+ embedded_in :work_item, class_name: 'Libis::Workflow::Mongoid::WorkItem'
14
14
  end
15
15
 
16
16
  class Properties
17
17
  include Libis::Workflow::Mongoid::Dynamic
18
- embedded_in :work_item, class_name: Libis::Workflow::Mongoid::WorkItemBase.to_s
18
+ embedded_in :work_item, class_name: 'Libis::Workflow::Mongoid::WorkItem'
19
19
  end
20
20
 
21
21
  class Summary
22
22
  include Libis::Workflow::Mongoid::Dynamic
23
- embedded_in :work_item, class_name: Libis::Workflow::Mongoid::WorkItemBase.to_s
23
+ embedded_in :work_item, class_name: 'Libis::Workflow::Mongoid::WorkItem'
24
24
  end
25
25
 
26
26
  def self.included(klass)
@@ -28,6 +28,8 @@ module Libis
28
28
  include Libis::Workflow::Base::WorkItem
29
29
  include Libis::Workflow::Mongoid::Base
30
30
 
31
+ store_in collection: 'workflow_items'
32
+
31
33
  embeds_one :options, class_name: Libis::Workflow::Mongoid::WorkItemBase::Options.to_s
32
34
  embeds_one :properties, class_name: Libis::Workflow::Mongoid::WorkItemBase::Properties.to_s
33
35
  embeds_one :summary, class_name: Libis::Workflow::Mongoid::WorkItemBase::Summary.to_s
@@ -43,10 +45,10 @@ module Libis
43
45
  end
44
46
  end
45
47
 
46
- # def destroy
47
- # # noinspection RubyResolve
48
- # self.logs.each { |log| log.destroy }
49
- # end
48
+ has_many :items, as: :parent, class_name: Libis::Workflow::Mongoid::WorkItem.to_s,
49
+ dependent: :destroy, autosave: true, order: :c_at.asc
50
+
51
+ belongs_to :parent, polymorphic: true
50
52
 
51
53
  set_callback(:destroy, :before) do |document|
52
54
  # noinspection RubyResolve
@@ -60,24 +62,8 @@ module Libis
60
62
  end
61
63
 
62
64
  end
63
-
64
- end
65
-
66
- def each
67
- self.items.each { |item| yield item }
68
65
  end
69
66
 
70
- def get_items
71
- self.items.to_a
72
- end
73
-
74
- def item_count
75
- self.items.count
76
- end
77
-
78
- alias_method :count, :item_count
79
- alias_method :size, :item_count
80
-
81
67
  def log_history
82
68
  # noinspection RubyResolve
83
69
  self.logs.log_history.all || []
@@ -9,37 +9,28 @@ module Libis
9
9
  module Workflow
10
10
  module Mongoid
11
11
 
12
- module Workflow
12
+ class Workflow
13
13
 
14
- def self.included(klass)
15
- klass.class_eval do
16
- include ::Libis::Workflow::Base::Workflow
17
- include ::Libis::Workflow::Mongoid::Base
14
+ include ::Libis::Workflow::Base::Workflow
15
+ include ::Libis::Workflow::Mongoid::Base
18
16
 
19
- store_in collection: 'workflow_definitions'
17
+ store_in collection: 'workflow_definitions'
20
18
 
21
- field :name, type: String
22
- field :description, type: String
23
- field :config, type: Hash, default: -> { Hash.new }
19
+ field :name, type: String
20
+ field :description, type: String
21
+ field :config, type: Hash, default: -> { Hash.new }
24
22
 
25
- index({name: 1}, {unique: 1})
23
+ index({name: 1}, {unique: 1})
26
24
 
27
- def klass.job_class(job_klass)
28
- has_many :jobs, inverse_of: :workflow, class_name: job_klass.to_s,
29
- dependent: :destroy, autosave: true, order: :c_at.asc
30
- end
31
-
32
- def klass.load(file_or_hash)
33
- config = Libis::Tools::ConfigFile.new
34
- config << file_or_hash
35
- return nil if config.empty?
36
- workflow = self.new
37
- workflow.configure(config.to_hash.key_strings_to_symbols(recursive: true))
38
- workflow
39
- end
40
-
41
- end
25
+ has_many :jobs, as: :workflow, dependent: :destroy, autosave: true, order: :c_at.asc
42
26
 
27
+ def self.load(file_or_hash)
28
+ config = Libis::Tools::ConfigFile.new
29
+ config << file_or_hash
30
+ return nil if config.empty?
31
+ workflow = self.new
32
+ workflow.configure(config.to_hash.key_strings_to_symbols(recursive: true))
33
+ workflow
43
34
  end
44
35
 
45
36
  end
@@ -12,9 +12,9 @@ module Libis
12
12
  autoload :Config, 'libis/workflow/mongoid/config'
13
13
  autoload :LogEntry, 'libis/workflow/mongoid/log_entry'
14
14
  autoload :Job, 'libis/workflow/mongoid/job'
15
- autoload :Run, 'libis/workflow/mongoid/run'
16
- autoload :WorkItem, 'libis/workflow/mongoid/work_item'
17
15
  autoload :WorkItemBase, 'libis/workflow/mongoid/work_item_base'
16
+ autoload :WorkItem, 'libis/workflow/mongoid/work_item'
17
+ autoload :Run, 'libis/workflow/mongoid/run'
18
18
  autoload :Worker, 'libis/workflow/mongoid/worker'
19
19
  autoload :Workflow, 'libis/workflow/mongoid/workflow'
20
20
 
data/mongoid.yml CHANGED
@@ -110,7 +110,7 @@ test:
110
110
 
111
111
  # Preload all models in development, needed when models use
112
112
  # inheritance. (default: false)
113
- #preload_models: false
113
+ preload_models: true
114
114
 
115
115
  # Raise an error when performing a #find and the document is not found.
116
116
  # (default: true)
@@ -3,6 +3,7 @@ require 'libis/workflow'
3
3
  require_relative 'test_item'
4
4
 
5
5
  class TestDirItem < TestItem
6
+
6
7
  include ::Libis::Workflow::Base::DirItem
7
8
 
8
9
  def name=(dir)
@@ -5,6 +5,7 @@ require 'libis-workflow'
5
5
  require_relative 'test_item'
6
6
 
7
7
  class TestFileItem < TestItem
8
+
8
9
  include ::Libis::Workflow::Base::FileItem
9
10
 
10
11
  def filename=(file)
@@ -2,7 +2,5 @@
2
2
 
3
3
  require 'libis/workflow/mongoid/work_item'
4
4
 
5
- class TestItem
6
- include Libis::Workflow::Mongoid::WorkItem
7
- run_class 'TestRun'
5
+ class TestItem < Libis::Workflow::Mongoid::WorkItem
8
6
  end
@@ -1,11 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'libis-workflow-mongoid'
3
3
 
4
- class TestRun
5
- include ::Libis::Workflow::Mongoid::Run
6
-
7
- item_class 'TestItem'
8
- job_class 'TestJob'
4
+ class TestRun <::Libis::Workflow::Mongoid::Run
9
5
 
10
6
  def name; 'TestRun'; end
11
7
 
data/spec/test_job.rb CHANGED
@@ -2,8 +2,5 @@
2
2
 
3
3
  require 'libis/workflow/mongoid/job'
4
4
 
5
- class TestJob
6
- include ::Libis::Workflow::Mongoid::Job
7
- run_class 'TestRun'
8
- workflow_class 'TestWorkflow'
5
+ class TestJob < ::Libis::Workflow::Mongoid::Job
9
6
  end
@@ -2,7 +2,5 @@
2
2
 
3
3
  require 'libis/workflow/mongoid/workflow'
4
4
 
5
- class TestWorkflow
6
- include ::Libis::Workflow::Mongoid::Workflow
7
- job_class 'TestJob'
5
+ class TestWorkflow < ::Libis::Workflow::Mongoid::Workflow
8
6
  end
@@ -90,25 +90,19 @@ describe 'TestWorkflow' do
90
90
 
91
91
  expect(run.options['CollectFiles'][:location]).to eq dirname
92
92
 
93
- def print_item(item, indent = 0)
94
- puts "#{' ' * indent * 2} - #{item.name}"
95
- item.get_items.each do |i|
96
- print_item(i, indent + 1)
97
- end
98
- end
99
- print_item(run)
100
-
93
+ expect(run.items.size).to eq 1
94
+ expect(run.items.count).to eq 1
95
+ expect(run.size).to eq 1
101
96
  expect(run.count).to eq 1
97
+ expect(run.items.first.class).to eq TestDirItem
102
98
  expect(run.first.class).to eq TestDirItem
99
+ expect(run.first.items.size).to eq 4
100
+ expect(run.first.items.count).to eq 4
101
+ expect(run.first.size).to eq 4
103
102
  expect(run.first.count).to eq 4
103
+ expect(run.first.items.first.class).to eq TestFileItem
104
104
  expect(run.first.first.class).to eq TestFileItem
105
105
 
106
- # the following tests do not work on Travis. Tried for days to find out why, but I give up.
107
- # expect(run.get_items.count).to eq 1
108
- # expect(run.get_items.first.class).to eq TestDirItem
109
- # expect(run.get_items.first.count).to eq 4
110
- # expect(run.get_items.first.get_items.first.class).to eq TestFileItem
111
-
112
106
  run.items.first.each_with_index do |x, i|
113
107
  expect(x.name).to eq %w'TestDirItem.rb TestFileItem.rb TestItem.rb TestRun.rb'[i]
114
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libis-workflow-mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.beta.14
4
+ version: 2.0.beta.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kris Dekeyser