Skip to content

Commit

Permalink
Rename top level module to RenderSync
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurnn committed Feb 11, 2016
1 parent b69a31e commit 0c77145
Show file tree
Hide file tree
Showing 53 changed files with 315 additions and 317 deletions.
62 changes: 31 additions & 31 deletions app/assets/javascripts/sync.coffee
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
$ = jQuery

@Sync =
@RenderSync =

ready: false
readyQueue: []

init: ->
$ =>
return unless SyncConfig? && Sync[SyncConfig.adapter]
@adapter ||= new Sync[SyncConfig.adapter]
return unless RenderSyncConfig? && RenderSync[RenderSyncConfig.adapter]
@adapter ||= new RenderSync[RenderSyncConfig.adapter]
return if @isReady() || !@adapter.available()
@ready = true
@connect()
Expand Down Expand Up @@ -60,18 +60,18 @@ $ = jQuery
#
# Examples
# partialName 'list_row', resourceName 'todo', order of lookup:
# Sync.TodoListRow
# Sync.ListRow
# Sync.View
# RenderSync.TodoListRow
# RenderSync.ListRow
# RenderSync.View
#
# Defaults to Sync.View if no custom view class has been defined
# Defaults to RenderSync.View if no custom view class has been defined
viewClassFromPartialName: (partialName, resourceName) ->
Sync[@camelize("#{resourceName}_#{partialName}")] ?
Sync[@camelize(partialName)] ?
Sync.View
RenderSync[@camelize("#{resourceName}_#{partialName}")] ?
RenderSync[@camelize(partialName)] ?
RenderSync.View


class Sync.Adapter
class RenderSync.Adapter

subscriptions: []

Expand All @@ -90,25 +90,25 @@ class Sync.Adapter

subscribe: (channel, callback) ->
@unsubscribeChannel(channel)
subscription = new Sync[SyncConfig.adapter].Subscription(@client, channel, callback)
subscription = new RenderSync[RenderSyncConfig.adapter].Subscription(@client, channel, callback)
@subscriptions.push(subscription)
subscription


class Sync.Faye extends Sync.Adapter
class RenderSync.Faye extends RenderSync.Adapter

subscriptions: []

available: ->
!!window.Faye

connect: ->
@client = new window.Faye.Client(SyncConfig.server)
@client = new window.Faye.Client(RenderSyncConfig.server)

isConnected: -> @client?.getState() is "CONNECTED"


class Sync.Faye.Subscription
class RenderSync.Faye.Subscription

constructor: (@client, channel, callback) ->
@channel = channel
Expand All @@ -118,7 +118,7 @@ class Sync.Faye.Subscription
@fayeSub.cancel()


class Sync.Pusher extends Sync.Adapter
class RenderSync.Pusher extends RenderSync.Adapter

subscriptions: []

Expand All @@ -127,24 +127,24 @@ class Sync.Pusher extends Sync.Adapter

connect: ->
opts =
encrypted: SyncConfig.pusher_encrypted
encrypted: RenderSyncConfig.pusher_encrypted

opts.wsHost = SyncConfig.pusher_ws_host if SyncConfig.pusher_ws_host
opts.wsPort = SyncConfig.pusher_ws_port if SyncConfig.pusher_ws_port
opts.wssPort = SyncConfig.pusher_wss_port if SyncConfig.pusher_wss_port
opts.wsHost = RenderSyncConfig.pusher_ws_host if RenderSyncConfig.pusher_ws_host
opts.wsPort = RenderSyncConfig.pusher_ws_port if RenderSyncConfig.pusher_ws_port
opts.wssPort = RenderSyncConfig.pusher_wss_port if RenderSyncConfig.pusher_wss_port

@client = new window.Pusher(SyncConfig.api_key, opts)
@client = new window.Pusher(RenderSyncConfig.api_key, opts)

isConnected: -> @client?.connection.state is "connected"

subscribe: (channel, callback) ->
@unsubscribeChannel(channel)
subscription = new Sync.Pusher.Subscription(@client, channel, callback)
subscription = new RenderSync.Pusher.Subscription(@client, channel, callback)
@subscriptions.push(subscription)
subscription


