yasm 0.0.3 → 0.0.6

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.
@@ -0,0 +1,33 @@
1
+ module Yasm
2
+ module Context
3
+ class StateConfiguration
4
+ class ActionHook
5
+ attr_reader :method
6
+
7
+ def initialize(method, options={})
8
+ @method = method
9
+ @only = [options[:only]].flatten.compact
10
+ @except = [options[:except]].flatten.compact
11
+ end
12
+
13
+ def applicable?(action)
14
+ if @only.empty? and @except.empty?
15
+ true
16
+ elsif !@only.empty?
17
+ if @only.include?(action)
18
+ true
19
+ else
20
+ false
21
+ end
22
+ elsif !@except.empty?
23
+ if @except.include?(action)
24
+ false
25
+ else
26
+ true
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -7,12 +7,13 @@ module Yasm
7
7
  def initialize(options)
8
8
  @context = options[:context]
9
9
  @state = options[:state]
10
+ @name = options[:name]
10
11
  end
11
12
 
12
13
  def value; state; end
13
14
 
14
15
  def state
15
- check_maximum
16
+ fast_forward
16
17
  @state
17
18
  end
18
19
 
@@ -26,13 +27,15 @@ module Yasm
26
27
 
27
28
  def do!(*actions)
28
29
  actions.each do |action|
30
+ run_before_action_hooks action
29
31
  fire! action
32
+ run_after_action_hooks action
30
33
  end
31
34
  end
32
35
 
33
36
  private
34
37
  def fire!(action)
35
- check_maximum
38
+ fast_forward
36
39
 
37
40
  # Verify that the action is possible given the current state
38
41
  if !@state.reached_minimum_time_limit?
@@ -51,13 +54,13 @@ module Yasm
51
54
  Yasm::Manager.execute_action action
52
55
  end
53
56
 
54
- def check_maximum
57
+ def fast_forward
55
58
  while @state.passed_maximum_time_limit?
56
59
  # setup the action that should be performed when a state has lasted too long
57
60
  action = Yasm::Manager.setup_action(
58
- :action => @state.class.maximum_duration_action,
59
- :context => context,
60
- :state_container => self
61
+ :action => @state.class.maximum_duration_action,
62
+ :context => context,
63
+ :state_container => self
61
64
  )
62
65
 
63
66
  # update the state
@@ -71,6 +74,26 @@ module Yasm
71
74
  Yasm::Manager.execute_action action
72
75
  end
73
76
  end
77
+
78
+ def run_before_action_hooks(action)
79
+ action = symbol action
80
+ context.class.state_configurations[@name].before_actions.each do |action_hook|
81
+ context.send action_hook.method if action_hook.applicable?(action)
82
+ end
83
+ end
84
+
85
+ def run_after_action_hooks(action)
86
+ action = symbol action
87
+ context.class.state_configurations[@name].after_actions.each do |action_hook|
88
+ context.send action_hook.method if action_hook.applicable?(action)
89
+ end
90
+ end
91
+
92
+ def symbol(obj)
93
+ obj = obj.class unless obj.class == Class
94
+ obj = obj.to_sym
95
+ obj
96
+ end
74
97
  end
75
98
  end
76
99
  end
