statesman 0.0.1

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.
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ describe Statesman::Transition do
4
+ describe "#initialize" do
5
+ let(:to) { :y }
6
+ let(:sort_key) { 0 }
7
+ let(:create) { Statesman::Transition.new(to, sort_key) }
8
+
9
+ specify { expect(create.to_state).to equal(to) }
10
+ specify { expect(create.created_at).to be_a(Time) }
11
+ specify { expect(create.sort_key).to be(sort_key) }
12
+
13
+ context "with metadata passed" do
14
+ let(:metadata) { { some: :hash } }
15
+ let(:create) { Statesman::Transition.new(to, sort_key, metadata) }
16
+
17
+ specify { expect(create.metadata).to eq(metadata) }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ require "support/active_record"
2
+
3
+ DB = Pathname.new("test.sqlite3")
4
+
5
+ class MyModel < ActiveRecord::Base
6
+ has_many :my_model_transitions
7
+ end
8
+
9
+ class MyModelTransition < ActiveRecord::Base
10
+ belongs_to :my_model
11
+ end
12
+
13
+ class CreateMyModelMigration < ActiveRecord::Migration
14
+ def change
15
+ create_table :my_models do |t|
16
+ t.string :current_state
17
+ t.timestamps
18
+ end
19
+ end
20
+ end
21
+
22
+ # TODO: make this a module we can extend from the app? Or a generator?
23
+ class CreateMyModelTransitionMigration < ActiveRecord::Migration
24
+ def change
25
+ create_table :my_model_transitions do |t|
26
+ t.string :to_state
27
+ t.integer :my_model_id
28
+ t.integer :sort_key
29
+ t.text :metadata
30
+ t.timestamps
31
+ end
32
+
33
+ add_index :my_model_transitions, :sort_key, unique: true
34
+ end
35
+ end
data/statesman.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'statesman/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "statesman"
8
+ spec.version = Statesman::VERSION
9
+ spec.authors = ["Harry Marr", "Andy Appleton"]
10
+ spec.email = ["developers@gocardless.com"]
11
+ spec.description = %q{A statesmanlike state machine library}
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/gocardless/statesman"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 2.14.1"
24
+ spec.add_development_dependency "guard-rspec", "~> 3.0.2"
25
+ spec.add_development_dependency "rubocop", "~> 0.12.0"
26
+ spec.add_development_dependency "guard-rubocop", "~> 0.2.2"
27
+ spec.add_development_dependency "activerecord", "~> 3.2"
28
+ spec.add_development_dependency "sqlite3", "~> 1.3.8"
29
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statesman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Harry Marr
8
+ - Andy Appleton
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: 2.14.1
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 2.14.1
56
+ - !ruby/object:Gem::Dependency
57
+ name: guard-rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 3.0.2
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 3.0.2
70
+ - !ruby/object:Gem::Dependency
71
+ name: rubocop
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 0.12.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: 0.12.0
84
+ - !ruby/object:Gem::Dependency
85
+ name: guard-rubocop
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: 0.2.2
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: 0.2.2
98
+ - !ruby/object:Gem::Dependency
99
+ name: activerecord
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ~>
103
+ - !ruby/object:Gem::Version
104
+ version: '3.2'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: '3.2'
112
+ - !ruby/object:Gem::Dependency
113
+ name: sqlite3
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: 1.3.8
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 1.3.8
126
+ description: A statesmanlike state machine library
127
+ email:
128
+ - developers@gocardless.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - .rubocop.yml
135
+ - Gemfile
136
+ - Guardfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - circle.yml
141
+ - lib/generators/statesman/migration_generator.rb
142
+ - lib/generators/statesman/templates/create_migration.rb.erb
143
+ - lib/generators/statesman/templates/transition_model.rb.erb
144
+ - lib/generators/statesman/templates/update_migration.rb.erb
145
+ - lib/generators/statesman/transition_generator.rb
146
+ - lib/statesman.rb
147
+ - lib/statesman/adapters/active_record.rb
148
+ - lib/statesman/adapters/memory.rb
149
+ - lib/statesman/callback.rb
150
+ - lib/statesman/config.rb
151
+ - lib/statesman/exceptions.rb
152
+ - lib/statesman/guard.rb
153
+ - lib/statesman/machine.rb
154
+ - lib/statesman/transition.rb
155
+ - lib/statesman/version.rb
156
+ - spec/spec_helper.rb
157
+ - spec/statesman/adapters/active_record_spec.rb
158
+ - spec/statesman/adapters/memory_spec.rb
159
+ - spec/statesman/adapters/shared_examples.rb
160
+ - spec/statesman/callback_spec.rb
161
+ - spec/statesman/config_spec.rb
162
+ - spec/statesman/guard_spec.rb
163
+ - spec/statesman/machine_spec.rb
164
+ - spec/statesman/transition_spec.rb
165
+ - spec/support/active_record.rb
166
+ - statesman.gemspec
167
+ homepage: https://github.com/gocardless/statesman
168
+ licenses:
169
+ - MIT
170
+ metadata: {}
171
+ post_install_message:
172
+ rdoc_options: []
173
+ require_paths:
174
+ - lib
175
+ required_ruby_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - '>='
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ required_rubygems_version: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - '>='
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ requirements: []
186
+ rubyforge_project:
187
+ rubygems_version: 2.0.3
188
+ signing_key:
189
+ specification_version: 4
190
+ summary: A statesmanlike state machine library
191
+ test_files:
192
+ - spec/spec_helper.rb
193
+ - spec/statesman/adapters/active_record_spec.rb
194
+ - spec/statesman/adapters/memory_spec.rb
195
+ - spec/statesman/adapters/shared_examples.rb
196
+ - spec/statesman/callback_spec.rb
197
+ - spec/statesman/config_spec.rb
198
+ - spec/statesman/guard_spec.rb
199
+ - spec/statesman/machine_spec.rb
200
+ - spec/statesman/transition_spec.rb
201
+ - spec/support/active_record.rb