class Sync.Pusher.Subscription
class RenderSync.Pusher.Subscription
constructor: (@client, channel, callback) ->
@channel = channel

Expand All @@ -155,7 +155,7 @@ class Sync.Pusher.Subscription
@client.unsubscribe(@channel) if @client.channel(@channel)?


class Sync.View
class RenderSync.View

removed: false

Expand Down Expand Up @@ -202,7 +202,7 @@ class Sync.View



class Sync.Partial
class RenderSync.Partial

attributes:
name: null
Expand Down Expand Up @@ -236,8 +236,8 @@ class Sync.Partial
@$start = $("[data-sync-id='#{@selectorStart}']")
@$end = $("[data-sync-id='#{@selectorEnd}']")
@$el = @$start.nextUntil(@$end)
@view = new (Sync.viewClassFromPartialName(@name, @resourceName))(@$el, @name)
@adapter = Sync.adapter
@view = new (RenderSync.viewClassFromPartialName(@name, @resourceName))(@$el, @name)
@adapter = RenderSync.adapter


subscribe: ->
Expand Down Expand Up @@ -287,7 +287,7 @@ class Sync.Partial
success: (data) -> callback(data.html)


class Sync.PartialCreator
class RenderSync.PartialCreator

attributes:
name: null
Expand All @@ -311,7 +311,7 @@ class Sync.PartialCreator
constructor: (attributes = {}) ->
@[key] = attributes[key] ? defaultValue for key, defaultValue of @attributes
@$el = $("[data-sync-id='#{@selector}']")
@adapter = Sync.adapter
@adapter = RenderSync.adapter