@@ -0,0 +1 @@
1
+ require 'yasm/persistence/couchrest_model'
@@ -0,0 +1,46 @@
1
+ module Yasm
2
+ module Persistence
3
+ module CouchRest
4
+ module Model
5
+ def self.included(base)
6
+ base.extend GetMethods
7
+ base.before_save :save_yasm_states
8
+ class << base
9
+ alias_method_chain :get, :load_yasm_states
10
+ alias_method_chain :find, :load_yasm_states
11
+ end
12
+ end
13
+
14
+ module GetMethods
15
+ def get_with_load_yasm_states(id, db = database)
16
+ doc = get_without_load_yasm_states id, db
17
+ doc.class.state_configurations.keys.each do |state_name|
18
+ Yasm::Manager.change_state(
19
+ :to => doc["yasm"]["states"][state_name.to_s]["class"].to_sym.to_class,
20
+ :on => doc.send(:state_container, state_name.to_sym),
21
+ :at => Time.parse(doc["yasm"]["states"][state_name.to_s]["instantiated_at"])
22
+ )
23
+ end if doc["yasm"] and doc["yasm"]["states"]
24
+ doc.fast_forward
25
+ doc
26
+ end
27
+
28
+ alias :find_with_load_yasm_states :get_with_load_yasm_states
29
+ end
30
+
31
+ private
32
+ def save_yasm_states
33
+ self["yasm"] ||= {}
34
+ self["yasm"]["states"] ||= {}
35
+ self.class.state_configurations.keys.each do |state_name|
36
+ container = state_container state_name
37
+ self["yasm"]["states"][state_name] = {
38
+ :class => container.value.class.to_s,
39
+ :instantiated_at => container.value.instantiated_at
40
+ }
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,58 +1,27 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
1
  Gem::Specification.new do |s|
7
2
  s.name = %q{yasm}
8
- s.version = "0.0.3"
3
+ s.version = File.read "VERSION"
9
4
 
10
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
6
  s.authors = ["Matt Parker"]
12
- s.date = %q{2011-02-17}
7
+ s.date = %q{2011-02-23}
13
8
  s.description = %q{Breaks up states, actions, and contexts into seperate classes.moonmaster9000@gmail.com}
14
9
  s.email = %q{moonmaster9000@gmail.com}
15
10
  s.extra_rdoc_files = [
16
11
  "README.markdown"
17
12
  ]
