stateology 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/CHANGELOG +2 -1
  2. data/README.markdown +1 -2
  3. data/lib/stateology.rb +21 -6
  4. metadata +2 -2
data/CHANGELOG CHANGED
@@ -1,4 +1,5 @@
1
-
1
+ 13-6-09
2
+ * now supports ruby 1.9.1 and ruby 1.8.6
2
3
 
3
4
  3-12-08
4
5
  * nested states now supported
data/README.markdown CHANGED
@@ -117,12 +117,11 @@ In the above the string "hello" is passed as a parameter to the state\_entry() m
117
117
 
118
118
  * The #state method can accept either a Symbol (e.g :Happy) or a Module (e.g Happy or Sample::Happy). The following are equivalent:
119
119
  s.state :Happy #=> change state to Happy
120
+ s.state Sample::Happy #=> equivalent to above (note the fully qualified name; as Happy is a module defined under the Sample class)
120
121
 
121
122
  * The #state method can take a block; the block will be executed after the successful change of state:
122
123
  e.g s.state(:Happy) { s.hello } #=> hello method invoked immediately after change of state as it's in the block
123
124
 
124
- s.state Sample::Happy #=> equivalent to above (note the fully qualified name; as Happy is a module defined under the Sample class)
125
-
126
125
  * alternatively; if the #state method is invoked internally by another instance method of the Sample class then a fully qualified module name is not required:
127
126
  state Happy #=> Fully qualified module name not required when #state invoked in an instance method
128
127
 
data/lib/stateology.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # stateology.rb
2
2
  # (C) John Mair 2008
3
3
  # This program is distributed under the terms of the MIT License
4
+ # now supports BOTH ruby 1.8.6 and ruby 1.9.1
4
5
 
5
6
  begin
6
7
  require 'rubygems'
@@ -11,7 +12,7 @@ end
11
12
  require 'mixology'
12
13
 
13
14
  module Stateology
14
- VERSION = "0.1.8"
15
+ VERSION = "0.2.0"
15
16
 
16
17
  # alternative to 'nil'
17
18
  Default = nil
@@ -21,18 +22,25 @@ module Stateology
21
22
  c.extend(SM_Class_Methods)
22
23
  end
23
24
 
25
+
24
26
  # class methods
25
27
  module SM_Class_Methods
26
28
  def state(name, &block)
29
+
30
+ if RUBY_VERSION =~ /1.9/
31
+ pram = [false]
32
+ else
33
+ pram = []
34
+ end
27
35
 
28
36
  # if const is defined here then module_eval
29
- if constants.include?(name.to_s) && const_defined?(name) then
37
+ if const_defined?(name, *pram) then
30
38
  self.module_eval(&block)
31
39
  else
32
40
 
33
41
  m = Module.new
34
42
  # if the state is defined further up the chain then "inherit it"
35
- if constants.include?(name.to_s) && !const_defined?(name) then
43
+ if constants.include?(name) || constants.include?(name.to_s) then
36
44
  # if constant not defined here then must be inherited
37
45
  inherited_state = const_get(name)
38
46
 
@@ -50,7 +58,7 @@ module Stateology
50
58
 
51
59
  # strip the class path and return just the constant name, i.e Hello::Fren -> Fren
52
60
  def __elided_class_path(sym)
53
- "#{sym}".split(/::/).last.intern
61
+ sym.to_s.split(/::/).last.to_sym
54
62
  end
55
63
 
56
64
  def __sym_to_mod(sym)
@@ -58,8 +66,9 @@ module Stateology
58
66
  end
59
67
 
60
68
  def __mod_to_sym(mod)
69
+
61
70
  # weird case where module does not have name (i.e when a state created on the eigenclass)
62
- if mod.name == "" then
71
+ if mod.name == nil || mod.name == "" then
63
72
  class << self; self; end.constants.each do |v|
64
73
  return v.to_sym if __sym_to_mod(v.to_sym) == mod
65
74
  end
@@ -72,13 +81,19 @@ module Stateology
72
81
  # is state_name a nested state?
73
82
  def __nested_state?(new_state)
74
83
 
84
+ if RUBY_VERSION =~ /1.9/
85
+ pram = [false]
86
+ else
87
+ pram = []
88
+ end
89
+
75
90
  # test is:
76
91
  # (1) are we currently in a state? (non nil)
77
92
  # (2) is the new state a state? (non nil)
78
93
  # (3) is the new state defined under the current state? (i.e it's nested)
79
94
  __current_state &&
80
95
  new_state &&
81
- __current_state.const_defined?(__elided_class_path(__mod_to_sym(new_state)))
96
+ __current_state.const_defined?(__elided_class_path(__mod_to_sym(new_state)), *pram)
82
97
  end
83
98
 
84
99
  # instance methods
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stateology
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mair
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-03 00:00:00 +13:00
12
+ date: 2009-06-13 00:00:00 +12:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency