workflow_sequel_adapter 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,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-19mode
5
+ - rbx-19mode
6
+ before_script:
7
+ - sudo apt-get install -qq graphviz
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in workflow_sequel_adapter.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jack Chu
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.
@@ -0,0 +1,50 @@
1
+ # workflow_sequel_adapter
2
+
3
+ This gem is a persistence adapter for the [Workflow](http://github.com/geekq/workflow) gem. All you do is include this adapter, and `Workflow` will use the `workflow_column` to retrieve and persist the workflow state.
4
+
5
+ Workflow is a state machine gem you can include to add state machine functionality to your classes.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'workflow_sequel_adapter'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install workflow_sequel_adapter
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ class User < Sequel::Model
25
+ include Workflow
26
+ # include the adapter after including Workflow
27
+ include WorkflowSequelAdapter
28
+
29
+ # uses 'state' as the workflow_column instead of 'workflow_state'
30
+ workflow_column :state
31
+
32
+ workflow do
33
+ state :active do
34
+ event :deactivate, transition_to: :inactive
35
+ end
36
+
37
+ state :inactive do
38
+ event :activate, transition_to: :active
39
+ end
40
+ end
41
+ end
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+ task :default => :test
5
+
6
+ desc "Run tests"
7
+ task :test do
8
+ Rake::TestTask.new do |t|
9
+ t.libs << 'lib' << 'test'
10
+ t.pattern = 'test/**/*_test.rb'
11
+ t.verbose = true
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ require "workflow_sequel_adapter/version"
2
+
3
+ module WorkflowSequelAdapter
4
+ def before_validation
5
+ write_initial_state
6
+ super
7
+ end
8
+
9
+ def load_workflow_state
10
+ send self.class.workflow_column
11
+ end
12
+
13
+ def persist_workflow_state(new_value)
14
+ send "#{self.class.workflow_column}=", new_value
15
+ save_changes
16
+ end
17
+
18
+ private
19
+ def write_initial_state
20
+ if load_workflow_state.nil? || load_workflow_state == ''
21
+ send("#{self.class.workflow_column}=", current_state.to_s)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module WorkflowSequelAdapter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,40 @@
1
+ require 'sequel'
2
+ require 'workflow'
3
+ require 'workflow_sequel_adapter'
4
+ require 'minitest/autorun'
5
+
6
+ DB = Sequel.sqlite
7
+
8
+ Sequel::Model.raise_on_save_failure = false
9
+
10
+ DB.instance_eval do
11
+ create_table :users do
12
+ primary_key :id
13
+ String :email
14
+ String :password
15
+ String :state
16
+ end
17
+ end
18
+
19
+ class User < Sequel::Model
20
+ include Workflow
21
+ include WorkflowSequelAdapter
22
+
23
+ workflow_column :state
24
+
25
+ workflow do
26
+ state :active do
27
+ event :deactivate, transition_to: :inactive
28
+ end
29
+
30
+ state :inactive do
31
+ event :activate, transition_to: :active
32
+ end
33
+ end
34
+ end
35
+
36
+ class MiniTest::Spec
37
+ before do
38
+ Sequel::Model.db.from(:users).truncate
39
+ end
40
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ describe WorkflowSequelAdapter do
4
+ describe User do
5
+ before do
6
+ @user = User.create(email: 'user@example.com', password: 'password')
7
+ end
8
+
9
+ it 'starts in active state' do
10
+ @user.state.must_equal 'active'
11
+ end
12
+
13
+ describe 'in the inactive state' do
14
+ it 'transitions to the inactive state via the deactivate event' do
15
+ @user.can_deactivate?.must_equal true
16
+ @user.deactivate!
17
+ @user.state.must_equal 'inactive'
18
+ end
19
+
20
+ it 'cannot be activated if already active' do
21
+ @user.can_activate?.must_equal false
22
+ end
23
+ end
24
+
25
+ describe 'in the inactive state' do
26
+ before do
27
+ @user.deactivate!
28
+ end
29
+
30
+ it 'transitions to the active state via the activate event' do
31
+ @user.can_activate?.must_equal true
32
+ @user.activate!
33
+ @user.state.must_equal 'active'
34
+ end
35
+
36
+ it 'cannot be deactivated if already inactive' do
37
+ @user.can_deactivate?.must_equal false
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'workflow_sequel_adapter/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "workflow_sequel_adapter"
8
+ gem.version = WorkflowSequelAdapter::VERSION
9
+ gem.authors = ["Jack Chu"]
10
+ gem.email = ["kamuigt@gmail.com"]
11
+ gem.description = %q{workflow_sequel_adapter is a persistence adapter for the Workflow gem. All you do is include this adapter, and `Workflow` will use the `workflow_column` to retrieve and persist the workflow state.}
12
+ gem.summary = %q{workflow_sequel_adapter is a persistence adapter for the Workflow gem.}
13
+ gem.homepage = "http://github.com/kamui/workflow_sequel_adapter"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "workflow"
21
+ gem.add_dependency "sequel"
22
+
23
+ gem.add_development_dependency "rake"
24
+ gem.add_development_dependency "minitest"
25
+ gem.add_development_dependency "sqlite3"
26
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: workflow_sequel_adapter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jack Chu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: workflow
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sequel
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: minitest
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: sqlite3
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: workflow_sequel_adapter is a persistence adapter for the Workflow gem.
95
+ All you do is include this adapter, and `Workflow` will use the `workflow_column`
96
+ to retrieve and persist the workflow state.
97
+ email:
98
+ - kamuigt@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - .gitignore
104
+ - .travis.yml
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/workflow_sequel_adapter.rb
110
+ - lib/workflow_sequel_adapter/version.rb
111
+ - test/test_helper.rb
112
+ - test/workflow_sequel_adapter_test.rb
113
+ - workflow_sequel_adapter.gemspec
114
+ homepage: http://github.com/kamui/workflow_sequel_adapter
115
+ licenses: []
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ segments:
127
+ - 0
128
+ hash: 221529894828090429
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ segments:
136
+ - 0
137
+ hash: 221529894828090429
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 1.8.24
141
+ signing_key:
142
+ specification_version: 3
143
+ summary: workflow_sequel_adapter is a persistence adapter for the Workflow gem.
144
+ test_files:
145
+ - test/test_helper.rb
146
+ - test/workflow_sequel_adapter_test.rb