switcher 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/switcher.rb CHANGED
@@ -46,6 +46,7 @@ module Switcher
46
46
  end
47
47
  end
48
48
  end
49
+
49
50
  end
50
51
 
51
52
  def switch(event, *args)
@@ -15,6 +15,15 @@ module Switcher
15
15
  self.instance_variable_set(:"@#{spec_name}_statement", Statement.new(self, spec, state_current, state_prev))
16
16
  end
17
17
  end
18
+
19
+ before_validation do
20
+ self.class.class_variable_get(:@@__specs__).each do |spc|
21
+ spc_name = spc.name
22
+
23
+ current_state = self.instance_variable_get(:"@#{spc.name}_statement").state_current
24
+ write_attribute(spc_name, current_state)
25
+ end
26
+ end
18
27
  end
19
28
  end
20
29
 
@@ -29,5 +29,6 @@ module Switcher
29
29
 
30
30
  true
31
31
  end
32
+
32
33
  end
33
34
  end
@@ -1,3 +1,3 @@
1
1
  module Switcher
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -74,4 +74,13 @@ describe Switcher::ActiveRecord do
74
74
  box.state_requested?.should be_true
75
75
  box.state_produced?.should be_false
76
76
  end
77
+
78
+ it "should force state" do
79
+ box.state_force(:broken)
80
+ box.save
81
+
82
+ reloaded = Box.find(box.id)
83
+
84
+ reloaded.state.should eq(:broken)
85
+ end
77
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-08 00:00:00.000000000Z
12
+ date: 2012-04-03 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70130949632800 !ruby/object:Gem::Requirement
16
+ requirement: &70245885352140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70130949632800
24
+ version_requirements: *70245885352140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70130949632380 !ruby/object:Gem::Requirement
27
+ requirement: &70245885351720 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70130949632380
35
+ version_requirements: *70245885351720
36
36
  description: Switcher is simple, event-driven state machine
37
37
  email:
38
38
  - andrey@aejis.eu