validating-workflow 0.7.7 → 0.7.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01c79cb96bb6f3ae9887854cf9f4e8be7a5cf834
4
- data.tar.gz: 5012d899c8754622b4d009b0fd9aa179fa5c5a2a
3
+ metadata.gz: d130757849316ba07bb518d99578f4184f59dbb3
4
+ data.tar.gz: 8b8fae7c226937dd0a5029ea9ae53cd05dd7688c
5
5
  SHA512:
6
- metadata.gz: bc7c0ca5b4b9aee56f8ea791c4b89443fedf9d17f746c42c8a6308a52e50bbbc162f3e2c1bcacfd8923d121c823a15cd3c94c8a050265b692029dfa2976dfd84
7
- data.tar.gz: ab4a4a86a5d65a0f359470f89d0a659173348e7594b990a556f338b0ceba72a8c7e1f50736b3bc367b2ec24a6b4e1204a561dff78e1d6b48e19e36d45f4743f3
6
+ metadata.gz: d2df156fe39c4a35538e4ee5d9d2ba42684f808357257e16b3c814f781ac24b69f46696f3ae56ad4066c49020b9d41202b7cc4f1bab74a3cfa35d55b1e3af08b
7
+ data.tar.gz: bfcfbc6ba0c6c45e8db8119180f21dcdeeeddcfb22a74d1b85e97fb70e859977bbbae10172dd076ebb0d427a5e3e229388caeef06bdfb5a6ca7889c89da6902d
data/Rakefile CHANGED
@@ -16,29 +16,3 @@ Rake::RDocTask.new do |rdoc|
16
16
  rdoc.options << "-S"
17
17
  end
18
18
 
19
- begin
20
- require 'jeweler'
21
- Jeweler::Tasks.new do |gemspec|
22
- gemspec.name = 'workflow'
23
- gemspec.rubyforge_project = 'workflow'
24
- gemspec.email = 'vladimir@geekq.net'
25
- gemspec.homepage = 'http://www.geekq.net/workflow/'
26
- gemspec.authors = ['Vladimir Dobriakov', 'Willem van Kerkhof']
27
- gemspec.summary = 'A replacement for acts_as_state_machine.'
28
- gemspec.description = <<-EOS
29
- Workflow is a finite-state-machine-inspired API for modeling and interacting
30
- with what we tend to refer to as 'workflow'.
31
-
32
- * nice DSL to describe your states, events and transitions
33
- * robust integration with ActiveRecord and non relational data stores
34
- * various hooks for single transitions, entering state etc.
35
- * convenient access to the workflow specification: list states, possible events
36
- for particular state
37
- EOS
38
-
39
- Jeweler::GemcutterTasks.new
40
- end
41
- rescue LoadError
42
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
43
- end
44
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.6
1
+ 0.7.9
@@ -0,0 +1,34 @@
1
+ module Workflow
2
+ module ActiveModelPersistence
3
+
4
+ def self.happy_to_be_included_in?(klass)
5
+ Object.const_defined?(:ActiveRecord) and klass.is_a? ActiveRecord::Base
6
+ end
7
+
8
+ def self.included(klass)
9
+ klass.before_validation :write_initial_state
10
+ end
11
+
12
+ def load_workflow_state
13
+ read_attribute(self.class.workflow_column)
14
+ end
15
+
16
+ # On transition the new workflow state is immediately saved in the
17
+ # database.
18
+ def persist_workflow_state(new_value)
19
+ update_attribute self.class.workflow_column, new_value
20
+ end
21
+
22
+ private
23
+
24
+ # Motivation: even if NULL is stored in the workflow_state database column,
25
+ # the current_state is correctly recognized in the Ruby code. The problem
26
+ # arises when you want to SELECT records filtering by the value of initial
27
+ # state. That's why it is important to save the string with the name of the
28
+ # initial state in all the new records.
29
+ def write_initial_state
30
+ write_attribute self.class.workflow_column, current_state.to_s
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,35 @@
1
+ module Workflow
2
+ module MongoidPersistence
3
+
4
+ def self.happy_to_be_included_in?(klass)
5
+ Object.const_defined?(:Mongoid) and klass.include? Mongoid::Document
6
+ end
7
+
8
+ def self.included(klass)
9
+ klass.after_initialize :write_initial_state
10
+ end
11
+
12
+ def load_workflow_state
13
+ read_attribute(self.class.workflow_column)
14
+ end
15
+
16
+ # implementation of abstract method: saves new workflow state to DB
17
+ def persist_workflow_state(new_value)
18
+ self.write_attribute(self.class.workflow_column, new_value.to_s)
19
+ self.save!
20
+ end
21
+
22
+ private
23
+
24
+ # Motivation: even if NULL is stored in the workflow_state database column,
25
+ # the current_state is correctly recognized in the Ruby code. The problem
26
+ # arises when you want to SELECT records filtering by the value of initial
27
+ # state. That's why it is important to save the string with the name of the
28
+ # initial state in all the new records.
29
+ def write_initial_state
30
+ write_attribute self.class.workflow_column, current_state.to_s
31
+ end
32
+
33
+ end
34
+ end
35
+
@@ -0,0 +1,17 @@
1
+ module Workflow
2
+ module RemodelPersistence
3
+
4
+ def self.happy_to_be_included_in?(klass)
5
+ Object.const_defined?(:Remodel) and klass < Remodel::Entity
6
+ end
7
+
8
+ def load_workflow_state
9
+ send(self.class.workflow_column)
10
+ end
11
+
12
+ def persist_workflow_state(new_value)
13
+ update(self.class.workflow_column => new_value)
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+
3
+ # Provides transaction rollback on halt. For now, you can choose between
4
+ # normal halt without any change to ordinary persistence (halt) or halt
5
+ # with transaction rollback (halt_with_rollback!), which will raise an
6
+ # ActiveRecord::Rollback exception.
7
+ # So this only works with ActiveRecord atm.
8
+
9
+ module Workflow
10
+ module Transactional
11
+ def new_transaction
12
+ self.class.transaction(:requires_new => true) do
13
+ yield
14
+ end
15
+ end
16
+
17
+ def halt_with_rollback!(reason = nil)
18
+ halt reason
19
+ raise ActiveRecord::Rollback
20
+ end
21
+
22
+ def process_event!(*args)
23
+ return_value = :unprocessed
24
+ self.new_transaction do
25
+ return_value = super(*args)
26
+ # raise ActiveRecord::Rollback if self.halted?
27
+ end
28
+ return return_value == :unprocessed ? false : return_value
29
+ end
30
+
31
+ end # module Transactional
32
+ end # module Workflow
data/lib/workflow.rb CHANGED
@@ -2,10 +2,11 @@ require 'rubygems'
2
2
 
