rails-workflow 1.4.5.4 → 1.4.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +23 -0
  4. data/Gemfile +2 -1
  5. data/Rakefile +4 -4
  6. data/bin/console +3 -3
  7. data/lib/active_support/overloads.rb +13 -6
  8. data/lib/workflow.rb +12 -279
  9. data/lib/workflow/adapters/active_record.rb +57 -50
  10. data/lib/workflow/adapters/active_record_validations.rb +25 -19
  11. data/lib/workflow/adapters/adapter.rb +23 -0
  12. data/lib/workflow/adapters/remodel.rb +8 -9
  13. data/lib/workflow/callbacks.rb +60 -45
  14. data/lib/workflow/callbacks/callback.rb +23 -37
  15. data/lib/workflow/callbacks/method_callback.rb +12 -0
  16. data/lib/workflow/callbacks/proc_callback.rb +23 -0
  17. data/lib/workflow/callbacks/string_callback.rb +12 -0
  18. data/lib/workflow/callbacks/transition_callback.rb +88 -78
  19. data/lib/workflow/callbacks/transition_callbacks/method_caller.rb +53 -0
  20. data/lib/workflow/callbacks/transition_callbacks/proc_caller.rb +60 -0
  21. data/lib/workflow/configuration.rb +1 -0
  22. data/lib/workflow/definition.rb +73 -0
  23. data/lib/workflow/errors.rb +37 -6
  24. data/lib/workflow/event.rb +30 -15
  25. data/lib/workflow/helper_method_configurator.rb +100 -0
  26. data/lib/workflow/specification.rb +45 -22
  27. data/lib/workflow/state.rb +45 -36
  28. data/lib/workflow/transition_context.rb +5 -4
  29. data/lib/workflow/transitions.rb +94 -0
  30. data/lib/workflow/version.rb +2 -1
  31. data/rails-workflow.gemspec +18 -18
  32. data/tags.markdown +31 -0
  33. metadata +13 -5
  34. data/lib/workflow/callbacks/transition_callbacks/method_wrapper.rb +0 -102
  35. data/lib/workflow/callbacks/transition_callbacks/proc_wrapper.rb +0 -48
  36. data/lib/workflow/draw.rb +0 -79
@@ -1,48 +0,0 @@
1
-
2
- module Workflow
3
- module Callbacks
4
- module TransitionCallbacks
5
- # A {Workflow::Callbacks::TransitionCallback} that wraps a callback proc.
6
- class ProcWrapper < ::Workflow::Callbacks::TransitionCallback
7
- # Builds a proc object that will correctly call the {#raw_proc}
8
- # by inspecting its parameters and pulling arguments from the {Workflow::TransitionContext}
9
- # object for the transition.
10
- def wrapper
11
- arguments = [
12
- name_arguments_string,
13
- rest_param_string,
14
- kw_arguments_string,
15
- keyrest_string,
16
- procedure_string].compact.join(', ')
17
-
18
- raw_proc = self.raw_proc
19
- str = build_proc("target.instance_exec(#{arguments})")
20
- eval(str)
21
- end
22
-
23
- private
24
-
25
- def name_arguments_string
26
- params = name_params
27
- names = []
28
- names << 'target' if params.shift
29
- (names << 'callbacks') && params.shift if around_callback?
30
- names += params.map{|name| "name_proc.call(:#{name})"}
31
- return names.join(', ') if names.any?
32
- end
33
-
34
- def procedure_string
35
- '&raw_proc'
36
- end
37
-
38
- def parameters
39
- raw_proc.parameters
40
- end
41
-
42
- def arity
43
- raw_proc.arity
44
- end
45
- end
46
- end
47
- end
48
- end
data/lib/workflow/draw.rb DELETED
@@ -1,79 +0,0 @@
1
- begin
2
- require 'rubygems'
3
-
4
- gem 'ruby-graphviz', '~> 1.0.0'
5
- gem 'activesupport'
6
-
7
- require 'graphviz'
8
- require 'active_support/inflector'
9
- rescue LoadError => e
10
- $stderr.puts "Could not load the ruby-graphiz or active_support gems for rendering: #{e.message}"
11
- end
12
-
13
- module Workflow
14
- module Draw
15
-
16
- # Generates a `dot` graph of the workflow.
17
- # Prerequisite: the `dot` binary. (Download from http://www.graphviz.org/)
18
- # You can use this method in your own Rakefile like this:
19
- #
20
- # namespace :doc do
21
- # desc "Generate a workflow graph for a model passed e.g. as 'MODEL=Order'."
22
- # task :workflow => :environment do
23
- # require 'workflow/draw'
24
- # Workflow::Draw::workflow_diagram(ENV['MODEL'].constantize)
25
- # end
26
- # end
27
- #
28
- # You can influence the placement of nodes by specifying
29
- # additional meta information in your states and transition descriptions.
30
- # You can assign higher `weight` value to the typical transitions
31
- # in your workflow. All other states and transitions will be arranged
32
- # around that main line. See also `weight` in the graphviz documentation.
33
- # Example:
34
- #
35
- # state :new do
36
- # event :approve, :transitions_to => :approved, :meta => {:weight => 8}
37
- # end
38
- #
39
- #
40
- # @param klass A class with the Workflow mixin, for which you wish the graphical workflow representation
41
- # @param [String] target_dir Directory, where to save the dot and the pdf files
42
- # @param [String] graph_options You can change graph orientation, size etc. See graphviz documentation
43
- def self.workflow_diagram(klass, options={})
44
- options = {
45
- :name => "#{klass.name.tableize}_workflow".gsub('/', '_'),
46
- :path => '.',
47
- :orientation => "landscape",
48
- :ratio => "fill",
49
- :format => 'png',
50
- :font => 'Helvetica'
51
- }.merge options
52
-
53
- graph = ::GraphViz.new('G', :rankdir => options[:orientation] == 'landscape' ? 'LR' : 'TB', :ratio => options[:ratio])
54
-
55
- # Add nodes
56
- klass.workflow_spec.states.each do |_, state|
57
- node = state.draw(graph)
58
- node.fontname = options[:font]
59
-
60
- state.uniq_events.each do |event|
61
- edge = event.draw(graph, state)
62
- edge.fontname = options[:font]
63
- end
64
- end
65
-
66
- # Generate the graph
67
- filename = File.join(options[:path], "#{options[:name]}.#{options[:format]}")
68
-
69
- graph.output options[:format] => "'#{filename}'"
70
-
71
- puts "
72
- Please run the following to open the generated file:
73
-
74
- open '#{filename}'
75
- "
76
- graph
77
- end
78
- end
79
- end