orator 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/orator/base.rb CHANGED
@@ -22,7 +22,8 @@ module Orator
22
22
  # @return [Array<Object>, nil] the values of the trigger, or nil if the
23
23
  # event was prevented.
24
24
  def __trigger(event, *args)
25
- orator, method_name = event.to_s.split('.')
25
+ orator = event[0..event.index('.')-1]
26
+ method_name = event[event.index('.')+1..-1]
26
27
  __check_event(orator, method_name)
27
28
 
28
29
  @event = [orator, method_name]
data/lib/orator/client.rb CHANGED
@@ -39,6 +39,15 @@ module Orator
39
39
  def trigger(event, *args)
40
40
  event_handler.trigger(event, context, *args)
41
41
  end
42
-
42
+
43
+ # This is here just in case anyone gets the bright idea to serialize the
44
+ # client with Oj. This should not happen, because it could reveal
45
+ # information that you may not want to be revealed.
46
+ #
47
+ # @return [Hash]
48
+ def to_hash
49
+ context.table
50
+ end
51
+
43
52
  end
44
53
  end
@@ -41,7 +41,8 @@ module Orator
41
41
 
42
42
  # This triggers the events. The events aren't triggered in any particular
43
43
  # order, since they are stored in a [Set]. Extra arguments are passed to
44
- # the block/class.
44
+ # the block/class. If no events are found, it runs the `socket.missing`
45
+ # event.
45
46
  #
46
47
  # @param event [String, Symbol] the event to trigger.
47
48
  # @param context [Object] the context to run in. If the event is mapped to
@@ -50,11 +51,14 @@ module Orator
50
51
  # @return [Object, nil]
51
52
  def trigger(event, context, *args)
52
53
  puts "Running event #{event}..." if Orator.debug
53
- events(event).map do |event|
54
+ if events(event).map do |event|
54
55
  puts "Found responder #{event[:block] || event[:class]}" if Orator.debug
55
56
 
56
57
  run_event(event, context, args)
57
58
  if event[:count] then event[:count] -= 1 end
59
+ end.length == 0
60
+ puts "could not find event, running socket.missing..." if Orator.debug
61
+ events('socket.missing').map { |e| run_event(e, context, args) }
58
62
  end
59
63
 
60
64
  clear_events
@@ -8,10 +8,16 @@ module Orator
8
8
  # @return [Client]
9
9
  attr_reader :client
10
10
 
11
+ # Provides access to the list of clients that are connected.
12
+ #
13
+ # @return [Set<Client>]
14
+ attr_accessor :clients
15
+
11
16
  # Initialize the class.
12
- def initialize(client)
13
- @client = client
14
- @struct = ::Orator::OpenStruct.new
17
+ def initialize(client, clients)
18
+ @client = client
19
+ @clients = clients
20
+ @struct = ::Orator::OpenStruct.new
15
21
  end
16
22
 
17
23
  # This sends a message to the client.
@@ -19,7 +25,7 @@ module Orator
19
25
  # @param data [Hash] the data to be sent to the client.
20
26
  # @return [void]
21
27
  def send(data)
22
- @client.socket.send Oj.dump(data, :mode => :null)
28
+ @client.socket.send Oj.dump(data, :mode => :compat)
23
29
  end
24
30
 
25
31
  # This builds a message from a hash and an event.
data/lib/orator/server.rb CHANGED
@@ -40,9 +40,9 @@ module Orator
40
40
  #
41
41
  # @param [Object]
42
42
  def handle_socket(socket)
43
- client = Client.new :event_handler => @event_handler.dup,
43
+ client = Client.new :event_handler => @event_handler.dup,
44
44
  :socket => socket, :context => nil
45
- client.context = MiddleGround.new(client)
45
+ client.context = MiddleGround.new(client, clients)
46
46
  clients << client
47
47
 
48
48
  socket.onopen do |handshake|
@@ -66,5 +66,5 @@ module Orator
66
66
  end
67
67
 
68
68
  end
69
-
69
+
70
70
  end
@@ -1,5 +1,5 @@
1
1
  module Orator
2
2
 
3
3
  # Version of Orator.
4
- VERSION = '0.5.1'
4
+ VERSION = '0.6.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Jeremy Rodi
@@ -13,6 +14,7 @@ dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: em-websocket
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: oj
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ~>
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ~>
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: swf_fu
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ~>
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ~>
53
60
  - !ruby/object:Gem::Version
@@ -55,6 +62,7 @@ dependencies:
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: rspec
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ~>
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ~>
67
76
  - !ruby/object:Gem::Version
@@ -75,65 +84,65 @@ executables:
75
84
  extensions: []
76
85
  extra_rdoc_files: []
77
86
  files:
87
+ - lib/tasks/orator.rake
88
+ - lib/orator.rb
89
+ - lib/orator/engine.rb
90
+ - lib/orator/server.rb
91
+ - lib/orator/base.rb
78
92
  - lib/orator/middle_ground.rb
93
+ - lib/orator/event_handler.rb
94
+ - lib/orator/open_struct.rb
79
95
  - lib/orator/version.rb