subscribe: ->
Expand All @@ -338,7 +338,7 @@ class Sync.PartialCreator
<script type='text/javascript' data-sync-el-placeholder></script>
<script type='text/javascript' data-sync-id='#{selectorEnd}'></script>
"""
partial = new Sync.Partial(
partial = new RenderSync.Partial(
name: @name
resourceName: @resourceName
resourceId: resourceId
Expand All @@ -352,4 +352,4 @@ class Sync.PartialCreator
partial.subscribe()
partial.insert(html)

Sync.init()
RenderSync.init()
6 changes: 3 additions & 3 deletions app/controllers/sync/refetches_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Sync::RefetchesController < ApplicationController
class RenderSync::RefetchesController < ApplicationController

before_filter :require_valid_request
before_filter :find_resource
Expand Down Expand Up @@ -35,14 +35,14 @@ def request_valid?
end

def find_resource
@resource = Sync::RefetchModel.find_by_class_name_and_id(
@resource = RenderSync::RefetchModel.find_by_class_name_and_id(
params[:resource_name],
params[:resource_id]
) || render_bad_request
end

def find_authorized_partial
@partial = Sync::RefetchPartial.find_by_authorized_resource(
@partial = RenderSync::RefetchPartial.find_by_authorized_resource(
@resource,
params[:partial_name],
self,
Expand Down
15 changes: 15 additions & 0 deletions app/helpers/render_sync/config_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module RenderSync::ConfigHelper
def include_sync_config(opts = {})
return unless RenderSync.adapter

str = ''

unless opts[:skip_adapter]
str << %{<script src="#{RenderSync.adapter_javascript_url}" data-turbolinks-eval=false></script>}
end

str << %{<script data-turbolinks-eval=false>var RenderSyncConfig = #{RenderSync.config_json};</script>}

str.html_safe
end
end
15 changes: 0 additions & 15 deletions app/helpers/sync/config_helper.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/generators/sync/install_generator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Sync
module RenderSync
module Generators
class InstallGenerator < Rails::Generators::Base
def self.source_root
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/sync/templates/sync.ru
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ require "sync"

Faye::WebSocket.load_adapter 'thin'

Sync.load_config(
RenderSync.load_config(
File.expand_path("../config/sync.yml", __FILE__),
ENV["RAILS_ENV"] || "development"
)

run Sync.pubsub_app
run RenderSync.pubsub_app
6 changes: 3 additions & 3 deletions lib/sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
require 'sync/engine'
end

module Sync
module RenderSync

class << self
attr_accessor :config, :client, :logger
Expand Down Expand Up @@ -80,13 +80,13 @@ def load_config(filename, environment)

def setup_client
raise ArgumentError, "auth_token missing" if config[:auth_token].nil?
@client = Sync::Clients.const_get(adapter).new
@client = RenderSync::Clients.const_get(adapter).new
@client.setup
end

def setup_dummy_client
config[:auth_token] = 'dummy_auth_token'
@client = Sync::Clients::Dummy.new
@client = RenderSync::Clients::Dummy.new
end

def setup_logger
Expand Down
4 changes: 2 additions & 2 deletions lib/sync/action.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Sync
module RenderSync
class Action
include Actions

Expand Down Expand Up @@ -36,4 +36,4 @@ def get_scope_from_options(options)
end

end
end
end
14 changes: 7 additions & 7 deletions lib/sync/actions.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Sync
module RenderSync
module Actions

# Render all sync'd partials for resource to string and publish update action
Expand All @@ -8,7 +8,7 @@ module Actions
# options - The Hash of options
# default_scope - The ActiveModel resource to scope the update channel to
# scope - Either a String, a symbol, an instance of ActiveModel or
# Sync::Scope or an Array containing a combination to scope
# RenderSync::Scope or an Array containing a combination to scope
# the update channel to. Will be concatenated to an optional
# default_scope
#
Expand All @@ -23,7 +23,7 @@ def sync_update(resource, options = {})
# options - The Hash of options
# default_scope - The ActiveModel resource to scope the update channel to
# scope - Either a String, a symbol, an instance of ActiveModel or
# Sync::Scope or an Array containing a combination to scope
# RenderSync::Scope or an Array containing a combination to scope
# the destroy channel to. Will be concatenated to an optional
# default_scope
#
Expand All @@ -39,7 +39,7 @@ def sync_destroy(resource, options = {})
# options - The Hash of options
# default_scope - The ActiveModel resource to scope the action channel to
# scope - Either a String, a symbol, an instance of ActiveModel or
# Sync::Scope or an Array containing a combination to scope
# RenderSync::Scope or an Array containing a combination to scope
# the channel to. Will be concatenated to an optional default_scope
#
def sync(resource, action, options = {})
Expand All @@ -58,7 +58,7 @@ def sync(resource, action, options = {})
end
end

Sync.client.batch_publish(messages.flatten)
RenderSync.client.batch_publish(messages.flatten)
end

# Render all sync'd partials for resource to string and publish
Expand All @@ -69,7 +69,7 @@ def sync(resource, action, options = {})
# options - The Hash of options
# default_scope - The ActiveModel resource to scope the new channel to
# scope - Either a String, a symbol, an instance of ActiveModel or
# Sync::Scope or an Array containing any combination to scope
# RenderSync::Scope or an Array containing any combination to scope
# the new channel to. Will be concatenated to an optional
# default_scope
#
Expand All @@ -89,7 +89,7 @@ def sync_new(resource, options = {})
end
end

Sync.client.batch_publish(messages.flatten)
RenderSync.client.batch_publish(messages.flatten)
end

private
Expand Down
6 changes: 3 additions & 3 deletions lib/sync/channel.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Sync
module RenderSync

class Channel

Expand All @@ -11,13 +11,13 @@ def initialize(name)
def signature
OpenSSL::HMAC.hexdigest(
OpenSSL::Digest.new('sha1'),
Sync.auth_token,
RenderSync.auth_token,
self.name
)
end

def to_s
Sync.client.normalize_channel(self.signature)
RenderSync.client.normalize_channel(self.signature)
end
end
end
2 changes: 1 addition & 1 deletion lib/sync/clients/dummy.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Sync
module RenderSync
module Clients
class Dummy
def method_missing(*args, &block)
Expand Down
Loading

0 comments on commit 0c77145

Please sign in to comment.