wizard_machine 0.0.0
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.
- data/CHANGELOG +4 -0
- data/LICENSE +20 -0
- data/Manifest +8 -0
- data/README +15 -0
- data/Rakefile +16 -0
- data/TODO +0 -0
- data/lib/wizard_machine.rb +128 -0
- data/lib/wizard_machine_controller_extensions.rb +26 -0
- data/wizard_machine.gemspec +30 -0
- metadata +73 -0
data/CHANGELOG
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Ryan Owens
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('wizard_machine', '0.0.0') do |p|
|
6
|
+
p.project = "wizard-machine"
|
7
|
+
p.description = "A Rails gem for managing the states of a model by defining wizard steps."
|
8
|
+
p.url = "http://rubyforge.org/projects/wizard-machine"
|
9
|
+
p.author = 'Ryan Owens'
|
10
|
+
p.email = "ryan (at) infoether (dot) com"
|
11
|
+
p.ignore_pattern = ["tmp/*", "script/*", "wizard_machine_notes.txt"]
|
12
|
+
p.development_dependencies = []
|
13
|
+
end
|
14
|
+
|
15
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
16
|
+
|
data/TODO
ADDED
File without changes
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module WizardMachine
|
2
|
+
|
3
|
+
def self.__wizard_machine_processing_class
|
4
|
+
@__wizard_machine_processing_class
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.__wizard_machine_processing_class=(klass)
|
8
|
+
raise "__wizard_machine_processing_class is already set (#{@__wizard_machine_processing_class.name}). Make sure you are calling setup_wizard_events! (#{klass.name}). " if !klass.nil? && !@__wizard_machine_processing_class.nil?
|
9
|
+
@__wizard_machine_processing_class = klass
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.included(base)
|
13
|
+
WizardMachine.__wizard_machine_processing_class = base
|
14
|
+
base.send :include, AASM
|
15
|
+
base.extend(ClassMethods)
|
16
|
+
|
17
|
+
# base.aasm_column :state #default is :aasm_state
|
18
|
+
|
19
|
+
base.after_create :created!
|
20
|
+
|
21
|
+
base.aasm_initial_state :new
|
22
|
+
base.aasm_state :new
|
23
|
+
end
|
24
|
+
|
25
|
+
module ClassMethods
|
26
|
+
|
27
|
+
def wizard_state(*args)
|
28
|
+
@all_state_names = nil
|
29
|
+
@wizard_state_names = nil
|
30
|
+
aasm_state(*args)
|
31
|
+
end
|
32
|
+
|
33
|
+
def wizard_state_is(state)
|
34
|
+
Proc.new { |service_account| service_account.wizard_state == state }
|
35
|
+
end
|
36
|
+
|
37
|
+
def all_state_names
|
38
|
+
@all_state_names ||= self.aasm_states.collect(&:name)
|
39
|
+
end
|
40
|
+
|
41
|
+
def wizard_state_names
|
42
|
+
@wizard_state_names ||= all_state_names - [:new]
|
43
|
+
end
|
44
|
+
|
45
|
+
def wizard_total_steps
|
46
|
+
wizard_state_names.size-1
|
47
|
+
end
|
48
|
+
|
49
|
+
def setup_wizard_events!
|
50
|
+
aasm_state :wizard_complete
|
51
|
+
|
52
|
+
aasm_event :created do
|
53
|
+
transitions :to => WizardMachine.__wizard_machine_processing_class.wizard_state_names.first, :from => [:new]
|
54
|
+
end
|
55
|
+
aasm_event :wizard_complete do
|
56
|
+
transitions :to => :wizard_complete, :from => WizardMachine.__wizard_machine_processing_class.all_state_names
|
57
|
+
end
|
58
|
+
wizard_state_names.each do |state|
|
59
|
+
aasm_event state do
|
60
|
+
transitions :to => state, :from => WizardMachine.__wizard_machine_processing_class.all_state_names
|
61
|
+
end
|
62
|
+
end
|
63
|
+
WizardMachine.__wizard_machine_processing_class = nil
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
def set_state!(state)
|
69
|
+
raise "No state with name: #{state.inspect}. wizard_states: #{self.wizard_state_names.inspect}" unless valid_state?(state)
|
70
|
+
self.send "#{state}!"
|
71
|
+
end
|
72
|
+
|
73
|
+
def valid_state?(state)
|
74
|
+
state = state.intern if state.respond_to? :intern
|
75
|
+
all_state_names.include? state
|
76
|
+
end
|
77
|
+
|
78
|
+
#TODO consider using wizard_state_names for the index. does it matter? this should just be internal, so it shouldn't really matter (I think).
|
79
|
+
def state_index
|
80
|
+
all_state_names.index wizard_state
|
81
|
+
end
|
82
|
+
|
83
|
+
def wizard_state
|
84
|
+
raise "Model is saved in an invalid state. You must have changed some of the wizard_states. Invalid state: #{aasm_current_state.inspect}. wizard_states: #{self.wizard_state_names.inspect}" unless valid_state?(aasm_current_state)
|
85
|
+
aasm_current_state
|
86
|
+
end
|
87
|
+
|
88
|
+
def wizard_current_step
|
89
|
+
state_index
|
90
|
+
end
|
91
|
+
|
92
|
+
def previous_state_index
|
93
|
+
state_index.zero? ? 0 : state_index - 1
|
94
|
+
end
|
95
|
+
|
96
|
+
def next_state_index
|
97
|
+
wizard_complete? ? nil : state_index + 1
|
98
|
+
end
|
99
|
+
|
100
|
+
def next_state_name
|
101
|
+
all_state_names[next_state_index]
|
102
|
+
end
|
103
|
+
|
104
|
+
def next_state!
|
105
|
+
set_state! next_state_name
|
106
|
+
end
|
107
|
+
|
108
|
+
def previous_wizard_state
|
109
|
+
all_state_names[previous_state_index]
|
110
|
+
end
|
111
|
+
|
112
|
+
def previous_state!
|
113
|
+
set_state! previous_wizard_state
|
114
|
+
end
|
115
|
+
|
116
|
+
def wizard_complete?
|
117
|
+
:wizard_complete == wizard_state
|
118
|
+
end
|
119
|
+
|
120
|
+
def all_state_names
|
121
|
+
self.class.all_state_names
|
122
|
+
end
|
123
|
+
|
124
|
+
def wizard_state_names
|
125
|
+
self.class.wizard_state_names
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module WizardMachineControllerExtensions
|
2
|
+
|
3
|
+
#TODO ad the ability to auto-gen certain actions into the plugin. For now this isn't actually used.
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
# base.send :include, AASM
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
|
9
|
+
self << class
|
10
|
+
#each state has its own action which needs to setup the service_account object from the params
|
11
|
+
# before_filter :service_account, :only => ServiceAccount.wizard_state_names
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
|
18
|
+
# def wizard_state(*args)
|
19
|
+
# @all_state_names = nil
|
20
|
+
# @wizard_state_names = nil
|
21
|
+
# aasm_state(*args)
|
22
|
+
# end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{wizard_machine}
|
5
|
+
s.version = "0.0.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Ryan Owens"]
|
9
|
+
s.date = %q{2009-08-25}
|
10
|
+
s.description = %q{A Rails gem for managing the states of a model by defining wizard steps.}
|
11
|
+
s.email = %q{ryan (at) infoether (dot) com}
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/wizard_machine.rb", "lib/wizard_machine_controller_extensions.rb", "LICENSE", "README", "TODO"]
|
13
|
+
s.files = ["CHANGELOG", "lib/wizard_machine.rb", "lib/wizard_machine_controller_extensions.rb", "LICENSE", "Rakefile", "README", "TODO", "Manifest", "wizard_machine.gemspec"]
|
14
|
+
s.homepage = %q{http://rubyforge.org/projects/wizard-machine}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Wizard_machine", "--main", "README"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{wizard-machine}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{A Rails gem for managing the states of a model by defining wizard steps.}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wizard_machine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Owens
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-25 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A Rails gem for managing the states of a model by defining wizard steps.
|
17
|
+
email: ryan (at) infoether (dot) com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- CHANGELOG
|
24
|
+
- lib/wizard_machine.rb
|
25
|
+
- lib/wizard_machine_controller_extensions.rb
|
26
|
+
- LICENSE
|
27
|
+
- README
|
28
|
+
- TODO
|
29
|
+
files:
|
30
|
+
- CHANGELOG
|
31
|
+
- lib/wizard_machine.rb
|
32
|
+
- lib/wizard_machine_controller_extensions.rb
|
33
|
+
- LICENSE
|
34
|
+
- Rakefile
|
35
|
+
- README
|
36
|
+
- TODO
|
37
|
+
- Manifest
|
38
|
+
- wizard_machine.gemspec
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://rubyforge.org/projects/wizard-machine
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --line-numbers
|
46
|
+
- --inline-source
|
47
|
+
- --title
|
48
|
+
- Wizard_machine
|
49
|
+
- --main
|
50
|
+
- README
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "1.2"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project: wizard-machine
|
68
|
+
rubygems_version: 1.3.5
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: A Rails gem for managing the states of a model by defining wizard steps.
|
72
|
+
test_files: []
|
73
|
+
|