dm-is-state_machine 0.10.2 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## Rubinius
17
+ *.rbc
18
+
19
+ ## PROJECT::GENERAL
20
+ *.gem
21
+ coverage
22
+ rdoc
23
+ pkg
24
+ tmp
25
+ doc
26
+ log
27
+ .yardoc
28
+ measurements
29
+
30
+ ## BUNDLER
31
+ .bundle
32
+ Gemfile.local
33
+ Gemfile.lock
34
+
35
+ ## PROJECT::SPECIFIC
36
+ spec/db/
data/Gemfile ADDED
@@ -0,0 +1,141 @@
1
+ # If you're working on more than one datamapper gem at a time, then it's
2
+ # recommended to create a local Gemfile and use this instead of the git
3
+ # sources. This will make sure that you are developing against your
4
+ # other local datamapper sources that you currently work on. Gemfile.local
5
+ # will behave identically to the standard Gemfile apart from the fact that
6
+ # it fetches the datamapper gems from local paths. This means that you can use
7
+ # the same environment variables, like ADAPTER(S) or PLUGIN(S) when running
8
+ # bundle commands. Gemfile.local is added to .gitignore, so you don't need to
9
+ # worry about accidentally checking local development paths into git.
10
+ # In order to create a local Gemfile, all you need to do is run:
11
+ #
12
+ # bundle exec rake local_gemfile
13
+ #
14
+ # This will give you a Gemfile.local file that points to your local clones of
15
+ # the various datamapper gems. It's assumed that all datamapper repo clones
16
+ # reside in the same directory. You can use the Gemfile.local like so for
17
+ # running any bundle command:
18
+ #
19
+ # BUNDLE_GEMFILE=Gemfile.local bundle foo
20
+ #
21
+ # You can also specify which adapter(s) should be part of the bundle by setting
22
+ # an environment variable. This of course also works when using the Gemfile.local
23
+ #
24
+ # bundle foo # dm-sqlite-adapter
25
+ # ADAPTER=mysql bundle foo # dm-mysql-adapter
26
+ # ADAPTERS=sqlite,mysql bundle foo # dm-sqlite-adapter and dm-mysql-adapter
27
+ #
28
+ # Of course you can also use the ADAPTER(S) variable when using the Gemfile.local
29
+ # and running specs against selected adapters.
30
+ #
31
+ # For easily working with adapters supported on your machine, it's recommended
32
+ # that you first install all adapters that you are planning to use or work on
33
+ # by doing something like
34
+ #
35
+ # ADAPTERS=sqlite,mysql,postgres bundle install
36
+ #
37
+ # This will clone the various repositories and make them available to bundler.
38
+ # Once you have them installed you can easily switch between adapters for the
39
+ # various development tasks. Running something like
40
+ #
41
+ # ADAPTER=mysql bundle exec rake spec
42
+ #
43
+ # will make sure that the dm-mysql-adapter is part of the bundle, and will be used
44
+ # when running the specs.
45
+ #
46
+ # You can also specify which plugin(s) should be part of the bundle by setting
47
+ # an environment variable. This also works when using the Gemfile.local
48
+ #
49
+ # bundle foo # dm-migrations
50
+ # PLUGINS=dm-validations bundle foo # dm-migrations and dm-validations
51
+ # PLUGINS=dm-validations,dm-types bundle foo # dm-migrations, dm-validations and dm-types
52
+ #
53
+ # Of course you can combine the PLUGIN(S) and ADAPTER(S) env vars to run specs
54
+ # for certain adapter/plugin combinations.
55
+ #
56
+ # Finally, to speed up running specs and other tasks, it's recommended to run
57
+ #
58
+ # bundle lock
59
+ #
60
+ # after running 'bundle install' for the first time. This will make 'bundle exec' run
61
+ # a lot faster compared to the unlocked version. With an unlocked bundle you would
62
+ # typically just run 'bundle install' from time to time to fetch the latest sources from
63
+ # upstream. When you locked your bundle, you need to run
64
+ #
65
+ # bundle install --relock
66
+ #
67
+ # to make sure to fetch the latest updates and then lock the bundle again. Gemfile.lock
68
+ # is added to the .gitignore file, so you don't need to worry about accidentally checking
69
+ # it into version control.
70
+
71
+ source 'http://rubygems.org'
72
+
73
+ DATAMAPPER = 'git://github.com/datamapper'
74
+ DM_VERSION = '~> 1.0.0.rc1'
75
+
76
+ group :runtime do # Runtime dependencies (as in the gemspec)
77
+
78
+ if ENV['EXTLIB']
79
+ gem 'extlib', '~> 0.9.15', :git => "#{DATAMAPPER}/extlib.git"
80
+ else
81
+ gem 'activesupport', '~> 3.0.0.beta3', :git => 'git://github.com/rails/rails.git', :require => nil
82
+ end
83
+
84
+ gem 'dm-core', DM_VERSION, :git => "#{DATAMAPPER}/dm-core.git"
85
+
86
+ end
87
+
88
+ group(:development) do # Development dependencies (as in the gemspec)
89
+
90
+ gem 'rake', '~> 0.8.7'
91
+ gem 'rspec', '~> 1.3'
92
+ gem 'jeweler', '~> 1.4'
93
+
94
+ end
95
+
96
+ group :quality do # These gems contain rake tasks that check the quality of the source code
97
+
98
+ gem 'metric_fu', '~> 1.3'
99
+ gem 'rcov', '~> 0.9.7'
100
+ gem 'reek', '~> 1.2.7'
101
+ gem 'roodi', '~> 2.1'
102
+ gem 'yard', '~> 0.5'
103
+ gem 'yardstick', '~> 0.1'
104
+
105
+ end
106
+
107
+ group :datamapper do # We need this because we want to pin these dependencies to their git master sources
108
+
109
+ adapters = ENV['ADAPTER'] || ENV['ADAPTERS']
110
+ adapters = adapters.to_s.gsub(',',' ').split(' ') - ['in_memory']
111
+
112
+ unless adapters.empty?
113
+
114
+ DO_VERSION = '~> 0.10.2'
115
+ DM_DO_ADAPTERS = %w[sqlite postgres mysql oracle sqlserver]
116
+
117
+ gem 'data_objects', DO_VERSION, :git => "#{DATAMAPPER}/do.git"
118
+
119
+ adapters.each do |adapter|
120
+ if DM_DO_ADAPTERS.any? { |dm_do_adapter| dm_do_adapter =~ /#{adapter}/ }
121
+ adapter = 'sqlite3' if adapter == 'sqlite'
122
+ gem "do_#{adapter}", DO_VERSION, :git => "#{DATAMAPPER}/do.git"
123
+ end
124
+ end
125
+
126
+ gem 'dm-do-adapter', DM_VERSION, :git => "#{DATAMAPPER}/dm-do-adapter.git"
127
+
128
+ adapters.each do |adapter|
129
+ gem "dm-#{adapter}-adapter", DM_VERSION, :git => "#{DATAMAPPER}/dm-#{adapter}-adapter.git"
130
+ end
131
+
132
+ end
133
+
134
+ plugins = ENV['PLUGINS'] || ENV['PLUGIN']
135
+ plugins = (plugins.to_s.gsub(',',' ').split(' ') + ['dm-migrations']).uniq
136
+
137
+ plugins.each do |plugin|
138
+ gem plugin, DM_VERSION, :git => "#{DATAMAPPER}/#{plugin}.git"
139
+ end
140
+
141
+ end
data/Rakefile CHANGED
@@ -15,10 +15,9 @@ begin
15
15
 
16
16
  gem.rubyforge_project = 'datamapper'
17
17
 
18
- gem.add_dependency 'dm-core', '~> 0.10.2'
18
+ gem.add_dependency 'dm-core', '~> 1.0.0.rc1'
19
19
 
20
- gem.add_development_dependency 'rspec', '~> 1.2.9'
21
- gem.add_development_dependency 'yard', '~> 0.4.0'
20
+ gem.add_development_dependency 'rspec', '~> 1.3'
22
21
  end
23
22
 
24
23
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.2
1
+ 1.0.0.rc1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dm-is-state_machine}
8
- s.version = "0.10.2"
8
+ s.version = "1.0.0.rc1"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David James"]
12
- s.date = %q{2009-12-11}
12
+ s.date = %q{2010-05-19}
13
13
  s.description = %q{DataMapper plugin for creating state machines}
