finite_machine 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d446f2433a6f518e7544808a4a833528be65828871f90e4030d8999bc1c32d06
4
- data.tar.gz: 153bb83ac71842a3edbfeecd65e3542ea8901cc48b48da4614ef5f68836529e6
3
+ metadata.gz: '0927d8bb3748c70aaf7c257b64baad97fecd95f609bcfe916d5f6f017bd9483c'
4
+ data.tar.gz: b571c8bbec3efbe87c92b3d6b789a416159980cf3bf61605baef8dbb95d1aad0
5
5
  SHA512:
6
- metadata.gz: 129d5ec6575f45616d0cfaf38571429fda0c0dc8ff7b619f5d2f911eb78d9ff5f5bdb1aca262dd44cb0b5dbd8fbd535132015dd161dd6d89f32add35b8acc31d
7
- data.tar.gz: dce7cb5f1d71d22e2fe50d9420d2d7a757c931b5658de8b8e024cdd6092600583330241d9259d6ae54894e1704d19331b22c84c8d7e6fc3ded4572611ce8a0b7
6
+ metadata.gz: c7fc9e56117dd2c0f47bd58fcda2f83517feea908382160bc402638742f54b2f6541f3cdef812995f7f44c64a9d3d9852e70e4aff3a8fdaf5cf0109bfbcf7883
7
+ data.tar.gz: 05cfeb53284406a2ddb4815f11bd349b6ded5bfaa2d25b2897ed51a3913d89ed36f58e9f108f59fc5098f14131860c2e0d1d8d37735fc6ff76e2fa17cb9982a6
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## [v0.12.1] - 2019-07-12
4
+
5
+ ### Changed
6
+ * Change to relax dev dependencies versions
7
+
8
+ ### Fixed
9
+ # Fix FiniteMachine.new to stop coercing object target that responds to to_hash into options
10
+
3
11
  ## [v0.12.0] - 2018-11-11
4
12
 
5
13
  ### Added
