state_objects 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -0
- data/README.md +6 -8
- data/lib/state_objects/base.rb +1 -4
- data/lib/state_objects/model_additions.rb +4 -0
- data/lib/state_objects/version.rb +1 -1
- data/test/state_objects_methods_test.rb +21 -0
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 0.0.6
|
2
|
+
* adding scope with _occurs. For example:
|
3
|
+
scope :red, where(WalkLight.color_state_red_occurs ) # => "(status_option ='R')"
|
4
|
+
|
5
|
+
## v0.0.5
|
6
|
+
* (Yanked)
|
7
|
+
|
1
8
|
## v0.0.4
|
2
9
|
* Changed Gem description to focus state that Many other state machines focus on events and state transitions.
|
3
10
|
This state machine focuses on behavior.
|
data/README.md
CHANGED
@@ -58,8 +58,8 @@ Or install it yourself as:
|
|
58
58
|
LightRedState
|
59
59
|
state_object_events :color_state, :change
|
60
60
|
|
61
|
-
scope :red, where(
|
62
|
-
scope :green, where(
|
61
|
+
scope :red, where(LightRedState.occurs )
|
62
|
+
scope :green, where(LightGreenState.occurs )
|
63
63
|
end
|
64
64
|
|
65
65
|
# now lets use it
|
@@ -71,8 +71,6 @@ Or install it yourself as:
|
|
71
71
|
|
72
72
|
### adds the following CLASS METHODS to WalkLight
|
73
73
|
|
74
|
-
TODO: there may be typos in the following. It should be cleared up when I move the specs into the gem.
|
75
|
-
|
76
74
|
* color_states
|
77
75
|
returns a array of 2-value arrays suitable to fill a select tag
|
78
76
|
The second example shows how to start the selection on a blank
|
@@ -120,11 +118,11 @@ adds the following INSTANCE METHODS to WalkLight
|
|
120
118
|
<%= radio_button :walk_light, :color_state, key %> <%= value %><br />
|
121
119
|
<% end %>
|
122
120
|
|
121
|
+
### Example #4: adding scope with _occurs
|
122
|
+
It's now easy to add scopes with using _occurs, which will generate your where statement for you.
|
123
123
|
|
124
|
-
|
125
|
-
|
126
|
-
color_state_js_list
|
127
|
-
|
124
|
+
scope :red, where(WalkLight.color_state_red_occurs ) # => "(status_option ='R')"
|
125
|
+
scope :green, where(WalkLight.color_state_green_occurs ) # => "(status_option ='G')"
|
128
126
|
|
129
127
|
## Contributing
|
130
128
|
|
data/lib/state_objects/base.rb
CHANGED
@@ -2,7 +2,7 @@ module StateObjects
|
|
2
2
|
class Base
|
3
3
|
|
4
4
|
def initialize(model)
|
5
|
-
@model = model
|
5
|
+
@model = model
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.state_object_values(*opts) # :nodoc:
|
@@ -13,9 +13,6 @@ module StateObjects
|
|
13
13
|
def self.db_value
|
14
14
|
'#{opts[1]}'
|
15
15
|
end
|
16
|
-
def self.where
|
17
|
-
"(status_option ='#{opts[1]}')"
|
18
|
-
end
|
19
16
|
def self.label
|
20
17
|
'#{opts[2]}'
|
21
18
|
end
|
@@ -64,6 +64,7 @@ module StateObjects
|
|
64
64
|
def #{id}_symbol
|
65
65
|
#{id}_state_klass.symbol
|
66
66
|
end
|
67
|
+
|
67
68
|
EOF
|
68
69
|
opts.each do |option_klass|
|
69
70
|
[:symbol, :label, :db_value].each do |required_method|
|
@@ -86,6 +87,9 @@ module StateObjects
|
|
86
87
|
def #{id}_#{option_klass.symbol}!
|
87
88
|
self.#{id} = '#{letter}'
|
88
89
|
end
|
90
|
+
def self.#{id}_#{option_klass.symbol}_occurs
|
91
|
+
"(#{id} ='#{letter}')"
|
92
|
+
end
|
89
93
|
EOF2
|
90
94
|
end # opts.each
|
91
95
|
end # state_objects
|
@@ -67,6 +67,27 @@ class StateObjectsTest < Test::Unit::TestCase
|
|
67
67
|
assert target.color_state_red?
|
68
68
|
end
|
69
69
|
|
70
|
+
def test_occurs
|
71
|
+
target = @model.new
|
72
|
+
assert_equal "(color_state ='G')", @model.color_state_green_occurs
|
73
|
+
assert_equal "(color_state ='R')", @model.color_state_red_occurs
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_state_objects_db_value
|
77
|
+
assert_equal 'G', LightGreenState.db_value
|
78
|
+
assert_equal 'R', LightRedState.db_value
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_state_objects_label
|
82
|
+
assert_equal "Walk", LightGreenState.label
|
83
|
+
assert_equal "Dont Walk", LightRedState.label
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_state_objects_symbol
|
87
|
+
assert_equal :green, LightGreenState.symbol
|
88
|
+
assert_equal :red, LightRedState.symbol
|
89
|
+
end
|
90
|
+
|
70
91
|
def test_sibling_of_target_not_effected_by_class_methods
|
71
92
|
SiblingOfModelUnderTest.payment_method_options
|
72
93
|
flunk "Should throw Exception"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: state_objects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: supermodel
|