80
- - lib/orator/server.rb
81
96
  - lib/orator/cli.rb
82
97
  - lib/orator/client.rb
83
- - lib/orator/open_struct.rb
84
- - lib/orator/engine.rb
85
- - lib/orator/base.rb
86
- - lib/orator/event_handler.rb
87
- - lib/generators/orator/orator_generator.rb
88
- - lib/generators/orator/config_generator.rb
98
+ - lib/generators/templates/template_orator.rb
89
99
  - lib/generators/templates/config.yml
90
100
  - lib/generators/templates/orators/example_orator.rb
91
101
  - lib/generators/templates/orators/application_orator.rb
92
- - lib/generators/templates/template_orator.rb
93
- - lib/orator.rb
94
- - lib/tasks/orator.rake
102
+ - lib/generators/orator/config_generator.rb
103
+ - lib/generators/orator/orator_generator.rb
95
104
  - bin/orator
96
- - spec/client_spec.rb
97
- - spec/spec_helper.rb
105
+ - spec/event_handler_spec.rb
98
106
  - spec/middle_ground_spec.rb
107
+ - spec/client_spec.rb
99
108
  - spec/base_orator_spec.rb
100
- - spec/event_handler_spec.rb
101
- - vendor/assets/javascripts/orator/middle_ground.coffee
102
- - vendor/assets/javascripts/orator/swfobject.js
103
- - vendor/assets/javascripts/orator/command_handler.coffee
104
- - vendor/assets/javascripts/orator/event_handler.coffee
105
- - vendor/assets/javascripts/orator/chat_logger.coffee
109
+ - spec/spec_helper.rb
110
+ - vendor/assets/swfs/WebSocketMain.swf
111
+ - vendor/assets/javascripts/orator.coffee
106
112
  - vendor/assets/javascripts/orator/web_socket.js
107
- - vendor/assets/javascripts/orator/strbuf.coffee
108
113
  - vendor/assets/javascripts/orator/stringify.jquery.js
109
114
  - vendor/assets/javascripts/orator/header.coffee
110
- - vendor/assets/javascripts/orator.coffee
111
- - vendor/assets/swfs/WebSocketMain.swf
115
+ - vendor/assets/javascripts/orator/event_handler.coffee
116
+ - vendor/assets/javascripts/orator/chat_logger.coffee
117
+ - vendor/assets/javascripts/orator/swfobject.js
118
+ - vendor/assets/javascripts/orator/command_handler.coffee
119
+ - vendor/assets/javascripts/orator/strbuf.coffee
120
+ - vendor/assets/javascripts/orator/middle_ground.coffee
112
121
  - README.md
113
122
  - Rakefile
114
123
  - LICENSE
115
124
  homepage: http://github.com/redjazz96/orator
116
125
  licenses: []
117
- metadata: {}
118
126
  post_install_message:
119
127
  rdoc_options: []
120
128
  require_paths:
121
129
  - lib
122
130
  required_ruby_version: !ruby/object:Gem::Requirement
131
+ none: false
123
132
  requirements:
124
133
  - - ! '>='
125
134
  - !ruby/object:Gem::Version
126
135
  version: '0'
127
136
  required_rubygems_version: !ruby/object:Gem::Requirement
137
+ none: false
128
138
  requirements:
129
139
  - - ! '>='
130
140
  - !ruby/object:Gem::Version
131
141
  version: '0'
132
142
  requirements: []
133
143
  rubyforge_project:
134
- rubygems_version: 2.0.2
144
+ rubygems_version: 1.8.24
135
145
  signing_key:
136
- specification_version: 4
146
+ specification_version: 3
137
147
  summary: Magic for your browser.
138
148
  test_files: []
139
- has_rdoc: false
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YjgxMWQyODVkNmU4OTZlYTlkNzVhMzM2MWMwYjM1NjZjNmMxN2M0Nw==
5
- data.tar.gz: !binary |-
6
- NjgxMWE5NWEyYjlhZGM1YWIyYjI5MGZlMDAzZGQ0MzE5NzE1MGVmMA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MTg5MTYzM2JmOTg2YmFiN2IzMjQ4OGQ0ZDVhOWE1MzU3MjQ5ODk5MzUwN2Uz
10
- MzFlNThmNDJlYzNiMDBlYjYwN2VhZjI4OGY0M2QzNzRmNTQ4MzZmYzY2ODI3
11
- NDljMDM0Zjc2MGQ1NzU3ZWNmNjRkMWU4ZmI3NWRhZmI5ZDNiOTk=
12
- data.tar.gz: !binary |-
13
- NTgyOGViMDY2ZDcxN2RkOThkZjI5MDMxZmMyZjdkNWQ0ODVkNjE4N2RhYTIx
14
- ZjllMjA1YzgzOGI1OWJkMjVkZWE3OThkNzEyNzliNmIwODgwYzRhZWY4Mzgx
15
- NGE4YWFkMzlhMzUwYzJjZmNmNGU5NzkxYWQ1ZmI3ZmM1OGMwZTM=