wires 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wires/channel.rb +22 -10
- data/lib/wires/convenience.rb +3 -2
- data/lib/wires/event.rb +2 -2
- 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: 95acdf9855630beb97ecabff1acb709c0251ad60
|
4
|
+
data.tar.gz: 43bd14f65cd614891e42f561bf4056245c7008c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 474fb2acc06c4a06a19239cd56d7aa8a525bcd80d43cc1426babac2c0709343e9f009d8f7006d2ac2f8ea43f5ee18af8b00c094721c24ef9a98b0d8d97cd1614
|
7
|
+
data.tar.gz: 5b3122f9bd2cf537209527ab3c672c0f5bb15a8aff194dc5db14d212375299da73344b2db3b6a06ac3f155e7c52f3a977bdc41c339bfb0b926209e1170e5adfd
|
data/lib/wires/channel.rb
CHANGED
@@ -46,19 +46,23 @@ module Wires
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# Register a proc to be triggered by an event on this channel
|
49
|
-
|
50
|
-
|
49
|
+
# Return the proc that was passed in
|
50
|
+
def register(*events, &proc)
|
51
51
|
if not proc.is_a?(Proc) then raise SyntaxError, \
|
52
52
|
"No Proc given to execute on event: #{events}" end
|
53
|
-
|
54
|
-
# Convert all events to strings
|
55
|
-
events = [events] unless events.is_a? Array
|
56
|
-
events.flatten!
|
57
|
-
events.map! { |e| (e.is_a?(Class) ? e.codestring : e.to_s) }
|
58
|
-
events.uniq!
|
59
|
-
|
53
|
+
_normalize_event_list(events)
|
60
54
|
@target_list << [events, proc]
|
61
|
-
|
55
|
+
proc
|
56
|
+
end
|
57
|
+
|
58
|
+
# Unregister a proc from the target list of this channel
|
59
|
+
# Return true if at least one matching target was unregistered, else false
|
60
|
+
def unregister(*events, &proc)
|
61
|
+
_normalize_event_list(events)
|
62
|
+
!!(@target_list.reject! do |e, p|
|
63
|
+
(proc and proc==p) and (events.map{|event| e.include? event}.all?)
|
64
|
+
end)
|
65
|
+
end
|
62
66
|
|
63
67
|
# Register hook to execute before fire - can call multiple times
|
64
68
|
def self.before_fire(retain=false, &block)
|
@@ -113,6 +117,14 @@ module Wires
|
|
113
117
|
|
114
118
|
nil end
|
115
119
|
|
120
|
+
# Convert events to array of unique codestrings
|
121
|
+
def _normalize_event_list(events)
|
122
|
+
events = [events] unless events.is_a? Array
|
123
|
+
events.flatten!
|
124
|
+
events.map! { |e| (e.is_a?(Class) ? e.codestring : e.to_s) }
|
125
|
+
events.uniq!
|
126
|
+
end
|
127
|
+
|
116
128
|
def _relevant_init
|
117
129
|
@relevant_channels = [@@channel_star]
|
118
130
|
@my_names = (self.name.is_a? Array) ? self.name : [self.name]
|
data/lib/wires/convenience.rb
CHANGED
@@ -9,9 +9,10 @@ module Wires
|
|
9
9
|
channels = [channels] unless channels.is_a? Array
|
10
10
|
for channel in channels
|
11
11
|
channel=Channel.new(channel) unless channel.is_a? Channel
|
12
|
-
channel.register(events, codeblock)
|
12
|
+
channel.register(*events, &codeblock)
|
13
13
|
end
|
14
|
-
|
14
|
+
codeblock
|
15
|
+
end
|
15
16
|
|
16
17
|
def fire(event, channel='*', **kwargs)
|
17
18
|
channel = Channel.new(channel) unless channel.is_a? Channel
|
data/lib/wires/event.rb
CHANGED
@@ -99,8 +99,8 @@ module Wires
|
|
99
99
|
for key in kwargs.keys
|
100
100
|
att = key.to_s
|
101
101
|
obj.instance_variable_set("@#{att}", kwargs[key])
|
102
|
-
class_eval
|
103
|
-
# class_eval
|
102
|
+
class_eval { attr_reader att }
|
103
|
+
# class_eval { attr_writer att }
|
104
104
|
end
|
105
105
|
|
106
106
|
obj
|
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.7
|
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-
|
11
|
+
date: 2013-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport-core-ext
|