strict_machine 0.2.2 → 0.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e21c71461362b2c86679c14bf638d729f47d2a0
4
- data.tar.gz: 6288394dfa44d4f18b650b35f33521ddc0b8817e
3
+ metadata.gz: 542f6cf6388b2aac07645d8b04fcfc231f4e1268
4
+ data.tar.gz: f6266610cec8fe353fad86242f4685b00809a75b
5
5
  SHA512:
6
- metadata.gz: a09633553405e5e81f27e394cff480b0126a7217189f0a3aa171b1d58140035220e763de86e07ef2e435de5e932a818402dafdfc1c1ac6bb78dd2875ee24d937
7
- data.tar.gz: 892f45b484201627e166efdbcb458c2cb220821bd3ad5e4cffe8217c0201cde461c273e1f50c643ac1ddd5ca110527615fbd7957c88e0b5956210d3f73076aca
6
+ metadata.gz: 8b6297c3b0adb649b56020bf69410024ddb4f46ce5ff6ae3827482f36b8dc9b4254bdd24cf5f3a85c2b9e3133ebaa292c19a73f5f3d4e62a2a205d98f0e3ea13
7
+ data.tar.gz: 38faa515fb26cccb1523097faee5795bd1ab532123cc9d866ba9d0b26f56ac7410df29128fb6acc842eca0a897cf6d7be24fd8eaea421c7c3bfb2aea78d0f498
data/README.md CHANGED
@@ -78,11 +78,14 @@ methods added to it:
78
78
 
79
79
  and an object's class will have:
80
80
 
81
- - `#definition` the DSL evaluation context object
82
81
  - `#strict_machine_attr` the name of the attribute to store state in
83
82
  - `#strict_machine_class` either the class containing the state machine, when
84
83
  mounting, or `self` when embedding
84
+
85
+ Also, the target class (`self` when embedding, or the state machine class when mounting) will have:
86
+
85
87
  - `#strict_machine` the DSL hook
88
+ - `#definition` the DSL evaluation context object
86
89
 
87
90
  ### Internals
88
91
 
@@ -1,7 +1,7 @@
1
1
  require_relative "ext/object"
2
2
 
3
3
  module StrictMachine
4
- VERSION = "0.2.2".freeze
4
+ VERSION = "0.2.3".freeze
5
5
 
6
6
  class << self; attr_accessor :list; end
7
7
  end
@@ -13,7 +13,7 @@ module StrictMachine
13
13
  metaclass.instance_eval do
14
14
  define_method(:definition) { dc }
15
15
  define_method(:strict_machine_class) { stored }
16
- define_method(:strict_machine_attr) { "@#{state_attr}".to_sym }
16
+ define_method(:strict_machine_attr) { state_attr }
17
17
  end
18
18
  end
19
19
  end
@@ -11,7 +11,7 @@ module StrictMachine
11
11
 
12
12
  def get_state_by_name(name)
13
13
  @states.each do |this_state|
14
- return this_state if this_state.name == name
14
+ return this_state if this_state.name == name.to_sym
15
15
  end
16
16
 
17
17
  raise StateNotFoundError, name
@@ -6,10 +6,10 @@ module StrictMachine
6
6
 
7
7
  metaclass.instance_eval do
8
8
  define_method(:strict_machine_class) { klass }
9
- define_method(:strict_machine_attr) { "@#{state_attr}".to_sym }
9
+ define_method(:strict_machine_attr) { state_attr }
10
10
  end
11
11
 
12
- self.include InstanceMethods
12
+ include InstanceMethods
13
13
  end
14
14
  end
15
15
  end
@@ -1,8 +1,12 @@
1
+ require_relative "instance_var_persistence"
2
+
1
3
  require "benchmark"
2
4
 
3
5
  module StrictMachine
4
6
  module MountStateMachine
5
7
  module InstanceMethods
8
+ include InstanceVarPersistence
9
+
6
10
  def trigger(*transitions)
7
11
  transitions.map { |t| change_state(t, state) }
8
12
 
@@ -16,7 +20,7 @@ module StrictMachine
16
20
  end
17
21
 
18
22
  def state_attr
19
- self.class.strict_machine_attr.to_s.delete("@")
23
+ self.class.strict_machine_attr.to_s
20
24
  end
21
25
 
22
26
  def states
@@ -25,22 +29,6 @@ module StrictMachine
25
29
 
26
30
  private
27
31
 
28
- def current_state_attr_value
29
- instance_variable_get state_machine_attr_name
30
- end
31
-
32
- def write_initial_state
33
- write_state(definition.initial_state_name)
34
- end
35
-
36
- def write_state(value)
37
- instance_variable_set state_machine_attr_name, value
38
- end
39
-
40
- def state_machine_attr_name
41
- self.class.strict_machine_attr
42
- end
43
-
44
32
  def definition
45
33
  self.class.strict_machine_class.definition
46
34
  end
@@ -0,0 +1,23 @@
1
+ module StrictMachine
2
+ module MountStateMachine
3
+ module InstanceVarPersistence
4
+ def current_state_attr_value
5
+ instance_variable_get state_machine_attr_name
6
+ end
7
+
8
+ def write_initial_state
9
+ write_state(definition.initial_state_name)
10
+ end
11
+
12
+ def write_state(value)
13
+ instance_variable_set state_machine_attr_name, value
14
+ end
15
+
16
+ private
17
+
18
+ def state_machine_attr_name
19
+ "@#{self.class.strict_machine_attr}"
20
+ end
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strict_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Antunes
@@ -95,6 +95,7 @@ files:
95
95
  - lib/strict_machine/mount_state_machine.rb
96
96
  - lib/strict_machine/mount_state_machine/class_methods.rb
97
97
  - lib/strict_machine/mount_state_machine/instance_methods.rb
98
+ - lib/strict_machine/mount_state_machine/instance_var_persistence.rb
98
99
  - spec/dsl_spec.rb
99
100
  - spec/dummy/dummy.rb
100
101
  - spec/dummy/dummy_state_machine.rb