faye-plugin 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+ gem 'faye', '~> 0.6.7'
3
+
4
+ # Add dependencies to develop your gem here.
5
+ # Include everything needed to run rake, tests, features, etc.
6
+ group :development do
7
+ gem "shoulda", ">= 0"
8
+ gem "bundler", "~> 1.0.0"
9
+ gem "jeweler", "~> 1.6.4"
10
+ gem "rcov", ">= 0"
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.6)
5
+ daemons (1.1.4)
6
+ em-hiredis (0.1.0)
7
+ hiredis (~> 0.3.0)
8
+ em-http-request (0.3.0)
9
+ addressable (>= 2.0.0)
10
+ escape_utils
11
+ eventmachine (>= 0.12.9)
12
+ escape_utils (0.2.4)
13
+ eventmachine (0.12.10)
14
+ faye (0.6.7)
15
+ em-hiredis (>= 0.0.1)
16
+ em-http-request (~> 0.3)
17
+ eventmachine (~> 0.12.0)
18
+ json (>= 1.0)
19
+ rack (>= 1.0)
20
+ thin (~> 1.2)
21
+ git (1.2.5)
22
+ hiredis (0.3.2)
23
+ jeweler (1.6.4)
24
+ bundler (~> 1.0)
25
+ git (>= 1.2.5)
26
+ rake
27
+ json (1.6.1)
28
+ rack (1.3.3)
29
+ rake (0.9.2)
30
+ rcov (0.9.9)
31
+ shoulda (2.10.3)
32
+ thin (1.2.11)
33
+ daemons (>= 1.0.9)
34
+ eventmachine (>= 0.12.6)
35
+ rack (>= 1.0.0)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ bundler (~> 1.0.0)
42
+ faye (~> 0.6.7)
43
+ jeweler (~> 1.6.4)
44
+ rcov
45
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Alexander Brodianoy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = faye-plugin
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to faye-plugin
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Alexander Brodianoy. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ gem.name = "faye-plugin"
17
+ gem.homepage = "http://github.com/dom1nga/faye-plugin"
18
+ gem.license = "MIT"
19
+ gem.summary = "Provides helper methods for automatically updating model fields on views"
20
+ gem.description = "Provides helper methods for automatically updating model fields on views"
21
+ gem.email = "beloved.dom1nga@gmail.com"
22
+ gem.authors = ["dom1nga"]
23
+
24
+ gem.add_dependency 'faye', '~> 0.6.7'
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "faye-plugin #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{faye-plugin}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["dom1nga"]
12
+ s.date = %q{2011-11-03}
13
+ s.description = %q{Provides helper methods for automatically updating model fields on views}
14
+ s.email = %q{beloved.dom1nga@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "faye-plugin-0.1.1.gem",
28
+ "faye-plugin.gemspec",
29
+ "lib/faye-plugin.rb",
30
+ "lib/faye-plugin/observers/faye_plugin_observer.rb",
31
+ "test/helper.rb",
32
+ "test/test_faye-plugin.rb",
33
+ "vendor/assets/javascripts/faye_plugin.js.erb"
34
+ ]
35
+ s.homepage = %q{http://github.com/dom1nga/faye-plugin}
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{Provides helper methods for automatically updating model fields on views}
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<faye>, ["~> 0.6.7"])
47
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
50
+ s.add_development_dependency(%q<rcov>, [">= 0"])
51
+ s.add_runtime_dependency(%q<faye>, ["~> 0.6.7"])
52
+ else
53
+ s.add_dependency(%q<faye>, ["~> 0.6.7"])
54
+ s.add_dependency(%q<shoulda>, [">= 0"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
57
+ s.add_dependency(%q<rcov>, [">= 0"])
58
+ s.add_dependency(%q<faye>, ["~> 0.6.7"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<faye>, ["~> 0.6.7"])
62
+ s.add_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
65
+ s.add_dependency(%q<rcov>, [">= 0"])
66
+ s.add_dependency(%q<faye>, ["~> 0.6.7"])
67
+ end
68
+ end
69
+
@@ -0,0 +1,25 @@
1
+ class FayePluginObserver < ActiveRecord::Observer
2
+ observe Rails.configuration.faye_observers
3
+
4
+ def broadcast_message(channel, data)
5
+ message = {:channel => channel, :data => data, :ext => {:auth_token => FAYE_TOKEN}}
6
+ uri = URI.parse("http://#{Rails.configuration.faye_host}:#{Rails.configuration.faye_port}/faye")
7
+ Net::HTTP.post_form(uri, :message => message.to_json)
8
+ end
9
+
10
+ def before_update(model)
11
+ if model.changed?
12
+ @client_changes = lambda do
13
+ model.changes.each do |key, value|
14
+ broadcast_message("/listener", "$(\"##{model.class.name.downcase}_#{model.id}_#{key}\").html(\"#{value[1]}\")")
15
+ end
16
+ end
17
+ else
18
+ @client_changes = lambda {}
19
+ end
20
+ end
21
+
22
+ def after_update(model)
23
+ @client_changes.call
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ module FayePlugin
2
+
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ base.send :include, InstanceMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ end
10
+
11
+ module InstanceMethods
12
+
13
+ def faye_watcher(object, attribute)
14
+ content_tag(:div, "#{object[attribute.to_sym]}", {:id => "#{object.class.name.downcase}_#{object.id}_#{attribute}"})
15
+ end
16
+
17
+ def broadcast(channel, &block)
18
+ message = {:channel => channel, :data => capture(&block), :ext => {:auth_token => FAYE_TOKEN}}
19
+ uri = URI.parse("http://#{Rails.configuration.faye_host}:#{Rails.configuration.faye_port}/faye")
20
+ Net::HTTP.post_form(uri, :message => message.to_json)
21
+ end
22
+
23
+ end
24
+ end
25
+
26
+ ActionView::Base.send(:include, FayePlugin) if defined?(ActionView::Base)
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'faye-plugin'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,4 @@
1
+ # require 'helper'
2
+ #
3
+ # class TestFayePlugin < Test::Unit::TestCase
4
+ # end
@@ -0,0 +1,8 @@
1
+
2
+
3
+ $(function() {
4
+ var faye = new Faye.Client("http://<%= Rails.configuration.faye_host %>:<%= Rails.configuration.faye_port %>/faye");
5
+ faye.subscribe('/listener', function (data) {
6
+ eval(data);
7
+ });
8
+ });
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faye-plugin
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - dom1nga
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-03 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 9
28
+ segments:
29
+ - 0
30
+ - 6
31
+ - 7
32
+ version: 0.6.7
33
+ type: :runtime
34
+ name: faye
35
+ prerelease: false
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ name: shoulda
49
+ prerelease: false
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ hash: 23
58
+ segments:
59
+ - 1
60
+ - 0
61
+ - 0
62
+ version: 1.0.0
63
+ type: :development
64
+ name: bundler
65
+ prerelease: false
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ hash: 7
74
+ segments:
75
+ - 1
76
+ - 6
77
+ - 4
78
+ version: 1.6.4
79
+ type: :development
80
+ name: jeweler
81
+ prerelease: false
82
+ version_requirements: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ type: :development
94
+ name: rcov
95
+ prerelease: false
96
+ version_requirements: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ hash: 9
104
+ segments:
105
+ - 0
106
+ - 6
107
+ - 7
108
+ version: 0.6.7
109
+ type: :runtime
110
+ name: faye
111
+ prerelease: false
112
+ version_requirements: *id006
113
+ description: Provides helper methods for automatically updating model fields on views
114
+ email: beloved.dom1nga@gmail.com
115
+ executables: []
116
+
117
+ extensions: []
118
+
119
+ extra_rdoc_files:
120
+ - LICENSE.txt
121
+ - README.rdoc
122
+ files:
123
+ - .document
124
+ - Gemfile
125
+ - Gemfile.lock
126
+ - LICENSE.txt
127
+ - README.rdoc
128
+ - Rakefile
129
+ - VERSION
130
+ - faye-plugin-0.1.1.gem
131
+ - faye-plugin.gemspec
132
+ - lib/faye-plugin.rb
133
+ - lib/faye-plugin/observers/faye_plugin_observer.rb
134
+ - test/helper.rb
135
+ - test/test_faye-plugin.rb
136
+ - vendor/assets/javascripts/faye_plugin.js.erb
137
+ has_rdoc: true
138
+ homepage: http://github.com/dom1nga/faye-plugin
139
+ licenses:
140
+ - MIT
141
+ post_install_message:
142
+ rdoc_options: []
143
+
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ hash: 3
152
+ segments:
153
+ - 0
154
+ version: "0"
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ hash: 3
161
+ segments:
162
+ - 0
163
+ version: "0"
164
+ requirements: []
165
+
166
+ rubyforge_project:
167
+ rubygems_version: 1.3.7
168
+ signing_key:
169
+ specification_version: 3
170
+ summary: Provides helper methods for automatically updating model fields on views
171
+ test_files: []
172
+