workflow_kit 0.0.1.apha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/.gitignore +7 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +20 -0
  4. data/Gemfile.lock +153 -0
  5. data/Guardfile +22 -0
  6. data/MIT-LICENSE +22 -0
  7. data/README.md +53 -0
  8. data/Rakefile +42 -0
  9. data/app/assets/images/workflow_kit/.gitkeep +0 -0
  10. data/app/assets/javascripts/workflow_kit/application.js +15 -0
  11. data/app/assets/javascripts/workflow_kit/workflows.js +2 -0
  12. data/app/assets/stylesheets/scaffold.css +56 -0
  13. data/app/assets/stylesheets/workflow_kit/application.css +13 -0
  14. data/app/assets/stylesheets/workflow_kit/workflows.css +4 -0
  15. data/app/controllers/workflow_kit/application_controller.rb +5 -0
  16. data/app/controllers/workflow_kit/workflows_controller.rb +96 -0
  17. data/app/helpers/workflow_kit/application_helper.rb +4 -0
  18. data/app/helpers/workflow_kit/workflows_helper.rb +4 -0
  19. data/app/models/workflow_kit/brick.rb +45 -0
  20. data/app/models/workflow_kit/parameter.rb +34 -0
  21. data/app/models/workflow_kit/parameterable.rb +40 -0
  22. data/app/models/workflow_kit/step.rb +27 -0
  23. data/app/models/workflow_kit/workflow.rb +20 -0
  24. data/app/views/workflow_kit/workflows/_form.html.erb +25 -0
  25. data/app/views/workflow_kit/workflows/edit.html.erb +6 -0
  26. data/app/views/workflow_kit/workflows/index.html.erb +25 -0
  27. data/app/views/workflow_kit/workflows/new.html.erb +5 -0
  28. data/app/views/workflow_kit/workflows/show.html.erb +29 -0
  29. data/config/routes.rb +9 -0
  30. data/db/migrate/20120721135535_create_workflow_kit_workflows.rb +10 -0
  31. data/db/migrate/20120721140135_create_workflow_kit_steps.rb +11 -0
  32. data/db/migrate/20120721140613_create_workflow_kit_parameters.rb +11 -0
  33. data/lib/tasks/workflow_kit_tasks.rake +4 -0
  34. data/lib/workflow_kit/engine.rb +6 -0
  35. data/lib/workflow_kit/version.rb +3 -0
  36. data/lib/workflow_kit.rb +4 -0
  37. data/script/rails +8 -0
  38. data/spec/models/brick_spec.rb +39 -0
  39. data/spec/models/parameter_spec.rb +69 -0
  40. data/spec/models/parameterable_spec.rb +58 -0
  41. data/spec/models/step_spec.rb +39 -0
  42. data/spec/models/workflow_spec.rb +38 -0
  43. data/spec/spec_helper.rb +43 -0
  44. data/spec/support/factory.rb +49 -0
  45. data/test/dummy/README.rdoc +261 -0
  46. data/test/dummy/Rakefile +7 -0
  47. data/test/dummy/app/assets/javascripts/application.js +15 -0
  48. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  49. data/test/dummy/app/assets/stylesheets/demo_app.css.sass +31 -0
  50. data/test/dummy/app/assets/stylesheets/nifty.css +79 -0
  51. data/test/dummy/app/controllers/application_controller.rb +3 -0
  52. data/test/dummy/app/helpers/application_helper.rb +2 -0
  53. data/test/dummy/app/helpers/error_messages_helper.rb +23 -0
  54. data/test/dummy/app/helpers/layout_helper.rb +22 -0
  55. data/test/dummy/app/mailers/.gitkeep +0 -0
  56. data/test/dummy/app/models/.gitkeep +0 -0
  57. data/test/dummy/app/models/message.rb +3 -0
  58. data/test/dummy/app/models/workflow_kit/brick_a.rb +12 -0
  59. data/test/dummy/app/models/workflow_kit/brick_b.rb +12 -0
  60. data/test/dummy/app/models/workflow_kit/brick_c.rb +12 -0
  61. data/test/dummy/app/models/workflow_kit/test_brick.rb +12 -0
  62. data/test/dummy/app/views/layouts/application.html.erb +18 -0
  63. data/test/dummy/app/views/workflow_kit/workflows/index.html.erb +48 -0
  64. data/test/dummy/config/application.rb +58 -0
  65. data/test/dummy/config/boot.rb +10 -0
  66. data/test/dummy/config/database.yml +25 -0
  67. data/test/dummy/config/environment.rb +5 -0
  68. data/test/dummy/config/environments/development.rb +37 -0
  69. data/test/dummy/config/environments/production.rb +67 -0
  70. data/test/dummy/config/environments/test.rb +37 -0
  71. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  72. data/test/dummy/config/initializers/inflections.rb +15 -0
  73. data/test/dummy/config/initializers/mime_types.rb +5 -0
  74. data/test/dummy/config/initializers/secret_token.rb +7 -0
  75. data/test/dummy/config/initializers/session_store.rb +8 -0
  76. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  77. data/test/dummy/config/locales/en.yml +5 -0
  78. data/test/dummy/config/routes.rb +7 -0
  79. data/test/dummy/config.ru +4 -0
  80. data/test/dummy/db/migrate/20120721225047_create_messages.rb +9 -0
  81. data/test/dummy/db/schema.rb +46 -0
  82. data/test/dummy/lib/assets/.gitkeep +0 -0
  83. data/test/dummy/log/.gitkeep +0 -0
  84. data/test/dummy/public/404.html +26 -0
  85. data/test/dummy/public/422.html +26 -0
  86. data/test/dummy/public/500.html +25 -0
  87. data/test/dummy/public/favicon.ico +0 -0
  88. data/test/dummy/script/rails +6 -0
  89. data/test/dummy/test/fixtures/messages.yml +7 -0
  90. data/test/dummy/test/unit/message_test.rb +7 -0
  91. data/test/test_helper.rb +15 -0
  92. data/workflow_kit.gemspec +50 -0
  93. metadata +360 -0
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/log/*.log
6
+ test/dummy/tmp/
7
+ test/dummy/.sass-cache
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Declare your gem's dependencies in workflow_kit.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # jquery-rails is used by the dummy application
9
+ gem "jquery-rails"
10
+
11
+ # Declare any dependencies that are still in development here instead of in
12
+ # your gemspec. These might include edge Rails or gems from your path or
13
+ # Git. Remember to move these dependencies to your gemspec before releasing
14
+ # your gem to rubygems.org.
15
+
16
+ # To use debugger
17
+ # gem 'debugger'
18
+
19
+ gem 'nifty-generators'
20
+ gem 'sass-rails'
data/Gemfile.lock ADDED
@@ -0,0 +1,153 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ workflow_kit (0.0.1.apha)
5
+ rails (~> 3.2.6)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionmailer (3.2.6)
11
+ actionpack (= 3.2.6)
12
+ mail (~> 2.4.4)
13
+ actionpack (3.2.6)
14
+ activemodel (= 3.2.6)
15
+ activesupport (= 3.2.6)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ journey (~> 1.0.1)
19
+ rack (~> 1.4.0)
20
+ rack-cache (~> 1.2)
21
+ rack-test (~> 0.6.1)
22
+ sprockets (~> 2.1.3)
23
+ activemodel (3.2.6)
24
+ activesupport (= 3.2.6)
25
+ builder (~> 3.0.0)
26
+ activerecord (3.2.6)
27
+ activemodel (= 3.2.6)
28
+ activesupport (= 3.2.6)
29
+ arel (~> 3.0.2)
30
+ tzinfo (~> 0.3.29)
31
+ activeresource (3.2.6)
32
+ activemodel (= 3.2.6)
33
+ activesupport (= 3.2.6)
34
+ activesupport (3.2.6)
35
+ i18n (~> 0.6)
36
+ multi_json (~> 1.0)
37
+ addressable (2.2.8)
38
+ arel (3.0.2)
39
+ builder (3.0.0)
40
+ capybara (1.1.2)
41
+ mime-types (>= 1.16)
42
+ nokogiri (>= 1.3.3)
43
+ rack (>= 1.0.0)
44
+ rack-test (>= 0.5.4)
45
+ selenium-webdriver (~> 2.0)
46
+ xpath (~> 0.1.4)
47
+ childprocess (0.3.4)
48
+ ffi (~> 1.0, >= 1.0.6)
49
+ diff-lcs (1.1.3)
50
+ erubis (2.7.0)
51
+ ffi (1.1.0)
52
+ guard (1.0.1)
53
+ ffi (>= 0.5.0)
54
+ thor (~> 0.14.6)
55
+ guard-rspec (0.5.5)
56
+ guard (>= 0.8.4)
57
+ hike (1.2.1)
58
+ i18n (0.6.0)
59
+ journey (1.0.4)
60
+ jquery-rails (2.0.2)
61
+ railties (>= 3.2.0, < 5.0)
62
+ thor (~> 0.14)
63
+ json (1.7.3)
64
+ libwebsocket (0.1.4)
65
+ addressable
66
+ mail (2.4.4)
67
+ i18n (>= 0.4.0)
68
+ mime-types (~> 1.16)
69
+ treetop (~> 1.4.8)
70
+ mime-types (1.19)
71
+ multi_json (1.3.6)
72
+ nifty-generators (0.4.6)
73
+ nokogiri (1.5.5)
74
+ polyglot (0.3.3)
75
+ rack (1.4.1)
76
+ rack-cache (1.2)
77
+ rack (>= 0.4)
78
+ rack-ssl (1.3.2)
79
+ rack
80
+ rack-test (0.6.1)
81
+ rack (>= 1.0)
82
+ rails (3.2.6)
83
+ actionmailer (= 3.2.6)
84
+ actionpack (= 3.2.6)
85
+ activerecord (= 3.2.6)
86
+ activeresource (= 3.2.6)
87
+ activesupport (= 3.2.6)
88
+ bundler (~> 1.0)
89
+ railties (= 3.2.6)
90
+ railties (3.2.6)
91
+ actionpack (= 3.2.6)
92
+ activesupport (= 3.2.6)
93
+ rack-ssl (~> 1.3.2)
94
+ rake (>= 0.8.7)
95
+ rdoc (~> 3.4)
96
+ thor (>= 0.14.6, < 2.0)
97
+ rake (0.9.2.2)
98
+ rdoc (3.12)
99
+ json (~> 1.4)
100
+ rspec (2.10.0)
101
+ rspec-core (~> 2.10.0)
102
+ rspec-expectations (~> 2.10.0)
103
+ rspec-mocks (~> 2.10.0)
104
+ rspec-core (2.10.1)
105
+ rspec-expectations (2.10.0)
106
+ diff-lcs (~> 1.1.3)
107
+ rspec-mocks (2.10.1)
108
+ rspec-rails (2.10.0)
109
+ actionpack (>= 3.0)
110
+ activesupport (>= 3.0)
111
+ railties (>= 3.0)
112
+ rspec (~> 2.10.0)
113
+ rubyzip (0.9.9)
114
+ sass (3.1.20)
115
+ sass-rails (3.2.5)
116
+ railties (~> 3.2.0)
117
+ sass (>= 3.1.10)
118
+ tilt (~> 1.3)
119
+ selenium-webdriver (2.25.0)
120
+ childprocess (>= 0.2.5)
121
+ libwebsocket (~> 0.1.3)
122
+ multi_json (~> 1.0)
123
+ rubyzip
124
+ sprockets (2.1.3)
125
+ hike (~> 1.2)
126
+ rack (~> 1.0)
127
+ tilt (~> 1.1, != 1.3.0)
128
+ sqlite3 (1.3.6)
129
+ thor (0.14.6)
130
+ tilt (1.3.3)
131
+ treetop (1.4.10)
132
+ polyglot
133
+ polyglot (>= 0.3.1)
134
+ tzinfo (0.3.33)
135
+ xpath (0.1.4)
136
+ nokogiri (~> 1.3)
137
+
138
+ PLATFORMS
139
+ ruby
140
+
141
+ DEPENDENCIES
142
+ bundler
143
+ capybara
144
+ guard (= 1.0.1)
145
+ guard-rspec (= 0.5.5)
146
+ jquery-rails
147
+ nifty-generators
148
+ nokogiri (>= 1.5.0)
149
+ rake
150
+ rspec-rails (= 2.10.0)
151
+ sass-rails
152
+ sqlite3
153
+ workflow_kit!
data/Guardfile ADDED
@@ -0,0 +1,22 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^spec/.+_spec\.rb$})
11
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
12
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
13
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
14
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
15
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
16
+ watch('spec/spec_helper.rb') { "spec" }
17
+ watch('config/routes.rb') { "spec/routing" }
18
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
19
+ # Capybara request specs
20
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
21
+ end
22
+
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Sebastian Fiedlschuster
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # WorkflowKit
2
+
3
+ This *ruby on rails gem* provides a *workflow construction kit* for rails apps. Users can arrange workflow bricks in a sequence for each workflow and add parameters. When a workflow is executed, each workflow brick executes a callback method written in ruby and passes the parameters.
4
+
5
+ ## Alpha State
6
+
7
+ This gem is currently in alpha state. It's not production ready, yet.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'workflow_kit'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install workflow_kit
22
+
23
+ ## Usage
24
+
25
+ ### Preparation
26
+
27
+ * Include in routes
28
+ ```ruby
29
+ # config/routes.rb
30
+ Rails.application.routes.draw do
31
+ mount WorkflowKit::Engine => "/workflow_kit"
32
+ end
33
+ ```
34
+
35
+ * Migrate Database
36
+ ```
37
+ rake workflow_kit:install:migrations
38
+ rake db:migrate
39
+ ```
40
+
41
+
42
+ TODO: Write usage instructions here
43
+
44
+ ## Further Reading
45
+ * Integration of mountable engines (like this gem): http://railscasts.com/episodes/277-mountable-engines?view=asciicast
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'WorkflowKit'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ #require 'rake/testtask'
31
+ #
32
+ #Rake::TestTask.new(:test) do |t|
33
+ # t.libs << 'lib'
34
+ # t.libs << 'test'
35
+ # t.pattern = 'test/**/*_test.rb'
36
+ # t.verbose = false
37
+ #end
38
+ #task :default => :test
39
+
40
+ require 'rspec/core/rake_task'
41
+ RSpec::Core::RakeTask.new( :spec )
42
+ task default: :spec
File without changes
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,5 @@
1
+ module WorkflowKit
2
+ class ApplicationController < ActionController::Base
3
+ layout 'application'
4
+ end
5
+ end
@@ -0,0 +1,96 @@
1
+ require_dependency "workflow_kit/application_controller"
2
+
3
+ module WorkflowKit
4
+ class WorkflowsController < ApplicationController
5
+ # GET /workflows
6
+ # GET /workflows.json
7
+ def index
8
+ @workflows = Workflow.all
9
+
10
+ respond_to do |format|
11
+ format.html # index.html.erb
12
+ format.json { render json: @workflows }
13
+ end
14
+ end
15
+
16
+ # GET /workflows/1
17
+ # GET /workflows/1.json
18
+ def show
19
+ @workflow = Workflow.find(params[:id])
20
+
21
+ respond_to do |format|
22
+ format.html # show.html.erb
23
+ format.json { render json: @workflow }
24
+ end
25
+ end
26
+
27
+ # GET /workflows/new
28
+ # GET /workflows/new.json
29
+ def new
30
+ @workflow = Workflow.new
31
+
32
+ respond_to do |format|
33
+ format.html # new.html.erb
34
+ format.json { render json: @workflow }
35
+ end
36
+ end
37
+
38
+ # GET /workflows/1/edit
39
+ def edit
40
+ @workflow = Workflow.find(params[:id])
41
+ end
42
+
43
+ # POST /workflows
44
+ # POST /workflows.json
45
+ def create
46
+ @workflow = Workflow.new(params[:workflow])
47
+
48
+ respond_to do |format|
49
+ if @workflow.save
50
+ format.html { redirect_to @workflow, notice: 'Workflow was successfully created.' }
51
+ format.json { render json: @workflow, status: :created, location: @workflow }
52
+ else
53
+ format.html { render action: "new" }
54
+ format.json { render json: @workflow.errors, status: :unprocessable_entity }
55
+ end
56
+ end
57
+ end
58
+
59
+ # PUT /workflows/1
60
+ # PUT /workflows/1.json
61
+ def update
62
+ @workflow = Workflow.find(params[:id])
63
+
64
+ respond_to do |format|
65
+ if @workflow.update_attributes(params[:workflow])
66
+ format.html { redirect_to @workflow, notice: 'Workflow was successfully updated.' }
67
+ format.json { head :no_content }
68
+ else
69
+ format.html { render action: "edit" }
70
+ format.json { render json: @workflow.errors, status: :unprocessable_entity }
71
+ end
72
+ end
73
+ end
74
+
75
+ # DELETE /workflows/1
76
+ # DELETE /workflows/1.json
77
+ def destroy
78
+ @workflow = Workflow.find(params[:id])
79
+ @workflow.destroy
80
+
81
+ respond_to do |format|
82
+ format.html { redirect_to workflows_url }
83
+ format.json { head :no_content }
84
+ end
85
+ end
86
+
87
+ # PUT /workflows/1/execute
88
+ def execute
89
+ @workflow = Workflow.find( params[ :id ] )
90
+ @workflow.execute
91
+
92
+ flash[ :notice ] = I18n.t( :executed_workflow, @workflow.name )
93
+ redirect_to :back
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,4 @@
1
+ module WorkflowKit
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module WorkflowKit
2
+ module WorkflowsHelper
3
+ end
4
+ end
@@ -0,0 +1,45 @@
1
+ module WorkflowKit
2
+ class Brick
3
+
4
+ @@descendants = []
5
+
6
+ def self.inherited( descendant_class )
7
+ @@descendants << descendant_class
8
+ end
9
+
10
+ def name
11
+ self.class.name
12
+ end
13
+
14
+ def description
15
+ end
16
+
17
+ def execute( params )
18
+ end
19
+
20
+ def self.all
21
+ @@descendants
22
+ end
23
+
24
+ def self.find_by_name( brick_name )
25
+ class_name = "WorkflowKit::#{brick_name}" if brick_name
26
+ return class_name.constantize.new
27
+ end
28
+
29
+ end
30
+
31
+ # If uncommented, this Brick will also be visible in the application.
32
+ # Thus, this should stay commented in production.
33
+ #
34
+ # class TestBrick < Brick
35
+ # def description
36
+ # "This is a test brick of the workflow_kit."
37
+ # end
38
+ #
39
+ # def execute( params )
40
+ # p "Executing TestBrick"
41
+ # p params
42
+ # end
43
+ # end
44
+
45
+ end
@@ -0,0 +1,34 @@
1
+ module WorkflowKit
2
+ class Parameter < ActiveRecord::Base
3
+
4
+ attr_accessible :key, :value
5
+
6
+ belongs_to :parameterable, polymorphic: true
7
+
8
+ def key
9
+ return super.to_sym unless super.kind_of? Symbol
10
+ return super
11
+ end
12
+
13
+ def value
14
+ v = super
15
+ v = v.to_i if ( not v.to_i == nil ) and ( v.to_i.to_s == v )
16
+ v = true if v == "true"
17
+ v = false if v == "false"
18
+ return v
19
+ end
20
+
21
+ def to_hash
22
+ return { key => value }
23
+ end
24
+
25
+ def self.to_hash( parameters )
26
+ parameter_hashes = parameters.collect do |parameter|
27
+ parameter.to_hash
28
+ end
29
+ merged_hash = parameter_hashes.inject { |all, h| all.merge( h ) }
30
+ return merged_hash
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,40 @@
1
+
2
+ module WorkflowKit
3
+
4
+ module Parameterable
5
+ def has_many_parameters
6
+
7
+ has_many :parameters, as: :parameterable, dependent: :destroy, autosave: true
8
+
9
+ include ParameterableInstanceMethods
10
+
11
+ end
12
+ end
13
+
14
+ module ParameterableInstanceMethods
15
+
16
+ # returns the associated parameters as hash
17
+ def parameters_to_hash
18
+ WorkflowKit::Parameter.to_hash( parameters )
19
+ end
20
+
21
+ def parameter_hash
22
+ parameters_to_hash
23
+ end
24
+
25
+ def parameters=( new_parameter_hash )
26
+
27
+ return super( new_parameter_hash ) if not new_parameter_hash.kind_of? Hash # original method
28
+
29
+ parameters.destroy_all # delete previous parameters
30
+ if new_parameter_hash
31
+ new_parameter_hash.each do |key, value|
32
+ self.parameters.build( key: key, value: value )
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -0,0 +1,27 @@
1
+ module WorkflowKit
2
+
3
+ require 'workflow_kit/brick'
4
+
5
+ class Step < ActiveRecord::Base
6
+
7
+ attr_accessible :sequence_index, :brick_name, :parameters
8
+
9
+ belongs_to :workflow
10
+
11
+ extend WorkflowKit::Parameterable
12
+ has_many_parameters
13
+
14
+
15
+ def execute( params = {} )
16
+ params = {} unless params
17
+ params = params.merge( self.parameters_to_hash ) if self.parameters.count > 0
18
+ self.brick.execute( params ) if self.brick
19
+ end
20
+
21
+ def brick
22
+ @brick = Brick.find_by_name( self.brick_name ) unless @brick
23
+ return @brick
24
+ end
25
+
26
+ end
27
+ end