14
14
  s.email = %q{djwonk [a] collectiveinsight [d] net}
15
15
  s.extra_rdoc_files = [
@@ -17,7 +17,9 @@ Gem::Specification.new do |s|
17
17
  "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
- "LICENSE",
20
+ ".gitignore",
21
+ "Gemfile",
22
+ "LICENSE",
21
23
  "README.rdoc",
22
24
  "Rakefile",
23
25
  "VERSION",
@@ -33,8 +35,10 @@ Gem::Specification.new do |s|
33
35
  "spec/examples/invalid_states.rb",
34
36
  "spec/examples/invalid_transitions_1.rb",
35
37
  "spec/examples/invalid_transitions_2.rb",
38
+ "spec/examples/light_switch.rb",
36
39
  "spec/examples/slot_machine.rb",
37
40
  "spec/examples/traffic_light.rb",
41
+ "spec/integration/inheritance_spec.rb",
38
42
  "spec/integration/invalid_events_spec.rb",
39
43
  "spec/integration/invalid_states_spec.rb",
40
44
  "spec/integration/invalid_transitions_spec.rb",
@@ -50,6 +54,7 @@ Gem::Specification.new do |s|
50
54
  "spec/unit/dsl/state_dsl_spec.rb",
51
55
  "spec/unit/state_machine_spec.rb",
52
56
  "tasks/ci.rake",
57
+ "tasks/local_gemfile.rake",
53
58
  "tasks/metrics.rake",
54
59
  "tasks/spec.rake",
55
60
  "tasks/yard.rake",
@@ -59,26 +64,45 @@ Gem::Specification.new do |s|
59
64
  s.rdoc_options = ["--charset=UTF-8"]
60
65
  s.require_paths = ["lib"]
61
66
  s.rubyforge_project = %q{datamapper}
62
- s.rubygems_version = %q{1.3.5}
67
+ s.rubygems_version = %q{1.3.6}
63
68
  s.summary = %q{DataMapper plugin for creating state machines}
69
+ s.test_files = [
70
+ "spec/examples/invalid_events.rb",
71
+ "spec/examples/invalid_states.rb",
72
+ "spec/examples/invalid_transitions_1.rb",
73
+ "spec/examples/invalid_transitions_2.rb",
74
+ "spec/examples/light_switch.rb",
75
+ "spec/examples/slot_machine.rb",
76
+ "spec/examples/traffic_light.rb",
77
+ "spec/integration/inheritance_spec.rb",
78
+ "spec/integration/invalid_events_spec.rb",
79
+ "spec/integration/invalid_states_spec.rb",
80
+ "spec/integration/invalid_transitions_spec.rb",
81
+ "spec/integration/slot_machine_spec.rb",
82
+ "spec/integration/traffic_light_spec.rb",
83
+ "spec/spec_helper.rb",
84
+ "spec/unit/data/event_spec.rb",
85
+ "spec/unit/data/machine_spec.rb",
86
+ "spec/unit/data/state_spec.rb",
87
+ "spec/unit/dsl/event_dsl_spec.rb",
88
+ "spec/unit/dsl/state_dsl_spec.rb",
89
+ "spec/unit/state_machine_spec.rb"
90
+ ]
64
91
 
65
92
  if s.respond_to? :specification_version then
66
93
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
67
94
  s.specification_version = 3
68
95
 
69
96
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
70
- s.add_runtime_dependency(%q<dm-core>, ["~> 0.10.2"])
71
- s.add_development_dependency(%q<rspec>, ["~> 1.2.9"])
72
- s.add_development_dependency(%q<yard>, ["~> 0.4.0"])
97
+ s.add_runtime_dependency(%q<dm-core>, ["~> 1.0.0.rc1"])
98
+ s.add_development_dependency(%q<rspec>, ["~> 1.3"])
73
99
  else
74
- s.add_dependency(%q<dm-core>, ["~> 0.10.2"])
75
- s.add_dependency(%q<rspec>, ["~> 1.2.9"])
76
- s.add_dependency(%q<yard>, ["~> 0.4.0"])
100
+ s.add_dependency(%q<dm-core>, ["~> 1.0.0.rc1"])
101
+ s.add_dependency(%q<rspec>, ["~> 1.3"])
77
102
  end
78
103
  else
79
- s.add_dependency(%q<dm-core>, ["~> 0.10.2"])
80
- s.add_dependency(%q<rspec>, ["~> 1.2.9"])
81
- s.add_dependency(%q<yard>, ["~> 0.4.0"])
104
+ s.add_dependency(%q<dm-core>, ["~> 1.0.0.rc1"])
105
+ s.add_dependency(%q<rspec>, ["~> 1.3"])
82
106
  end
83
107
  end
84
108
 
@@ -1,3 +1,5 @@
1
+ require 'dm-core'
2
+
1
3
  require 'dm-is-state_machine/is/state_machine'
2
4
  require 'dm-is-state_machine/is/data/event'
3
5
  require 'dm-is-state_machine/is/data/machine'
@@ -68,6 +68,13 @@ module DataMapper
68
68
  pop_state_machine_context
69
69
  end
70
70
 
71
+ def inherited(base)
72
+ super
73
+ base.class_eval do
74
+ @is_state_machine = superclass.instance_variable_get(:@is_state_machine)
75
+ end
76
+ end
77
+
71
78
  protected
72
79
 
73
80
  def push_state_machine_context(label)
@@ -0,0 +1,25 @@
1
+ class LightSwitch
2
+ include DataMapper::Resource
3
+ property :id, Serial
4
+ property :type, Discriminator
5
+
6
+ is :state_machine, :initial => :off do
7
+ state :off
8
+ state :on, :enter => :on_hook
9
+
10
+ event :switch do
11
+ transition :from => :on, :to => :off
12
+ transition :from => :off, :to => :on
13
+ end
14
+ end
15
+
16
+ def on_hook
17
+ puts "Light turned on!"
18
+ end
19
+ end
20
+
21
+ class Dimmer < LightSwitch
22
+ def on_hook
23
+ puts "Lights! Camera! Action! your're on!"
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ require 'examples/light_switch'
3
+
4
+ describe 'Inherited state machine' do
5
+
6
+ it 'should not explode' do
7
+ dimmer = Dimmer.new
8
+ lambda { dimmer.switch! }.should_not raise_error(NoMethodError)
9
+ end
10
+
11
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,30 +1,11 @@
1
- require 'rubygems'
2
-
3
- # use local dm-core if running from a typical dev checkout.
4
- lib = File.join('..', '..', 'dm-core', 'lib')
5
- $LOAD_PATH.unshift(lib) if File.directory?(lib)
6
- require 'dm-core'
7
-
8
- # Support running specs with 'rake spec' and 'spec'
9
- $LOAD_PATH.unshift('lib') unless $LOAD_PATH.include?('lib')
1
+ require 'dm-core/spec/setup'
2
+ require 'dm-core/spec/lib/adapter_helpers'
10
3
 
11
4
  require 'dm-is-state_machine'
5
+ require 'dm-migrations'
12
6
 
13
- def load_driver(name, default_uri)
14
- return false if ENV['ADAPTER'] != name.to_s
7
+ DataMapper::Spec.setup
15
8
 
16
- begin
17
- DataMapper.setup(name, ENV["#{name.to_s.upcase}_SPEC_URI"] || default_uri)
18
- DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[name]
19
- true
20
- rescue LoadError => e
21
- warn "Could not load do_#{name}: #{e}"
22
- false
23
- end
9
+ Spec::Runner.configure do |config|
10
+ config.extend(DataMapper::Spec::Adapters::Helpers)
24
11
  end
25
-
26
- ENV['ADAPTER'] ||= 'sqlite3'
27
-
28
- HAS_SQLITE3 = load_driver(:sqlite3, 'sqlite3::memory:')
29
- HAS_MYSQL = load_driver(:mysql, 'mysql://localhost/dm_core_test')
30
- HAS_POSTGRES = load_driver(:postgres, 'postgres://postgres@localhost/dm_core_test')
@@ -0,0 +1,18 @@
1
+ desc "Support bundling from local source code (allows BUNDLE_GEMFILE=Gemfile.local bundle foo)"
2
+ task :local_gemfile do |t|
3
+
4
+ root = Pathname(__FILE__).dirname.parent
5
+ datamapper = root.parent
6
+
7
+ source_regex = /DATAMAPPER = 'git:\/\/github.com\/datamapper'/
8
+ gem_source_regex = /:git => \"#\{DATAMAPPER\}\/(.+?)(?:\.git)?\"/
9
+
10
+ root.join('Gemfile.local').open('w') do |f|
11
+ root.join('Gemfile').open.each do |line|
12
+ line.sub!(source_regex, "DATAMAPPER = '#{datamapper}'")
13
+ line.sub!(gem_source_regex, ':path => "#{DATAMAPPER}/\1"')
14
+ f.puts line
15
+ end
16
+ end
17
+
18
+ end
data/tasks/spec.rake CHANGED
@@ -35,7 +35,4 @@ rescue LoadError
35
35
  end
36
36
  end
37
37
 
38
- task :spec => :check_dependencies
39
- task :rcov => :check_dependencies
40
-
41
38
  task :default => :spec
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-is-state_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
4
+ prerelease: true
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ - rc1
10
+ version: 1.0.0.rc1
5
11
  platform: ruby
6
12
  authors:
7
13
  - David James
@@ -9,39 +15,37 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-12-11 00:00:00 -08:00
18
+ date: 2010-05-19 00:00:00 -07:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: dm-core
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
20
25
  requirements:
21
26
  - - ~>
22
27
  - !ruby/object:Gem::Version
23
- version: 0.10.2
24
- version:
28
+ segments:
29
+ - 1
30
+ - 0
31
+ - 0
32
+ - rc1
33
+ version: 1.0.0.rc1
34
+ type: :runtime
35
+ version_requirements: *id001
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: rspec
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
30
40
  requirements:
31
41
  - - ~>
32
42
  - !ruby/object:Gem::Version
33
- version: 1.2.9
34
- version:
35
- - !ruby/object:Gem::Dependency
36
- name: yard
43
+ segments:
44
+ - 1
45
+ - 3
46
+ version: "1.3"
37
47
  type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ~>
42
- - !ruby/object:Gem::Version
43
- version: 0.4.0
44
- version:
48
+ version_requirements: *id002
45
49
  description: DataMapper plugin for creating state machines
46
50
  email: djwonk [a] collectiveinsight [d] net
47
51
  executables: []
@@ -52,6 +56,8 @@ extra_rdoc_files:
52
56
  - LICENSE
53
57
  - README.rdoc
54
58
  files:
59
+ - .gitignore
60
+ - Gemfile
55
61
  - LICENSE
56
62
  - README.rdoc
57
63
  - Rakefile
@@ -68,8 +74,10 @@ files:
68
74
  - spec/examples/invalid_states.rb
69
75
  - spec/examples/invalid_transitions_1.rb
70
76
  - spec/examples/invalid_transitions_2.rb
77
+ - spec/examples/light_switch.rb
71
78
  - spec/examples/slot_machine.rb
72
79
  - spec/examples/traffic_light.rb
80
+ - spec/integration/inheritance_spec.rb
73
81
  - spec/integration/invalid_events_spec.rb
74
82
  - spec/integration/invalid_states_spec.rb
75
83
  - spec/integration/invalid_transitions_spec.rb
@@ -85,6 +93,7 @@ files:
85
93
  - spec/unit/dsl/state_dsl_spec.rb
86
94
  - spec/unit/state_machine_spec.rb
87
95
  - tasks/ci.rake
96
+ - tasks/local_gemfile.rake
88
97
  - tasks/metrics.rake
89
98
  - tasks/spec.rake
90
99
  - tasks/yard.rake
@@ -102,20 +111,43 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
111
  requirements:
103
112
  - - ">="
104
113
  - !ruby/object:Gem::Version
114
+ segments:
115
+ - 0
105
116
  version: "0"
106
- version:
107
117
  required_rubygems_version: !ruby/object:Gem::Requirement
108
118
  requirements:
109
- - - ">="
119
+ - - ">"
110
120
  - !ruby/object:Gem::Version
111
- version: "0"
112
- version:
121
+ segments:
122
+ - 1
123
+ - 3
124
+ - 1
125
+ version: 1.3.1
113
126
  requirements: []
114
127
 
115
128
  rubyforge_project: datamapper
116
- rubygems_version: 1.3.5
129
+ rubygems_version: 1.3.6
117
130
  signing_key:
118
131
  specification_version: 3
119
132
  summary: DataMapper plugin for creating state machines
120
- test_files: []
121
-
133
+ test_files:
134
+ - spec/examples/invalid_events.rb
135
+ - spec/examples/invalid_states.rb
136
+ - spec/examples/invalid_transitions_1.rb
137
+ - spec/examples/invalid_transitions_2.rb
138
+ - spec/examples/light_switch.rb
139
+ - spec/examples/slot_machine.rb
140
+ - spec/examples/traffic_light.rb
141
+ - spec/integration/inheritance_spec.rb
142
+ - spec/integration/invalid_events_spec.rb
143
+ - spec/integration/invalid_states_spec.rb
144
+ - spec/integration/invalid_transitions_spec.rb
145
+ - spec/integration/slot_machine_spec.rb
146
+ - spec/integration/traffic_light_spec.rb
147
+ - spec/spec_helper.rb
148
+ - spec/unit/data/event_spec.rb
149
+ - spec/unit/data/machine_spec.rb
150
+ - spec/unit/data/state_spec.rb
151
+ - spec/unit/dsl/event_dsl_spec.rb
152
+ - spec/unit/dsl/state_dsl_spec.rb
153
+ - spec/unit/state_machine_spec.rb