data/README.md CHANGED
@@ -28,7 +28,7 @@
28
28
  * easy [custom object integration](#29-target)
29
29
  * natural DSL for declaring events, callbacks and exception handlers
30
30
  * [callbacks](#4-callbacks) for state and event changes
31
- * ability to check [reachable](#25-can-and-cannot) state(s)
31
+ * ability to check [reachable](#28-can-and-cannot) state(s)
32
32
  * ability to check for [terminal](#25-terminal) state(s)
33
33
  * transition [guard conditions](#38-conditional-transitions)
34
34
  * dynamic [choice pseudostates](#39-choice-pseudostates)
@@ -1394,7 +1394,7 @@ class Account < ActiveRecord::Base
1394
1394
  event :authorize, :pending => :access
1395
1395
 
1396
1396
  on_enter do |event|
1397
- target.state = state
1397
+ target.state = state.to
1398
1398
  end
1399
1399
  end
1400
1400
  end
@@ -1412,7 +1412,7 @@ Please note that you do not need to call `target.save` inside callback, it is en
1412
1412
 
1413
1413
  ### 7.3 Transactions
1414
1414
 
1415
- When using **FiniteMachine** with ActiveRecord it advisable to trigger state changes inside transactions to ensure integrity of the database. Given Account example from section 8.2 one can run event in transaction in the following way:
1415
+ When using **FiniteMachine** with ActiveRecord it advisable to trigger state changes inside transactions to ensure integrity of the database. Given Account example from section 7.2 one can run event in transaction in the following way:
1416
1416
 
1417
1417
  ```ruby
1418
1418
  ActiveRecord::Base.transaction do
@@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
6
6
  spec.name = "finite_machine"
7
7
  spec.version = FiniteMachine::VERSION
8
8
  spec.authors = ["Piotr Murach"]
9
- spec.email = [""]
9
+ spec.email = ["me@piotrmurach.com"]
10
10
  spec.description = %q{A minimal finite state machine with a straightforward syntax. You can quickly model states, add callbacks and use object-oriented techniques to integrate with ORMs.}
11
11
  spec.summary = %q{A minimal finite state machine with a straightforward syntax.}
12
12
  spec.homepage = "http://piotrmurach.github.io/finite_machine/"
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
25
25
 
26
- spec.add_development_dependency 'bundler', '>= 1.5.0', '< 2.0'
26
+ spec.add_development_dependency 'bundler', '>= 1.5'
27
27
  spec.add_development_dependency 'rspec', '~> 3.1'
28
28
  spec.add_development_dependency 'rspec-benchmark', '~> 0.4.0'
29
29
  spec.add_development_dependency 'rake'
@@ -60,8 +60,8 @@ module FiniteMachine
60
60
  # @return [FiniteMachine::StateMachine]
61
61
  #
62
62
  # @api public
63
- def new(*args, **options, &block)
64
- StateMachine.new(*args, **options, &block)
63
+ def new(*args, &block)
64
+ StateMachine.new(*args, &block)
65
65
  end
66
66
 
67
67
  # A factory method for creating reusable FiniteMachine definitions
@@ -85,7 +85,8 @@ module FiniteMachine
85
85
  # the alias for target object
86
86
  #
87
87
  # @api private
88
- def initialize(*args, **options, &block)
88
+ def initialize(*args, &block)
89
+ options = args.last.is_a?(::Hash) ? args.pop : {}
89
90
  @initial_state = DEFAULT_STATE
90
91
  @auto_methods = options.fetch(:auto_methods, true)
91
92
  @subscribers = Subscribers.new
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FiniteMachine
4
- VERSION = "0.12.0"
4
+ VERSION = "0.12.1"
5
5
  end
@@ -1,13 +1,13 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- if RUBY_VERSION > '1.9' and (ENV['COVERAGE'] || ENV['TRAVIS'])
3
+ if ENV['COVERAGE'] || ENV['TRAVIS']
4
4
  require 'simplecov'
5
5
  require 'coveralls'
6
6
 
7
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
8
8
  SimpleCov::Formatter::HTMLFormatter,
9
9
  Coveralls::SimpleCov::Formatter
10
- ]
10
+ ])
11
11
 
12
12
  SimpleCov.start do
13
13
  command_name 'spec'
@@ -189,4 +189,37 @@ RSpec.describe FiniteMachine, '#target' do
189
189
  'event save called'
190
190
  ])
191
191
  end
192
+
193
+ it "handles targets responding to :to_hash message" do
194
+ stub_const("Serializer", Class.new do
195
+ def initialize(data)
196
+ @data = data
197
+ end
198
+
199
+ def write(new_data)
200
+ @data.merge!(new_data)
201
+ end
202
+
203
+ def to_hash
204
+ @data
205
+ end
206
+ alias to_h to_hash
207
+ end)
208
+
209
+ model = Serializer.new({a: 1, b: 2})
210
+
211
+ fsm = FiniteMachine.new(model) do
212
+ initial :a
213
+
214
+ event :serialize, :a => :b
215
+
216
+ on_after :serialize do |event|
217
+ target.write(c: 3)
218
+ end
219
+ end
220
+
221
+ fsm.serialize
222
+
223
+ expect(model.to_h).to include({a: 1, b: 2, c: 3})
224
+ end
192
225
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finite_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-11 00:00:00.000000000 Z
11
+ date: 2019-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -30,20 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.5.0
34
- - - "<"
35
- - !ruby/object:Gem::Version
36
- version: '2.0'
33
+ version: '1.5'
37
34
  type: :development
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - ">="
42
39
  - !ruby/object:Gem::Version
43
- version: 1.5.0
44
- - - "<"
45
- - !ruby/object:Gem::Version
46
- version: '2.0'
40
+ version: '1.5'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: rspec
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -90,7 +84,7 @@ description: A minimal finite state machine with a straightforward syntax. You c
90
84
  quickly model states, add callbacks and use object-oriented techniques to integrate
91
85
  with ORMs.
92
86
  email:
93
- - ''
87
+ - me@piotrmurach.com
94
88
  executables: []
95
89
  extensions: []
96
90
  extra_rdoc_files: []
@@ -209,8 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
203
  - !ruby/object:Gem::Version
210
204
  version: '0'
211
205
  requirements: []
212
- rubyforge_project:
213
- rubygems_version: 2.7.3
206
+ rubygems_version: 3.0.3
214
207
  signing_key:
215
208
  specification_version: 4
216
209
  summary: A minimal finite state machine with a straightforward syntax.