eventd 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +61 -61
- data/lib/eventd/eventd_client.rb +31 -0
- data/lib/eventd/eventd_element.rb +69 -0
- data/lib/eventd/eventd_object.rb +56 -56
- data/lib/eventd/eventd_server.rb +6 -0
- data/lib/eventd.rb +2 -2
- metadata +6 -11
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
M2E5ZmVkODExOTk5NjE2OWVkYjQ2ZWQ1Y2U4MDk3M2UxMDUwZmE4Yw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
M2JkZDNmZjQ1MGVlYzUxNDA2MGRjZmQxNDQzNzlkMmRmMTExYWY1OA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MTc4Yjc0OGMwZmQ2OGM3NGVmNmZhMjljNzZlOTRmNDEwMGEwMmM1YjhhNzI3
|
10
|
+
ZGIwOTM5YTljN2ZmNGQzODdjMDU4ZDlkZGY5YzY2YjlhOTRiZDg5NzY1Y2U1
|
11
|
+
ZWVmMWMwOGRlNjk0NWUwZjRlNjllMGIwYmRjMDFjZTJmMjI1Y2Q=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjRlMWJjNWU1NzcyZGQ4OWEyNzFmYzlhNDRjOTY3NTI0NTQ1ZDU0NmU5MTA1
|
14
|
+
NGEwYTc3YWUxM2IwZGJlNmJhZDE1M2IxM2VlNmM4OWM4OGJkYjgwODYxYjM4
|
15
|
+
OWIzMTI2MzMxOWZmMWNjNzVmYjA5ZThmZDViNTZhOTlkZmJlMGQ=
|
data/README.md
CHANGED
@@ -1,61 +1,61 @@
|
|
1
|
-
Introduction
|
2
|
-
------------
|
3
|
-
|
4
|
-
Eventd is a web socket client and server wrapper around **em-websockets**. Eventd strives to provide an event-based
|
5
|
-
structure, which provides the basis for web-socket enabled applications. Eventd implements a Server and a Client, which
|
6
|
-
both inherit from ``EventdObject``.
|
7
|
-
|
8
|
-
|
9
|
-
Installation
|
10
|
-
------------
|
11
|
-
|
12
|
-
```
|
13
|
-
gem install eventd
|
14
|
-
```
|
15
|
-
|
16
|
-
|
17
|
-
EventdObject Example
|
18
|
-
--------------------
|
19
|
-
|
20
|
-
```ruby
|
21
|
-
require 'eventd'
|
22
|
-
|
23
|
-
class Dog < EventdObject
|
24
|
-
def initialize(name)
|
25
|
-
super()
|
26
|
-
@name = name
|
27
|
-
end
|
28
|
-
|
29
|
-
def bark
|
30
|
-
self.emit 'bark'
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
vader = Dog.new 'Vader'
|
35
|
-
|
36
|
-
vader.on 'bark' do
|
37
|
-
puts 'Vader barked! OMGWTFBBQ!'
|
38
|
-
end
|
39
|
-
|
40
|
-
vader.bark
|
41
|
-
```
|
42
|
-
|
43
|
-
|
44
|
-
EventdServer Example
|
45
|
-
---------------------
|
46
|
-
|
47
|
-
```ruby
|
48
|
-
require 'eventd'
|
49
|
-
|
50
|
-
server = EventdServer.new :host => '127.0.0.1', :port => 8080
|
51
|
-
|
52
|
-
server.run do
|
53
|
-
server.on 'connection' do |client|
|
54
|
-
client.on 'hello' do
|
55
|
-
client.emit 'hello!'
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
server.start
|
61
|
-
```
|
1
|
+
Introduction
|
2
|
+
------------
|
3
|
+
|
4
|
+
Eventd is a web socket client and server wrapper around **em-websockets**. Eventd strives to provide an event-based
|
5
|
+
structure, which provides the basis for web-socket enabled applications. Eventd implements a Server and a Client, which
|
6
|
+
both inherit from ``EventdObject``.
|
7
|
+
|
8
|
+
|
9
|
+
Installation
|
10
|
+
------------
|
11
|
+
|
12
|
+
```
|
13
|
+
gem install eventd
|
14
|
+
```
|
15
|
+
|
16
|
+
|
17
|
+
EventdObject Example
|
18
|
+
--------------------
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
require 'eventd'
|
22
|
+
|
23
|
+
class Dog < EventdObject
|
24
|
+
def initialize(name)
|
25
|
+
super()
|
26
|
+
@name = name
|
27
|
+
end
|
28
|
+
|
29
|
+
def bark
|
30
|
+
self.emit 'bark'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
vader = Dog.new 'Vader'
|
35
|
+
|
36
|
+
vader.on 'bark' do
|
37
|
+
puts 'Vader barked! OMGWTFBBQ!'
|
38
|
+
end
|
39
|
+
|
40
|
+
vader.bark
|
41
|
+
```
|
42
|
+
|
43
|
+
|
44
|
+
EventdServer Example
|
45
|
+
---------------------
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
require 'eventd'
|
49
|
+
|
50
|
+
server = EventdServer.new :host => '127.0.0.1', :port => 8080
|
51
|
+
|
52
|
+
server.run do
|
53
|
+
server.on 'connection' do |client|
|
54
|
+
client.on 'hello' do
|
55
|
+
client.emit 'hello!'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
server.start
|
61
|
+
```
|
data/lib/eventd/eventd_client.rb
CHANGED
@@ -12,12 +12,19 @@
|
|
12
12
|
require 'json'
|
13
13
|
|
14
14
|
require_relative './eventd_object'
|
15
|
+
require_relative './eventd_element'
|
15
16
|
|
16
17
|
class EventdClient < EventdObject
|
17
18
|
|
18
19
|
# em-websocket socket object
|
19
20
|
attr_accessor :socket
|
20
21
|
|
22
|
+
# Initializer
|
23
|
+
#
|
24
|
+
# == Attributes
|
25
|
+
# * +socket+
|
26
|
+
# * +server+
|
27
|
+
|
21
28
|
def initialize(socket, server = nil)
|
22
29
|
super()
|
23
30
|
@socket = socket
|
@@ -25,6 +32,8 @@ class EventdClient < EventdObject
|
|
25
32
|
setup_socket unless @socket == nil
|
26
33
|
end
|
27
34
|
|
35
|
+
# Handle required events from the socket
|
36
|
+
|
28
37
|
def setup_socket
|
29
38
|
@socket.onopen do |handshake|
|
30
39
|
self.emit('connect', handshake, true)
|
@@ -50,6 +59,13 @@ class EventdClient < EventdObject
|
|
50
59
|
end
|
51
60
|
end
|
52
61
|
|
62
|
+
# Send an emission to the client side library
|
63
|
+
#
|
64
|
+
# == Attributes
|
65
|
+
# * +channel+
|
66
|
+
# * +data+
|
67
|
+
# * +local+
|
68
|
+
|
53
69
|
def emit(channel, data = nil, local = false)
|
54
70
|
super(channel, data)
|
55
71
|
|
@@ -59,6 +75,12 @@ class EventdClient < EventdObject
|
|
59
75
|
end
|
60
76
|
end
|
61
77
|
|
78
|
+
# Send a broadcast to other clients
|
79
|
+
#
|
80
|
+
# == Attributes
|
81
|
+
# * +channel+
|
82
|
+
# * +data+
|
83
|
+
|
62
84
|
def broadcast(channel, data = nil)
|
63
85
|
if @server.broadcast_channel_allowed? channel
|
64
86
|
@server.clients.each do |client| client.emit channel, data end
|
@@ -66,4 +88,13 @@ class EventdClient < EventdObject
|
|
66
88
|
self.emit 'error', "Broadcasts are not allowed on channel: #{channel}"
|
67
89
|
end
|
68
90
|
end
|
91
|
+
|
92
|
+
# Instantiate a new EventdElement
|
93
|
+
#
|
94
|
+
# == Attributes
|
95
|
+
# * +selector+
|
96
|
+
|
97
|
+
def element(selector)
|
98
|
+
EventdElement.new(selector, self)
|
99
|
+
end
|
69
100
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# EventdElement
|
2
|
+
#
|
3
|
+
# Object representation of an element on the client's page. Mimics a jQuery style API.
|
4
|
+
#
|
5
|
+
# Shot Framework - Copyright (c) Jesse Aaron Dunlap <me@jessedunlap.me>
|
6
|
+
# Licensed under the MIT License. For full licensing information, please
|
7
|
+
# see LICENSE.md. http://github.com/JesseDunlap/shot/
|
8
|
+
|
9
|
+
class EventdElement < EventdObject
|
10
|
+
# Instance of EventdClient, which is used to trigger interface emissions
|
11
|
+
attr_accessor :client
|
12
|
+
|
13
|
+
# jQuery Selector associated with the element
|
14
|
+
attr_accessor :selector
|
15
|
+
|
16
|
+
# Initializer
|
17
|
+
#
|
18
|
+
# == Attributes
|
19
|
+
# * +selector+
|
20
|
+
# * +client+
|
21
|
+
|
22
|
+
def initialize(selector, client)
|
23
|
+
super()
|
24
|
+
@selector = selector
|
25
|
+
@client = client
|
26
|
+
end
|
27
|
+
|
28
|
+
# Handles any method called, and attempts to turn it into a valid jQuery call
|
29
|
+
|
30
|
+
def method_missing(method, *attributes, &block)
|
31
|
+
self.jq method, attributes
|
32
|
+
end
|
33
|
+
|
34
|
+
# Call a jQuery method
|
35
|
+
#
|
36
|
+
# == Attribtues
|
37
|
+
# * +method+
|
38
|
+
# * +*attributes+
|
39
|
+
|
40
|
+
def jq(method, *attributes)
|
41
|
+
@client.emit "eapi_jq", {
|
42
|
+
:selector => @selector,
|
43
|
+
:method => method,
|
44
|
+
:attributes => attributes
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
# Add an event listener
|
49
|
+
#
|
50
|
+
# == Attributes
|
51
|
+
# * +event+
|
52
|
+
# * +&callback+
|
53
|
+
|
54
|
+
def on(event, &callback)
|
55
|
+
random_callback_id = SecureRandom.uuid
|
56
|
+
|
57
|
+
@client.emit "eapi_event", {
|
58
|
+
:selector => @selector,
|
59
|
+
:callback => random_callback_id,
|
60
|
+
:event => event
|
61
|
+
}
|
62
|
+
|
63
|
+
@client.on random_callback_id do
|
64
|
+
callback.call
|
65
|
+
end
|
66
|
+
|
67
|
+
super(event, callback)
|
68
|
+
end
|
69
|
+
end
|
data/lib/eventd/eventd_object.rb
CHANGED
@@ -1,57 +1,57 @@
|
|
1
|
-
# EventdObject
|
2
|
-
#
|
3
|
-
# Implements an event-based architecture centered around the concept of *channels* and *listeners*. Each channel can
|
4
|
-
# contain multiple listeners. An "emission" can be sent on a channel, which will be then sent to all corresponding
|
5
|
-
# listeners on that channel. Emissions can have optional data sent with them to the listeners.
|
6
|
-
#
|
7
|
-
# Shot Framework - Copyright (c) Jesse Aaron Dunlap <me@jessedunlap.me>
|
8
|
-
# Licensed under the MIT License. For full licensing information, please
|
9
|
-
# see LICENSE.md. http://github.com/JesseDunlap/shot/
|
10
|
-
|
11
|
-
|
12
|
-
class EventdObject
|
13
|
-
attr_accessor :events
|
14
|
-
|
15
|
-
# Initialize the EventdObject and set up the events hash.
|
16
|
-
# Note:: It is important that you always call +super()+ so that the +events+ hash can be initialized
|
17
|
-
|
18
|
-
def initialize
|
19
|
-
@events = {}
|
20
|
-
end
|
21
|
-
|
22
|
-
# Add an event listener to a specified channel
|
23
|
-
#
|
24
|
-
# == Attributes
|
25
|
-
# * +channel+ - Channel to subscribe to
|
26
|
-
# * +callback+ - Callback block, which is triggered when an emission occurs on the channel
|
27
|
-
|
28
|
-
def on(channel, &callback)
|
29
|
-
@events[channel] = (@events[channel] or [])
|
30
|
-
@events[channel].push callback
|
31
|
-
end
|
32
|
-
|
33
|
-
# Remove all event listeners from a specified channel
|
34
|
-
#
|
35
|
-
# == Attributes
|
36
|
-
# * +channel+ - Channel to unsubscribe from
|
37
|
-
|
38
|
-
def off(channel)
|
39
|
-
@events[channel] = []
|
40
|
-
end
|
41
|
-
|
42
|
-
# Send an emission on a channel
|
43
|
-
#
|
44
|
-
# == Attributes
|
45
|
-
# * +channel+ - Channel to emit on
|
46
|
-
# * +data+ - Optional. Data to send along with the emission.
|
47
|
-
|
48
|
-
def emit(channel, data = nil)
|
49
|
-
emit 'emission', { :channel => channel, :data => data } unless channel == 'emission'
|
50
|
-
|
51
|
-
@events[channel] = (@events[channel] or [])
|
52
|
-
|
53
|
-
@events[channel].each do |callback|
|
54
|
-
if data == nil then callback.call else callback.call data end
|
55
|
-
end
|
56
|
-
end
|
1
|
+
# EventdObject
|
2
|
+
#
|
3
|
+
# Implements an event-based architecture centered around the concept of *channels* and *listeners*. Each channel can
|
4
|
+
# contain multiple listeners. An "emission" can be sent on a channel, which will be then sent to all corresponding
|
5
|
+
# listeners on that channel. Emissions can have optional data sent with them to the listeners.
|
6
|
+
#
|
7
|
+
# Shot Framework - Copyright (c) Jesse Aaron Dunlap <me@jessedunlap.me>
|
8
|
+
# Licensed under the MIT License. For full licensing information, please
|
9
|
+
# see LICENSE.md. http://github.com/JesseDunlap/shot/
|
10
|
+
|
11
|
+
|
12
|
+
class EventdObject
|
13
|
+
attr_accessor :events
|
14
|
+
|
15
|
+
# Initialize the EventdObject and set up the events hash.
|
16
|
+
# Note:: It is important that you always call +super()+ so that the +events+ hash can be initialized
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@events = {}
|
20
|
+
end
|
21
|
+
|
22
|
+
# Add an event listener to a specified channel
|
23
|
+
#
|
24
|
+
# == Attributes
|
25
|
+
# * +channel+ - Channel to subscribe to
|
26
|
+
# * +callback+ - Callback block, which is triggered when an emission occurs on the channel
|
27
|
+
|
28
|
+
def on(channel, &callback)
|
29
|
+
@events[channel] = (@events[channel] or [])
|
30
|
+
@events[channel].push callback
|
31
|
+
end
|
32
|
+
|
33
|
+
# Remove all event listeners from a specified channel
|
34
|
+
#
|
35
|
+
# == Attributes
|
36
|
+
# * +channel+ - Channel to unsubscribe from
|
37
|
+
|
38
|
+
def off(channel)
|
39
|
+
@events[channel] = []
|
40
|
+
end
|
41
|
+
|
42
|
+
# Send an emission on a channel
|
43
|
+
#
|
44
|
+
# == Attributes
|
45
|
+
# * +channel+ - Channel to emit on
|
46
|
+
# * +data+ - Optional. Data to send along with the emission.
|
47
|
+
|
48
|
+
def emit(channel, data = nil)
|
49
|
+
emit 'emission', { :channel => channel, :data => data } unless channel == 'emission'
|
50
|
+
|
51
|
+
@events[channel] = (@events[channel] or [])
|
52
|
+
|
53
|
+
@events[channel].each do |callback|
|
54
|
+
if data == nil then callback.call else callback.call data end
|
55
|
+
end
|
56
|
+
end
|
57
57
|
end
|
data/lib/eventd/eventd_server.rb
CHANGED
@@ -75,6 +75,12 @@ class EventdServer < EventdObject
|
|
75
75
|
@run_callback = callback
|
76
76
|
end
|
77
77
|
|
78
|
+
# Allows you to extend the functionality of a server, through a plugin
|
79
|
+
|
80
|
+
def plugin(&callback)
|
81
|
+
callback.call self
|
82
|
+
end
|
83
|
+
|
78
84
|
# Allow any broadcast
|
79
85
|
|
80
86
|
def allow_broadcasts
|
data/lib/eventd.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
require_relative './eventd/eventd_server'
|
2
|
-
require_relative './eventd/eventd_client'
|
1
|
+
require_relative './eventd/eventd_server'
|
2
|
+
require_relative './eventd/eventd_client'
|
3
3
|
require_relative './eventd/eventd_object'
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eventd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jesse A. Dunlap
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-08-23 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: em-websocket
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: flexmock
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -52,6 +47,7 @@ extensions: []
|
|
52
47
|
extra_rdoc_files: []
|
53
48
|
files:
|
54
49
|
- lib/eventd/eventd_client.rb
|
50
|
+
- lib/eventd/eventd_element.rb
|
55
51
|
- lib/eventd/eventd_object.rb
|
56
52
|
- lib/eventd/eventd_server.rb
|
57
53
|
- lib/eventd.rb
|
@@ -60,26 +56,25 @@ files:
|
|
60
56
|
homepage: http://github.com/shot/
|
61
57
|
licenses:
|
62
58
|
- MIT
|
59
|
+
metadata: {}
|
63
60
|
post_install_message:
|
64
61
|
rdoc_options: []
|
65
62
|
require_paths:
|
66
63
|
- lib
|
67
64
|
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
-
none: false
|
69
65
|
requirements:
|
70
66
|
- - ! '>='
|
71
67
|
- !ruby/object:Gem::Version
|
72
68
|
version: '0'
|
73
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
70
|
requirements:
|
76
71
|
- - ! '>='
|
77
72
|
- !ruby/object:Gem::Version
|
78
73
|
version: '0'
|
79
74
|
requirements: []
|
80
75
|
rubyforge_project:
|
81
|
-
rubygems_version:
|
76
|
+
rubygems_version: 2.0.7
|
82
77
|
signing_key:
|
83
|
-
specification_version:
|
78
|
+
specification_version: 4
|
84
79
|
summary: A simple, clever way of adding event-based functionality to Ruby objects.
|
85
80
|
test_files: []
|