18
- s.files = [
19
- "VERSION",
20
- "lib/yasm.rb",
21
- "lib/yasm/action.rb",
22
- "lib/yasm/context.rb",
23
- "lib/yasm/context/anonymous_state_identifier.rb",
24
- "lib/yasm/context/state_configuration.rb",
25
- "lib/yasm/context/state_container.rb",
26
- "lib/yasm/conversions.rb",
27
- "lib/yasm/conversions/class.rb",
28
- "lib/yasm/conversions/symbol.rb",
29
- "lib/yasm/exceptions.rb",
30
- "lib/yasm/exceptions/final_state_exception.rb",
31
- "lib/yasm/exceptions/invalid_action_exception.rb",
32
- "lib/yasm/exceptions/time_limit_not_yet_reached.rb",
33
- "lib/yasm/manager.rb",
34
- "lib/yasm/state.rb",
35
- "lib/yasm/version.rb",
36
- "yasm.gemspec"
37
- ]
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ #s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+
38
18
  s.homepage = %q{http://github.com/moonmaster9000/yasm}
39
19
  s.require_paths = ["lib"]
40
20
  s.rubygems_version = %q{1.5.0}
41
21
  s.summary = %q{Yet Another State Machine. Pronounced "yaz-um."}
42
-
43
- if s.respond_to? :specification_version then
44
- s.specification_version = 3
45
-
46
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
- s.add_runtime_dependency(%q<activesupport>, ["~> 3.0"])
48
- s.add_runtime_dependency(%q<i18n>, ["~> 0.5.0"])
49
- else
50
- s.add_dependency(%q<activesupport>, ["~> 3.0"])
51
- s.add_dependency(%q<i18n>, ["~> 0.5.0"])
52
- end
53
- else
54
- s.add_dependency(%q<activesupport>, ["~> 3.0"])
55
- s.add_dependency(%q<i18n>, ["~> 0.5.0"])
56
- end
22
+
23
+ s.add_dependency(%q<activesupport>, ["~> 3.0"])
24
+ s.add_dependency(%q<i18n>, ["~> 0.5.0"])
25
+ s.add_development_dependency(%q<couchrest_model>, [">= 0"])
26
+ s.add_development_dependency(%q<cucumber>, ["~> 0.10.0"])
57
27
  end
58
-
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yasm
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Parker
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-17 00:00:00 -05:00
18
+ date: 2011-02-23 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -49,6 +49,36 @@ dependencies:
49
49
  version: 0.5.0
50
50
  type: :runtime
51
51
  version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: couchrest_model
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ type: :development
65
+ version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: cucumber
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 55
75
+ segments:
76
+ - 0
77
+ - 10
78
+ - 0
79
+ version: 0.10.0
80
+ type: :development
81
+ version_requirements: *id004
52
82
  description: Breaks up states, actions, and contexts into seperate classes.moonmaster9000@gmail.com
53
83
  email: moonmaster9000@gmail.com
54
84
  executables: []
@@ -58,12 +88,31 @@ extensions: []
58
88
  extra_rdoc_files:
59
89
  - README.markdown
60
90
  files:
91
+ - .gitignore
92
+ - CHANGELOG
93
+ - Gemfile
94
+ - PUBLIC_DOMAIN
95
+ - README.markdown
61
96
  - VERSION
97
+ - features/action_callbacks.feature
98
+ - features/actions.feature
99
+ - features/final_states.feature
100
+ - features/persistance/couchrest_model_persistance.feature
101
+ - features/state_with_limited_actions.feature
102
+ - features/states_with_time_limits.feature
103
+ - features/step_definitions/action_callback_steps.rb
104
+ - features/step_definitions/action_steps.rb
105
+ - features/step_definitions/final_state_steps.rb
106
+ - features/step_definitions/persistence/couchrest_model_persistence_steps.rb
107
+ - features/step_definitions/state_with_limited_actions_steps.rb
108
+ - features/step_definitions/states_with_time_limits_steps.rb
109
+ - features/support/setup.rb
62
110
  - lib/yasm.rb
63
111
  - lib/yasm/action.rb
64
112
  - lib/yasm/context.rb
65
113
  - lib/yasm/context/anonymous_state_identifier.rb
66
114
  - lib/yasm/context/state_configuration.rb
115
+ - lib/yasm/context/state_configuration/action_hook.rb
67
116
  - lib/yasm/context/state_container.rb
68
117
  - lib/yasm/conversions.rb
69
118
  - lib/yasm/conversions/class.rb
@@ -73,10 +122,11 @@ files:
73
122
  - lib/yasm/exceptions/invalid_action_exception.rb
74
123
  - lib/yasm/exceptions/time_limit_not_yet_reached.rb
75
124
  - lib/yasm/manager.rb
125
+ - lib/yasm/persistence.rb
126
+ - lib/yasm/persistence/couchrest_model.rb
76
127
  - lib/yasm/state.rb
77
128
  - lib/yasm/version.rb
78
129
  - yasm.gemspec
79
- - README.markdown
80
130
  has_rdoc: true
81
131
  homepage: http://github.com/moonmaster9000/yasm
82
132
  licenses: []
@@ -111,5 +161,17 @@ rubygems_version: 1.5.0
111
161
  signing_key:
112
162
  specification_version: 3
113
163
  summary: Yet Another State Machine. Pronounced "yaz-um."
114
- test_files: []
115
-
164
+ test_files:
165
+ - features/action_callbacks.feature
166
+ - features/actions.feature
167
+ - features/final_states.feature
168
+ - features/persistance/couchrest_model_persistance.feature
169
+ - features/state_with_limited_actions.feature
170
+ - features/states_with_time_limits.feature
171
+ - features/step_definitions/action_callback_steps.rb
172
+ - features/step_definitions/action_steps.rb
173
+ - features/step_definitions/final_state_steps.rb
174
+ - features/step_definitions/persistence/couchrest_model_persistence_steps.rb
175
+ - features/step_definitions/state_with_limited_actions_steps.rb
176
+ - features/step_definitions/states_with_time_limits_steps.rb
177
+ - features/support/setup.rb