nodevent 3.0.5 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-18mode # JRuby in 1.8 mode
5
+ - jruby-19mode # JRuby in 1.9 mode
6
+ - rbx-18mode
7
+ - rbx-19mode
8
+ - 1.8.7
9
+ script: rspec
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in nodevent.gemspec
4
- gemspec
4
+ #gemspec
5
5
  gem 'rspec'
6
- gem 'nodevent', :path => '.'
7
6
  gem 'rails'
data/README.md CHANGED
@@ -1,24 +1,158 @@
1
+ [![Build Status](https://secure.travis-ci.org/cconstantine/NoDevent-gem.png?branch=master)](http://travis-ci.org/cconstantine/NoDevent-gem)
2
+
1
3
  # Nodevent
2
4
 
3
- TODO: Write a gem description
5
+ Ruby support for sending NoDevent events.
4
6
 
5
7
  ## Installation
6
8
 
7
- Add this line to your application's Gemfile:
9
+ There is a rubygem named 'nodevent'. To install simply `gem install nodevent` the in ruby:
10
+ ```ruby
11
+ require 'nodevent'
12
+ ```
13
+
14
+ or, add this to your Gemfile
15
+ ```ruby
16
+ gem 'nodevent'
17
+ ```
18
+
19
+ ## Configuring NoDevent
20
+
21
+ The NoDevent module comes with a default config that will work if you're using the default appliance config. NoDevent expects a global $redis redis connection to exist, and it will use that to post events.
22
+
23
+ You can override that config
24
+ ```ruby
25
+ NoDevent::Emitter.config = {:host => "http://myawesomesite", :namespace => "/other_namespace", :secret => 'lajf0q983j4laidsnvqo84jfoqijflkjafds' }
26
+ ```
27
+ The namespace must match exactly to your configured namespace in the appliance. If there is a missmatch nothing will happen in the client and it can be VERY frustrating to debug. The secret must match also, or you will get errors attempting to join a room. You are also completely replacing the default config, so you must specify everything.
28
+
29
+
30
+ ## View helper
31
+ To get the magic javascript include tag in your view there is a rails view helper.
32
+ ```ruby
33
+ javascript_include_nodevent
34
+ ```
35
+ That will include the script tag with the configured path.
36
+
37
+ ## NoDevent::Emitter
38
+
39
+ This is where the magic happens.
40
+
41
+ ### Example usage:
42
+ In the controller
43
+ ```ruby
44
+ @room = NoDevent::Emitter.room(current_user)
45
+ @roomkey = NoDevent::Emitter.room_key(current_user, Time.zone.now + 1.hour)
46
+ ```
47
+
48
+ In the view
49
+ ```erb
50
+ <%= content_for :javascript do %>
51
+ current_user_room = NoDevent.room('<%=@room%>');
52
+ current_user_room.setKey('<%=@roomkey%>');
53
+ current_user_room.join();
54
+ <% end %>
55
+
56
+ ### NoDevent::Emitter.room(obj)
57
+
58
+ Example usage:
59
+ ```ruby
60
+ # Get the name of a room for a class/module
61
+ @roomname = NoDevent::Emitter.room(SomeModel)
62
+
63
+ # Get the name of a room for a model instance
64
+ @roomname = NoDevent::Emitter.room(SomeModel.first)
65
+
66
+ # Just returns "the_room"
67
+ @roomname = NoDevent::Emitter.room("the_room")
68
+ ```
69
+ This is a helper method to get the name of a room. You don't really need to use it, but it can convert objects that inherit from ActiveRecord::Base into their unique room name.
70
+
71
+ ### NoDevent::Emitter.room_key(obj, expires)
72
+
73
+ This is a helper method to generate the key for a room with a given experation time.
74
+
75
+ Example usage:
76
+ ```ruby
77
+ @roomkey = NoDevent::Emitter.room_key(SomeModel, Time.zone.now + 1.hour)
78
+ @roomkey = NoDevent::Emitter.room_key(SomeModel.first, Time.zone.now + 1.hour)
79
+ @roomkey = NoDevent::Emitter.room_key(@roomname, Time.zone.now + 1.hour)
80
+ @roomkey = NoDevent::Emitter.room_key('the_room', Time.zone.now + 1.hour)
81
+ ```
82
+ The above code will generate a key for the room that is valid for the next hour.
83
+
84
+ ### NoDevent::Emitter.emit(room, event, message)
85
+
86
+ This method emits a named event with a message (any object that responds to .to_json) to the room.
87
+
88
+ ```ruby
89
+ NoDevent::Emitter.emit(NoDevent::Emitter.room(SomeModel.first), 'the_event', 'some_message')
90
+ NoDevent::Emitter.emit('the_room', 'the_event', {:some => :data, :other => :thing})
91
+ ```
92
+
93
+ The event will travel through redis to the NoDevent appliance server, and any browser client room object will emit an event named after the event name.
94
+ ```javascript
95
+ var room = Nodevent.room('the_room')
96
+ room.join()
97
+ room.on('the_event', function(message) {});
98
+ ```
99
+
100
+ This method can be called from anywhere, and it will send the event to any browser client listening appropriately. This means it can be emitted on model creation, or even from a resque job.
101
+
102
+ ## NoDevent mixin.
103
+ To help even further, I've provided the NoDevent::Base module as an include-able thing for models.
104
+
105
+ ```ruby
106
+ class SomeModel < ActiveRecord::Base
107
+ include NoDevent::Base
108
+
109
+ after_create :nodevent_create
110
+ after_update :nodevent_update
111
+
112
+ def as_json(options={})
113
+ super(options).merge(:nodevent => {:room => room, :key => room_key(Time.zone.now + 1.hour)})
114
+ end
115
+
116
+ end
117
+ ```
118
+
119
+ The above example includes NoDevent support directly into a model.
120
+
121
+ It also provides the following:
122
+ * The class's room will be notified of created instances
123
+ * Instances will include the room name and key for getting updates
124
+ * Updates to a model will notify listeners of the change
125
+
126
+
127
+ When using this you can ask SomeModel for its room name
128
+ ```ruby
129
+ @roomname = SomeMode.first.room
130
+ ```
8
131
 
9
- gem 'nodevent'
132
+ or the room key
133
+ ```ruby
134
+ @roomkey = SomeModel.first.room_key(Time.zone.now + 1.hour)
135
+ ```
10
136
 
11
- And then execute:
137
+ or even emit directly to it's room
138
+ ```ruby
139
+ # Emit an arbitrary message to the model instance's room
140
+ SomeModel.first.emit('the_event', 'some_message')
12
141
 
13
- $ bundle
142
+ # Emit a json-ed version of the model
143
+ SomeModel.first.emit('update')
144
+ ```
14
145
 
15
- Or install it yourself as:
146
+ ## Versioning
16
147
 
17
- $ gem install nodevent
148
+ I'm using the following versioning scheme:
149
+ ```
150
+ x.y.z
151
+ ```
18
152
 
19
- ## Usage
153
+ A change in the 'x' indictes that there has been a backwards incompatible interface change. A change in the 'y' indicates some new functionality or significant bug fix, and a change in the 'z' indictes a minor bug fix.
20
154
 
21
- TODO: Write usage instructions here
155
+ Don't attempt to get a guage on how mature this system is by the version numbers. I'm following this pattern so that automatic version matching systems like bundler and npm can update developers' packages and protect against backwards incompatible changes. The rubygem and npm package follow each other in version number on the 'x', and 'y', but not 'z'.
22
156
 
23
157
  ## Contributing
24
158
 
@@ -1,3 +1,3 @@
1
1
  module Nodevent
2
- VERSION = "3.0.5"
2
+ VERSION = "3.1.0"
3
3
  end
data/lib/nodevent.rb CHANGED
@@ -66,7 +66,7 @@ module NoDevent
66
66
 
67
67
  def config
68
68
  @@config ||= Hash.new({
69
- :host => "http://loadsfcalhost:8080",
69
+ :host => "http://localhost:8080",
70
70
  :namespace => "/nodevent"
71
71
  })
72
72
  @@config
@@ -75,7 +75,7 @@ module NoDevent
75
75
  def emit(room, name, message)
76
76
  room = NoDevent::Emitter.room(room)
77
77
 
78
- $redis.publish("events",
78
+ $redis.publish(@@config[:namespace],
79
79
  { :room => room,
80
80
  :event => name,
81
81
  :message => message}.to_json)
data/nodevent.gemspec CHANGED
@@ -3,10 +3,10 @@ require File.expand_path('../lib/nodevent/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Chris Constantine"]
6
- gem.email = ["cconstan@gmail.com.com"]
6
+ gem.email = ["cconstan@gmail.com"]
7
7
  gem.description = %q{Write a gem description}
8
8
  gem.summary = %q{ Write a gem summary}
9
- gem.homepage = "https://github.com/cconstantine/NoDevent"
9
+ gem.homepage = "https://github.com/cconstantine/NoDevent-gem"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
12
12
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
data/spec/spec_helper.rb CHANGED
@@ -12,6 +12,7 @@ if defined?(Bundler)
12
12
  # If you want your assets lazily compiled in production, use this line
13
13
  # Bundler.require(:default, :assets, Rails.env)
14
14
  end
15
+ require 'nodevent'
15
16
 
16
17
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
18
  RSpec.configure do |config|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nodevent
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.5
4
+ version: 3.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-27 00:00:00.000000000 Z
12
+ date: 2012-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -29,14 +29,12 @@ dependencies:
29
29
  version: 2.0.0
30
30
  description: Write a gem description
31
31
  email:
32
- - cconstan@gmail.com.com
32
+ - cconstan@gmail.com
33
33
  executables: []
34
34
  extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
- - .gitignore
38
- - .rspec
39
- - .rvmrc
37
+ - .travis.yml
40
38
  - Gemfile
41
39
  - LICENSE
42
40
  - README.md
@@ -47,7 +45,7 @@ files:
47
45
  - spec/base_spec.rb
48
46
  - spec/emitter_spec.rb
49
47
  - spec/spec_helper.rb
50
- homepage: https://github.com/cconstantine/NoDevent
48
+ homepage: https://github.com/cconstantine/NoDevent-gem
51
49
  licenses: []
52
50
  post_install_message:
53
51
  rdoc_options: []
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format progress
data/.rvmrc DELETED
@@ -1,48 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
- # development environment upon cd'ing into the directory
5
-
6
- # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
- # Only full ruby name is supported here, for short names use:
8
- # echo "rvm use 1.9.3" > .rvmrc
9
- environment_id="ruby-1.9.3-p194@nodevent"
10
-
11
- # Uncomment the following lines if you want to verify rvm version per project
12
- # rvmrc_rvm_version="1.14.5 (stable)" # 1.10.1 seams as a safe start
13
- # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
- # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
- # return 1
16
- # }
17
-
18
- # First we attempt to load the desired environment directly from the environment
19
- # file. This is very fast and efficient compared to running through the entire
20
- # CLI and selector. If you want feedback on which environment was used then
21
- # insert the word 'use' after --create as this triggers verbose mode.
22
- if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
- && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
- then
25
- \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
- [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
- \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
- else
29
- # If the environment file has not yet been created, use the RVM CLI to select.
30
- rvm --create "$environment_id" || {
31
- echo "Failed to create RVM environment '${environment_id}'."
32
- return 1
33
- }
34
- fi
35
-
36
- # If you use bundler, this might be useful to you:
37
- # if [[ -s Gemfile ]] && {
38
- # ! builtin command -v bundle >/dev/null ||
39
- # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
- # }
41
- # then
42
- # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
- # gem install bundler
44
- # fi
45
- # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
- # then
47
- # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
- # fi