Last active
January 23, 2016 03:02
-
-
Save cpuguy83/4707055 to your computer and use it in GitHub Desktop.
Server Push based controller
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
class BasePusher < AbstractController::Base | |
include AbstractController::Logger | |
include AbstractController::Rendering | |
include AbstractController::Layouts | |
include AbstractController::Helpers | |
include AbstractController::Translation | |
include AbstractController::AssetPaths | |
include AbstractController::Callbacks | |
include Rails.application.routes.url_helpers if defined? Rails | |
# Needed this because my partials use caching | |
include ActionView::Helpers::CacheHelper if defined? ActionView | |
include ActionController::Caching::Fragments if defined? ActionController | |
helper ApplicationHelper | |
self.view_paths = "app/views" | |
# Haven't gotten the requirements down for actually caching just yet, so disabling | |
# But this needs to be set so we don't get exceptions on when the cache method is called from the view | |
def perform_caching | |
false | |
end | |
def controller_path | |
@controller_path ||= self.class.to_s.gsub(/Pusher$/, '').underscore | |
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
class FooObject < ActiveRecord::Base | |
after_save :push_to_client | |
private | |
def push_to_client | |
FooBjectsPusher.new.foo_action | |
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
FooObjectsPusher < BasePusher | |
# define actions | |
def foo_action | |
# format content and push | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment