rails_machine 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 9192990128344bfbd59af9da23b9381350c08734
4
- data.tar.gz: 882bb537865d1662e6e8fba8eb6bd8f7f6bb256f
3
+ metadata.gz: d7e1659eebf7238e7fbb2e3167d8b7c127a32cac
4
+ data.tar.gz: d958c76251e9b1a808c0fe2fef285b4fb73ac611
5
5
  SHA512:
6
- metadata.gz: 1874e59b1d7759c80e4d704efd758dde68f9253ef3e73deecac7cd0e0899b34c29b057ba7fe44dcc64fcdc71c576b5fe239df04f78f2a5c82b03e6aa6b5c1249
7
- data.tar.gz: 5dde52dcae7c035db92715402ab5d87e4e0a2af702a7c578f53bdd0bca7b8d32e5fa241285d7cf14f360464a2b340625afa032c99825b74b6c493c847d204a00
6
+ metadata.gz: 8a93fbde64eca07e5584b5b3fa1ab67f32e9fc9186085e4c47d19e99e9c34a63b7575a76fdbac1b43b0ef192b069bd8c274e07cfbb3227564a2529ceb7782246
7
+ data.tar.gz: 2ecd0a3bc38a722cec81539f6ad600874008c7b51af4993ab40522640fe49b6fa63df59526cbd3a9870da83db3c478a803d0c5e135d7b55124d2882250c08e8c
@@ -1,24 +1,32 @@
1
1
  module RailsMachine
2
- class Configuration
2
+ class Configuration
3
3
 
4
- attr_reader :states, :transitions
4
+ attr_reader :states, :transitions
5
5
 
6
- def initialize
7
- @states ||= []
8
- @transitions ||= {}
9
- end
6
+ def initialize
7
+ @states ||= []
8
+ @transitions ||= {}
9
+ end
10
10
 
11
- # Just runs code
12
- def run(&blk)
13
- self.instance_eval(&blk)
14
- end
11
+ # Just runs code
12
+ def run(&blk)
13
+ self.instance_eval(&blk)
14
+ end
15
15
 
16
- def state(name)
17
- @states << name
18
- end
16
+ def state(name, id: next_id)
17
+ @states << [name, id]
18
+ end
19
19
 
20
- def transition(from: :any, to: :any, guards: [])
21
- (@transitions[from] ||= [])<< { to: to, guards: guards }
22
- end
23
- end
20
+ def transition(from: :any, to: :any, guards: [])
21
+ (@transitions[from] ||= [])<< { to: to, guards: guards }
22
+ end
23
+
24
+ def next_id
25
+ if @states.empty?
26
+ 0
27
+ else
28
+ @states.map(&:second).max.next
29
+ end
30
+ end
31
+ end
24
32
  end
@@ -1,3 +1,3 @@
1
1
  module RailsMachine
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/rails_machine.rb CHANGED
@@ -28,7 +28,7 @@ module RailsMachine
28
28
 
29
29
  self.transitions = configuration.transitions
30
30
 
31
- enum state: configuration.states
31
+ enum state: Hash[configuration.states]
32
32
  end
33
33
  end
34
34
 
metadata CHANGED
@@ -1,10 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grzegorz Łuszczek
8
+ - Adrian Słapa
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
@@ -14,33 +15,34 @@ dependencies:
14
15
  name: rails
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - '>='
18
+ - - ">="
18
19
  - !ruby/object:Gem::Version
19
20
  version: '4.1'
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - '>='
25
+ - - ">="
25
26
  - !ruby/object:Gem::Version
26
27
  version: '4.1'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: sqlite3
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - '>='
32
+ - - ">="
32
33
  - !ruby/object:Gem::Version
33
34
  version: '0'
34
35
  type: :development
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - '>='
39
+ - - ">="
39
40
  - !ruby/object:Gem::Version
40
41
  version: '0'
41
42
  description: Simple implementation of state machine for Rails using enums.
42
43
  email:
43
44
  - grzegorz@piklus.pl
45
+ - adrianouno@gmail.com
44
46
  executables: []
45
47
  extensions: []
46
48
  extra_rdoc_files: []
@@ -62,12 +64,12 @@ require_paths:
62
64
  - lib
63
65
  required_ruby_version: !ruby/object:Gem::Requirement
64
66
  requirements:
65
- - - '>='
67
+ - - ">="
66
68
  - !ruby/object:Gem::Version
67
69
  version: '2.1'
68
70
  required_rubygems_version: !ruby/object:Gem::Requirement
69
71
  requirements:
70
- - - '>='
72
+ - - ">="
71
73
  - !ruby/object:Gem::Version
72
74
  version: '0'
73
75
  requirements: []