action_pusher 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create 1.9.3@action_pusher_gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in action_pusher.gemspec
4
+ gemspec
@@ -0,0 +1,42 @@
1
+ # ActionPusher
2
+ #### Render views to Pusher from anywhere in your application
3
+
4
+ [Pusher](http://pusher.com/) users often want to transmit JSON or HTML to the browser upon model events, but models have no business generating either. ActionPusher allows you to render data to Pusher using your existing view templates from an observer or model.
5
+
6
+ ## Requirements
7
+ * Rails 3.1
8
+ * [Pusher gem](http://rubygems.org/gems/pusher)
9
+
10
+ ## Installation
11
+
12
+ gem 'action_pusher', :require => false
13
+
14
+ Create an initializer at **config/initializers/action_pusher.rb** such as:
15
+
16
+ require 'action_pusher'
17
+ ActionPusher::Base.view_paths = File.join( Rails.root, 'app/api' )
18
+
19
+ Ensure that _view_paths_ points to the location where your templates are actually stored. The default is app/views.
20
+
21
+ Create a directory at **app/pushers** to store your ActionPusher "controllers".
22
+
23
+ ## Example
24
+
25
+ **app/pushers/notification_pusher.rb**:
26
+
27
+ class NotificationPusher < ActionPusher::Base
28
+ def initialize(notification)
29
+ @notification = notification
30
+ event = @notification.event
31
+ channel = @notification.notification_channel.name
32
+ Pushable.push(channel, event, render(template: 'notifications/show'))
33
+ end
34
+
35
+ def controller_path; 'notifications'; end
36
+ end
37
+
38
+ Now when I call NotificationPusher.new( notification ) from my model callbacks, observers, what-have-you... my Notification model object is transmitted to Pusher as pretty JSON output from [jbuilder](https://github.com/rails/jbuilder)!
39
+
40
+ ## Credit
41
+
42
+ This gem was inspired by [stephan.com](http://stackoverflow.com/users/444955/stephan-com)'s solution to a question on [StackOverflow](http://stackoverflow.com/questions/6318959/rails-how-to-render-a-view-partial-in-a-model), I just wrapped it up in a gem once I got it working well in production.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "action_pusher/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "action_pusher"
7
+ s.version = ActionPusher::VERSION
8
+ s.authors = ["Logan Koester"]
9
+ s.email = ["logan@logankoester.com"]
10
+ s.homepage = "https://github.com/agoragames/action_pusher"
11
+ s.summary = %q{Render views to Pusher from anywhere in your application}
12
+ s.description = %q{Render views to Pusher from anywhere in your application}
13
+
14
+ s.rubyforge_project = "action_pusher"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency 'rails', '>= 3.1'
24
+ s.add_runtime_dependency 'pusher'
25
+ end
@@ -0,0 +1,21 @@
1
+ require "action_pusher/version"
2
+
3
+ module ActionPusher
4
+ class Base < AbstractController::Base
5
+ include AbstractController::Rendering
6
+ include AbstractController::Helpers
7
+ include AbstractController::Translation
8
+ include AbstractController::AssetPaths
9
+ include Rails.application.routes.url_helpers
10
+
11
+ helper ApplicationHelper
12
+ self.view_paths = File.join( Rails.root, 'app/views' )
13
+
14
+ class Pushable
15
+ def self.push(channel, event, data)
16
+ @channel, @event, @data = channel, event, data
17
+ Pusher[@channel].trigger(@event, @data )
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module ActionPusher
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: action_pusher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Logan Koester
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &19419540 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *19419540
25
+ - !ruby/object:Gem::Dependency
26
+ name: pusher
27
+ requirement: &19418000 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *19418000
36
+ description: Render views to Pusher from anywhere in your application
37
+ email:
38
+ - logan@logankoester.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - .rvmrc
45
+ - Gemfile
46
+ - README.markdown
47
+ - Rakefile
48
+ - action_pusher.gemspec
49
+ - lib/action_pusher.rb
50
+ - lib/action_pusher/version.rb
51
+ homepage: https://github.com/agoragames/action_pusher
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project: action_pusher
71
+ rubygems_version: 1.8.10
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Render views to Pusher from anywhere in your application
75
+ test_files: []