wires 0.3.5 → 0.3.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.
- checksums.yaml +4 -4
- data/lib/wires/channel.rb +46 -29
- data/lib/wires/event.rb +4 -3
- data/lib/wires/time.rb +16 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b89018baa293cf418580c299f57c87efc111ff84
|
4
|
+
data.tar.gz: f99305a8263a8697bc87479f5abef918091182c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a6b46c0f31c127d9b80221ba099c6f9f8252d2e442a33828a48a0514c0f95743f6ecb03893d26497b1073c41fd12e52d9fd3bb43cce99bb031a85d08321dd4f
|
7
|
+
data.tar.gz: 700abbf49b2e3de5bd1396b89a7eef600100bcc865a649f3b0eb8274850fc7f7ae20205b11aa2a7b397111066a51b2f72e1ab09315f04b29e4548e4a55d4e7fe
|
data/lib/wires/channel.rb
CHANGED
@@ -5,11 +5,9 @@ module Wires
|
|
5
5
|
|
6
6
|
attr_reader :name
|
7
7
|
attr_reader :target_list
|
8
|
+
attr_reader :relevant_channels
|
8
9
|
|
9
|
-
def
|
10
|
-
@name = name
|
11
|
-
@target_list = Set.new
|
12
|
-
nil end
|
10
|
+
def inspect; "Channel(#{name.inspect})"; end
|
13
11
|
|
14
12
|
# Redefine this class method to use an alternate Hub
|
15
13
|
def self.hub; Hub; end
|
@@ -33,6 +31,20 @@ module Wires
|
|
33
31
|
end
|
34
32
|
end
|
35
33
|
|
34
|
+
def initialize(name)
|
35
|
+
@name = name
|
36
|
+
@target_list = Set.new
|
37
|
+
unless @@channel_hash.empty?
|
38
|
+
_relevant_init
|
39
|
+
@@channel_hash.values.each do |c|
|
40
|
+
c.send(:_test_relevance, self)
|
41
|
+
_test_relevance c
|
42
|
+
end
|
43
|
+
else
|
44
|
+
@relevant_channels = []
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
36
48
|
# Register a proc to be triggered by an event on this channel
|
37
49
|
def register(events, proc)
|
38
50
|
|
@@ -77,6 +89,8 @@ module Wires
|
|
77
89
|
# Fire an event on this channel
|
78
90
|
def fire(event, blocking:false)
|
79
91
|
|
92
|
+
raise *@not_firable if @not_firable
|
93
|
+
|
80
94
|
backtrace = caller
|
81
95
|
|
82
96
|
# Create an instance object from one of several acceptable input forms
|
@@ -99,38 +113,41 @@ module Wires
|
|
99
113
|
|
100
114
|
nil end
|
101
115
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
my_names = (self.name.is_a? Array) ? self.name : [self.name]
|
107
|
-
my_names.map {|o| (o.respond_to? :channel_name) ? o.channel_name : o.to_s}
|
116
|
+
def _relevant_init
|
117
|
+
@relevant_channels = [@@channel_star]
|
118
|
+
@my_names = (self.name.is_a? Array) ? self.name : [self.name]
|
119
|
+
@my_names.map {|o| (o.respond_to? :channel_name) ? o.channel_name : o.to_s}
|
108
120
|
.flatten(1)
|
121
|
+
_test_relevance self
|
122
|
+
end
|
123
|
+
|
124
|
+
def _test_relevance(other_chan)
|
125
|
+
if self==@@channel_star
|
126
|
+
@relevant_channels << other_chan
|
127
|
+
return
|
128
|
+
end
|
109
129
|
|
110
|
-
for my_name in my_names
|
130
|
+
for my_name in @my_names
|
111
131
|
|
112
|
-
if my_name.is_a?(Regexp) then
|
132
|
+
if my_name.is_a?(Regexp) then
|
133
|
+
@not_firable = [TypeError,
|
113
134
|
"Cannot fire on Regexp channel: #{self.name}."\
|
114
|
-
" Regexp channels can only used in event handlers."
|
115
|
-
|
116
|
-
for other_chan in @@channel_hash.values
|
117
|
-
|
118
|
-
other_name = other_chan.name
|
119
|
-
other_name = (other_name.respond_to? :channel_name) ? \
|
120
|
-
other_name.channel_name : other_name
|
121
|
-
|
122
|
-
relevant << other_chan if \
|
123
|
-
if other_name.is_a?(Regexp)
|
124
|
-
my_name =~ other_name
|
125
|
-
else
|
126
|
-
my_name.to_s == other_name.to_s
|
127
|
-
end
|
128
|
-
|
135
|
+
" Regexp channels can only used in event handlers."]
|
136
|
+
return
|
129
137
|
end
|
130
138
|
|
139
|
+
other_name = other_chan.name
|
140
|
+
other_name = (other_name.respond_to? :channel_name) ? \
|
141
|
+
other_name.channel_name : other_name
|
142
|
+
|
143
|
+
@relevant_channels << other_chan if \
|
144
|
+
!@relevant_channels.include?(other_chan) and \
|
145
|
+
if other_name.is_a?(Regexp)
|
146
|
+
my_name =~ other_name
|
147
|
+
else
|
148
|
+
my_name.to_s == other_name.to_s
|
149
|
+
end
|
131
150
|
end
|
132
|
-
|
133
|
-
return relevant.uniq
|
134
151
|
end
|
135
152
|
|
136
153
|
# Compare matching with another Channel
|
data/lib/wires/event.rb
CHANGED
@@ -42,9 +42,10 @@ module Wires
|
|
42
42
|
|
43
43
|
# Convert class <ClassNameEvent> to string "class_name"
|
44
44
|
def codestring(cls=self)
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
@codestring ||= \
|
46
|
+
File.basename cls.to_s
|
47
|
+
.underscore
|
48
|
+
.gsub(/_event$/, "")
|
48
49
|
end
|
49
50
|
|
50
51
|
# List of codestrings associated with this event and ancestors
|
data/lib/wires/time.rb
CHANGED
@@ -40,7 +40,7 @@ module Wires
|
|
40
40
|
def active?; @active end
|
41
41
|
def inactive?; not @active end
|
42
42
|
|
43
|
-
def ready?(at_time=Time.now);
|
43
|
+
def ready?(at_time=Time.now); @active and at_time and (at_time>=@time) end
|
44
44
|
|
45
45
|
def time_until; (@active ? [(Time.now - @time), 0].max : nil) end
|
46
46
|
|
@@ -92,6 +92,8 @@ module Wires
|
|
92
92
|
# Operate on the metaclass as a type of singleton pattern
|
93
93
|
class << self
|
94
94
|
|
95
|
+
attr_accessor :grain
|
96
|
+
|
95
97
|
# Add an event to the schedule
|
96
98
|
def add(*args)
|
97
99
|
new_item = (args.first.is_a? TimeSchedulerItem) ?
|
@@ -121,18 +123,20 @@ module Wires
|
|
121
123
|
|
122
124
|
def schedule_add(new_item)
|
123
125
|
|
124
|
-
if
|
125
|
-
|
126
|
-
new_item.fire
|
127
|
-
break unless new_item.ready?
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
if new_item.ready?(@next_pass)
|
132
|
-
Thread.new do
|
126
|
+
if @keepgoing
|
127
|
+
if new_item.ready?
|
133
128
|
loop do
|
134
|
-
new_item.
|
135
|
-
break unless new_item.ready?
|
129
|
+
new_item.fire
|
130
|
+
break unless new_item.ready?
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
if new_item.ready?(@next_pass)
|
135
|
+
Thread.new do
|
136
|
+
loop do
|
137
|
+
new_item.fire_when_ready(blocking:true)
|
138
|
+
break unless new_item.ready?(@next_pass)
|
139
|
+
end
|
136
140
|
end
|
137
141
|
end
|
138
142
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wires
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe McIlvain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport-core-ext
|