stonepath 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/lib/stonepath.rb CHANGED
@@ -45,8 +45,16 @@ end
45
45
 
46
46
  require 'rubygems'
47
47
  require 'active_record'
48
+ require "stonepath/config"
48
49
 
50
+ # I want to move these into init.rb, but for some reason, the way rails processes the
51
+ # init.rb chokes on load. I suspect this is an artificial issue because of the way the
52
+ # embedded test app works.
49
53
  load File.expand_path( File.dirname(__FILE__)) + "/stonepath/extensions/activerecordbase.rb"
50
- require "stonepath/config"
54
+ load File.expand_path( File.dirname(__FILE__)) + "/stonepath/extensions/action_controller.rb"
55
+ load File.expand_path( File.dirname(__FILE__)) + "/stonepath/extensions/kernel.rb"
56
+ load File.expand_path( File.dirname(__FILE__)) + '/stonepath/extensions/action_view.rb'
57
+
58
+
51
59
 
52
60
 
@@ -0,0 +1,50 @@
1
+ if Object.const_defined?(:ActionController)
2
+
3
+ module ActionController
4
+ module Resources
5
+
6
+ def define_events_controller(object_sym)
7
+ class_name = object_sym.to_s.classify
8
+ controller_name = class_name + "EventsController"
9
+
10
+ # This is some amazing bit of meta that will probably go away when we have
11
+ # a work_item generator. In short, at runtime, this defines the controller
12
+ # that handles events for something declared in the routes file as a
13
+ # stonepath_workitem
14
+ Object.const_set(controller_name, ApplicationController.clone).class_eval do
15
+ id_name = (class_name.downcase + "_id").to_sym
16
+ #still need generic http error handling
17
+ define_method("create") do
18
+ if request.post?
19
+ @object = get_class(class_name).find(params[id_name])
20
+ event = params[:id]
21
+ if get_class(class_name).aasm_events.keys.include?(event.to_sym)
22
+ respond_to do |format|
23
+ if @object.send(event + "!")
24
+ flash[:notice] = "Event '#{event}' was successfully performed."
25
+ format.html { redirect_to(@object) }
26
+ format.xml { render :xml => @object }
27
+ else
28
+ flash[:notice] = "Event '#{event}' was NOT successfully performed."
29
+ format.html { redirect_to(@object) }
30
+ format.xml { render :xml => @object.errors, :status => :unprocessable_entity }
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ def stonepath_workitems(resources_symbol, params={})
41
+ singular_resource_name = resources_symbol.to_s.singularize
42
+ self.resources resources_symbol, params do |o|
43
+ o.resource :event, {:only => "create", :controller => "#{singular_resource_name}_events"}
44
+ end
45
+ define_events_controller(resources_symbol)
46
+ end
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,17 @@
1
+ # this 'if' test is necessary because the test app we are using doesn't load ActionView.
2
+ # of course, the correct way to fix it is to fix the test app and write some tests!
3
+ if Object.const_defined?(:ActionView)
4
+ module ActionView
5
+ module Helpers
6
+ module UrlHelper
7
+
8
+ def link_to_stonepath_event(object, event)
9
+ path_method = object.class.to_s.downcase + "_event_path"
10
+ path = self.send(path_method, object, :id => event.to_s)
11
+ link_to(event.to_s.humanize, path, :method => :post)
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module Kernel
2
+ def get_class(name)
3
+ self.class.const_get(name)
4
+ end
5
+ end
data/rails/init.rb ADDED
File without changes
@@ -0,0 +1,8 @@
1
+ class StonepathWorkitemGenerator < Rails::Generator::Base
2
+ def manifest
3
+ record do |m|
4
+ task_name = args[0]
5
+ m.readme("workitem_readme.txt")
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ We will eventually have a real generator here that will even include some default config for AASM settings, restful routes for the workflow actions, etc. Until then, it would be best to start a workitem by:
2
+
3
+ 1) Using scaffold generator
4
+ 2) adding aasm_state:string and owner_id:integer to the migration.
5
+ 3) adding:
6
+
7
+ require 'aasm'
8
+ require 'stonepath'
9
+
10
+ stonepath_workitem
11
+
12
+ to the model
13
+
14
+ 4) defining a state machine.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stonepath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Bock
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-05 00:00:00 -05:00
12
+ date: 2010-01-06 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -45,19 +45,25 @@ files:
45
45
  - lib/stonepath/config.rb
46
46
  - lib/stonepath/controller_hooks.rb
47
47
  - lib/stonepath/event_logging.rb
48
+ - lib/stonepath/extensions/action_controller.rb
49
+ - lib/stonepath/extensions/action_view.rb
48
50
  - lib/stonepath/extensions/activerecordbase.rb
51
+ - lib/stonepath/extensions/kernel.rb
49
52
  - lib/stonepath/group.rb
50
53
  - lib/stonepath/role.rb
51
54
  - lib/stonepath/task.rb
52
55
  - lib/stonepath/work_bench.rb
53
56
  - lib/stonepath/work_item.rb
54
57
  - lib/stonepath/work_owner.rb
58
+ - rails/init.rb
55
59
  - rails_generators/stonepath/stonepath_event_log_generator.rb
56
60
  - rails_generators/stonepath/stonepath_task_generator.rb
61
+ - rails_generators/stonepath/stonepath_workitem_generator.rb
57
62
  - rails_generators/stonepath/templates/create_event_records.rb
58
63
  - rails_generators/stonepath/templates/event_record.rb
59
64
  - rails_generators/stonepath/templates/generic_task.rb
60
65
  - rails_generators/stonepath/templates/generic_task_migration.rb
66
+ - rails_generators/stonepath/templates/workitem_readme.txt
61
67
  - script/console
62
68
  - script/destroy
63
69
  - script/generate