eventful.rb 0.7.0
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 +7 -0
- data/lib/Eventful/ActiveRecord/ClassMethods.rb +16 -0
- data/lib/Eventful/ActiveRecord.rb +4 -0
- data/lib/Eventful/ClassMethods.rb +39 -0
- data/lib/Eventful/Poro/ClassMethods.rb +16 -0
- data/lib/Eventful/Poro.rb +4 -0
- data/lib/Eventful.rb +33 -0
- data/lib/ObjectSpace/self.select_objects.rb +15 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3b9a8e5622060297424496b78fc52312d8cb0acf7d62d67571a8990c75cb8580
|
4
|
+
data.tar.gz: 85aaf96637073d8e8aff7375e4977e74bd20ca9834535b7635ed936d4ae1db2a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 531ffe23a894e0337cf48d29c2f96415986771cf90523f0d3d3d2e8167868443b2538fbab98e30790baeb5dc445c8ad400b3d36a0afcd18817001fe23d492fd5
|
7
|
+
data.tar.gz: 6edb8b51096c9e2addc3ddbd8d6aab373d9fa4f0b4df97a28fd5d35c3878930b2351ba1f886887553717b286ea2f49f050154d4fe9141a454c7bd82adec54d41
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Eventful/ActiveRecord/ClassMethods.rb
|
2
|
+
# Eventful::ActiveRecord::ClassMethods
|
3
|
+
|
4
|
+
module Eventful
|
5
|
+
module ActiveRecord
|
6
|
+
module ClassMethods
|
7
|
+
|
8
|
+
def active
|
9
|
+
final_state_names = stateful_states.final_states.collect(&:name).collect(&:to_s)
|
10
|
+
final_state_names_with_empty = (final_state_names.empty? ? '' : final_state_names)
|
11
|
+
where('current_state NOT IN (?)', final_state_names_with_empty).all
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Eventful/ClassMethods.rb
|
2
|
+
# Eventful::ClassMethods
|
3
|
+
|
4
|
+
module Eventful
|
5
|
+
module ClassMethods
|
6
|
+
|
7
|
+
# memory resident
|
8
|
+
def memory_run(frequency_in_seconds = 1, runtime_in_seconds = nil)
|
9
|
+
if runtime_in_seconds
|
10
|
+
expiry_time = Time.now + runtime_in_seconds
|
11
|
+
end
|
12
|
+
loop do
|
13
|
+
break if runtime_in_seconds && Time.now >= expiry_time
|
14
|
+
scheduled_run
|
15
|
+
sleep frequency_in_seconds
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# scheduled
|
20
|
+
def scheduled_run
|
21
|
+
self.active.each do |instance|
|
22
|
+
instance.transitions.each do |transition|
|
23
|
+
if instance.send("#{transition.event_name}?")
|
24
|
+
instance.send("#{transition.event_name}")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def run(frequency_in_seconds = nil, runtime_in_seconds = nil)
|
31
|
+
if frequency_in_seconds
|
32
|
+
memory_run(frequency_in_seconds, runtime_in_seconds)
|
33
|
+
else
|
34
|
+
scheduled_run
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Eventful/Poro/ClassMethods.rb
|
2
|
+
# Eventful::Poro::ClassMethods
|
3
|
+
|
4
|
+
require_relative File.join('..', '..', 'ObjectSpace', 'self.select_objects')
|
5
|
+
|
6
|
+
module Eventful
|
7
|
+
module Poro
|
8
|
+
module ClassMethods
|
9
|
+
|
10
|
+
def active
|
11
|
+
ObjectSpace.select_objects(self){|o| o.active?}
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/Eventful.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Eventful.rb
|
2
|
+
# Eventful
|
3
|
+
|
4
|
+
# 20141121, 20150112, 13
|
5
|
+
# 0.7.0
|
6
|
+
|
7
|
+
require 'Stateful'
|
8
|
+
require_relative File.join('Eventful', 'ClassMethods')
|
9
|
+
|
10
|
+
module Eventful
|
11
|
+
|
12
|
+
class << self
|
13
|
+
|
14
|
+
def load_persistence_class_methods(klass)
|
15
|
+
if defined?(ActiveRecord::Base) && klass < ActiveRecord::Base
|
16
|
+
require_relative File.join('Eventful', 'ActiveRecord')
|
17
|
+
klass.extend(Eventful::ActiveRecord::ClassMethods)
|
18
|
+
else
|
19
|
+
require_relative File.join('Eventful', 'Poro')
|
20
|
+
klass.extend(Eventful::Poro::ClassMethods)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def extended(klass)
|
25
|
+
klass.extend(Stateful)
|
26
|
+
klass.extend(Eventful::ClassMethods)
|
27
|
+
load_persistence_class_methods(klass)
|
28
|
+
end
|
29
|
+
alias_method :included, :extended
|
30
|
+
|
31
|
+
end # class << self
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# ObjectSpace/self.select_objects
|
2
|
+
# ObjectSpace.select_objects
|
3
|
+
|
4
|
+
# 20111117
|
5
|
+
# 0.0.1
|
6
|
+
|
7
|
+
module ObjectSpace
|
8
|
+
|
9
|
+
def self.select_objects(klass = Object, &block)
|
10
|
+
selected_objects = []
|
11
|
+
each_object(klass){|o| selected_objects << o if block.call(o)}
|
12
|
+
selected_objects
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eventful.rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- thoran
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: By defining predicate methods which except for the addition of '?' matches
|
14
|
+
a state machine event and then configuring an in memory or cron-based event loop,
|
15
|
+
the state machine will be able to change state automatically.
|
16
|
+
email: code@thoran.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/Eventful.rb
|
22
|
+
- lib/Eventful/ActiveRecord.rb
|
23
|
+
- lib/Eventful/ActiveRecord/ClassMethods.rb
|
24
|
+
- lib/Eventful/ClassMethods.rb
|
25
|
+
- lib/Eventful/Poro.rb
|
26
|
+
- lib/Eventful/Poro/ClassMethods.rb
|
27
|
+
- lib/ObjectSpace/self.select_objects.rb
|
28
|
+
homepage: http://github.com/thoran/Eventful
|
29
|
+
licenses:
|
30
|
+
- MIT
|
31
|
+
metadata: {}
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.8.6
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubygems_version: 3.0.3
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: Automatically change state with Stateful state machines.
|
51
|
+
test_files: []
|