3
3
  # See also README.markdown for documentation
4
4
  module Workflow
5
- autoload :ActiveModelPersistence, 'workflow/active_model_persistence'
6
- autoload :MongoidPersistence, 'workflow/mongoid_persistence'
7
- autoload :RemodelPersistence, 'workflow/remodel_persistence'
8
- autoload :Transactional, 'workflow/transactional'
5
+ autoload :ActiveModelPersistence, 'workflow/active_model_persistence'
6
+ autoload :MongoidPersistence, 'workflow/mongoid_persistence'
7
+ autoload :RemodelPersistence, 'workflow/remodel_persistence'
8
+ autoload :Transactional, 'workflow/transactional'
9
+ autoload :StateDependentValidations, 'workflow/state_dependent_validations'
9
10
 
10
11
  class Specification
11
12
 
@@ -21,6 +22,10 @@ module Workflow
21
22
  states.keys
22
23
  end
23
24
 
25
+ def event_names
26
+ states.values.map{|e| e.events.keys }.uniq
27
+ end
28
+
24
29
  private
25
30
 
26
31
  def state(name, meta = {:meta => {}}, &events_and_etc)
@@ -0,0 +1 @@
1
+ require 'workflow'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validating-workflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.7
4
+ version: 0.7.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dobriakov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-27 00:00:00.000000000 Z
12
+ date: 2017-05-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: |
15
15
  Validating-Workflow is a finite-state-machine-inspired API for modeling and interacting
@@ -27,41 +27,47 @@ extensions: []
27
27
  extra_rdoc_files:
28
28
  - README.markdown
29
29
  files:
30
- - .gitignore
30
+ - ".gitignore"
31
31
  - MIT-LICENSE
32
32
  - README.markdown
33
33
  - Rakefile
34
34
  - VERSION
35
35
  - lib/workflow.rb
36
+ - lib/workflow/active_model_persistence.rb
37
+ - lib/workflow/mongoid_persistence.rb
38
+ - lib/workflow/remodel_persistence.rb
39
+ - lib/workflow/state_dependent_validations.rb
40
+ - lib/workflow/transactional.rb
36
41
  - test/couchtiny_example.rb
37
42
  - test/main_test.rb
38
43
  - test/multiple_workflows_test.rb
39
44
  - test/readme_example.rb
40
45
  - test/test_helper.rb
41
46
  - test/without_active_record_test.rb
47
+ - validating-workflow.rb
42
48
  - workflow.rb
43
- - lib/workflow/state_dependent_validations.rb
44
49
  homepage: http://www.geekq.net/workflow/
45
- licenses: []
50
+ licenses:
51
+ - MIT
46
52
  metadata: {}
47
53
  post_install_message:
48
54
  rdoc_options:
49
- - --charset=UTF-8
55
+ - "--charset=UTF-8"
50
56
  require_paths:
51
57
  - lib
52
58
  required_ruby_version: !ruby/object:Gem::Requirement
53
59
  requirements:
54
- - - '>='
60
+ - - ">="
55
61
  - !ruby/object:Gem::Version
56
62
  version: '0'
57
63
  required_rubygems_version: !ruby/object:Gem::Requirement
58
64
  requirements:
59
- - - '>='
65
+ - - ">="
60
66
  - !ruby/object:Gem::Version
61
67
  version: '0'
62
68
  requirements: []
63
69
  rubyforge_project:
64
- rubygems_version: 2.0.2
70
+ rubygems_version: 2.5.2
65
71
  signing_key:
66
72
  specification_version: 3
67
73
  summary: A replacement for acts_as_state_machine, an enhancement of workflow.
@@ -72,4 +78,3 @@ test_files:
72
78
  - test/without_active_record_test.rb
73
79
  - test/multiple_workflows_test.rb
74
80
  - test/readme_example.rb
75
- has_rdoc: