Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
README.rdoc | |||
lib/**/*.rb | |||
bin/* | |||
features/**/*.feature | |||
LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
## MAC OS | |||
.DS_Store | |||
|
|||
## TEXTMATE | |||
*.tmproj | |||
tmtags | |||
|
|||
## EMACS | |||
*~ | |||
\#* | |||
.\#* | |||
|
|||
## VIM | |||
*.swp | |||
|
|||
## PROJECT::GENERAL | |||
coverage | |||
rdoc | |||
pkg | |||
|
|||
## PROJECT::SPECIFIC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
Copyright (c) 2010 Alexander MacCaw | |||
|
|||
Permission is hereby granted, free of charge, to any person obtaining | |||
a copy of this software and associated documentation files (the | |||
"Software"), to deal in the Software without restriction, including | |||
without limitation the rights to use, copy, modify, merge, publish, | |||
distribute, sublicense, and/or sell copies of the Software, and to | |||
permit persons to whom the Software is furnished to do so, subject to | |||
the following conditions: | |||
|
|||
The above copyright notice and this permission notice shall be | |||
included in all copies or substantial portions of the Software. | |||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
= Juggernaut | |||
|
|||
Description goes here. | |||
|
|||
== Copyright | |||
|
|||
Copyright (c) 2010 Alex MacCaw. See LICENSE for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
require 'rubygems' | |||
require 'rake' | |||
|
|||
begin | |||
require 'jeweler' | |||
Jeweler::Tasks.new do |gem| | |||
gem.name = "juggernaut" | |||
gem.summary = %Q{Simple realtime push} | |||
gem.description = %Q{Use Juggernaut to easily implement realtime chat, collaboration, gaming and much more!} | |||
gem.email = "info@eribium.org" | |||
gem.homepage = "http://github.com/maccman/juggernaut" | |||
gem.authors = ["Alex MacCaw"] | |||
gem.add_dependency "redis", ">= 0" | |||
end | |||
Jeweler::GemcutterTasks.new | |||
rescue LoadError | |||
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
2.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
class ModelObserver < ActiveRecord::Observer | |||
observe :activity | |||
|
|||
def after_create(rec) | |||
publish(:create, rec) | |||
end | |||
|
|||
def after_update(rec) | |||
publish(:update, rec) | |||
end | |||
|
|||
def after_destroy(rec) | |||
publish(:destroy, rec) | |||
end | |||
|
|||
protected | |||
def publish(type, rec) | |||
Juggernaut.publish( | |||
Array(rec.sync_clients).map {|c| "sync/#{c}" }, | |||
{:type => type, :id => rec.id, :record => rec} | |||
) | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,49 @@ | |||
# Generated by jeweler | |||
# DO NOT EDIT THIS FILE DIRECTLY | |||
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command | |||
# -*- encoding: utf-8 -*- | |||
|
|||
Gem::Specification.new do |s| | |||
s.name = %q{juggernaut} | |||
s.version = "2.0.0" | |||
|
|||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= | |||
s.authors = ["Alex MacCaw"] | |||
s.date = %q{2010-09-03} | |||
s.description = %q{Use Juggernaut to easily implement realtime chat, collaboration, gaming and much more!} | |||
s.email = %q{info@eribium.org} | |||
s.extra_rdoc_files = [ | |||
"LICENSE", | |||
"README" | |||
] | |||
s.files = [ | |||
".document", | |||
".gitignore", | |||
"LICENSE", | |||
"Rakefile", | |||
"VERSION", | |||
"lib/juggernaut.rb" | |||
] | |||
s.homepage = %q{http://github.com/maccman/juggernaut} | |||
s.rdoc_options = ["--charset=UTF-8"] | |||
s.require_paths = ["lib"] | |||
s.rubygems_version = %q{1.3.7} | |||
s.summary = %q{Simple realtime push} | |||
s.test_files = [ | |||
"examples/model_observer.rb" | |||
] | |||
|
|||
if s.respond_to? :specification_version then | |||
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION | |||
s.specification_version = 3 | |||
|
|||
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then | |||
s.add_runtime_dependency(%q<redis>, [">= 0"]) | |||
else | |||
s.add_dependency(%q<redis>, [">= 0"]) | |||
end | |||
else | |||
s.add_dependency(%q<redis>, [">= 0"]) | |||
end | |||
end | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
require "redis" | |||
require "json" | |||
|
|||
module Juggernaut | |||
def redis | |||
@redis ||= Redis.new | |||
end | |||
|
|||
def redis=(val) | |||
@redis = val | |||
end | |||
|
|||
def publish(channels, data) | |||
message = {:channels => Array(channels), :data => data} | |||
redis.publish(:juggernaut, message.to_json) | |||
end | |||
|
|||
extend self | |||
end |