From 0c771451f7b55d8d15d97abf9e1c197f7bd56932 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Thu, 11 Feb 2016 18:02:04 -0500 Subject: [PATCH] Rename top level module to RenderSync --- app/assets/javascripts/sync.coffee | 62 ++++++++++---------- app/controllers/sync/refetches_controller.rb | 6 +- app/helpers/render_sync/config_helper.rb | 15 +++++ app/helpers/sync/config_helper.rb | 15 ----- lib/generators/sync/install_generator.rb | 2 +- lib/generators/sync/templates/sync.ru | 4 +- lib/sync.rb | 6 +- lib/sync/action.rb | 4 +- lib/sync/actions.rb | 14 ++--- lib/sync/channel.rb | 6 +- lib/sync/clients/dummy.rb | 2 +- lib/sync/clients/faye.rb | 24 ++++---- lib/sync/clients/pusher.rb | 24 ++++---- lib/sync/controller_helpers.rb | 4 +- lib/sync/engine.rb | 6 +- lib/sync/erb_tracker.rb | 2 +- lib/sync/faye_extension.rb | 4 +- lib/sync/model.rb | 22 +++---- lib/sync/model_actions.rb | 14 ++--- lib/sync/model_change_tracking.rb | 8 +-- lib/sync/model_syncing.rb | 8 +-- lib/sync/model_touching.rb | 4 +- lib/sync/partial.rb | 6 +- lib/sync/partial_creator.rb | 4 +- lib/sync/reactor.rb | 4 +- lib/sync/refetch_model.rb | 4 +- lib/sync/refetch_partial.rb | 8 +-- lib/sync/refetch_partial_creator.rb | 4 +- lib/sync/renderer.rb | 4 +- lib/sync/resource.rb | 6 +- lib/sync/scope.rb | 2 +- lib/sync/scope_definition.rb | 2 +- lib/sync/view_helpers.rb | 14 ++--- test/sync/action_test.rb | 26 ++++---- test/sync/channel_test.rb | 4 +- test/sync/config_test.rb | 10 ++-- test/sync/erb_tracker_test.rb | 18 +++--- test/sync/faye_extension_test.rb | 4 +- test/sync/message_test.rb | 36 ++++++------ test/sync/model_test.rb | 32 +++++----- test/sync/partial_creator_test.rb | 6 +- test/sync/partial_test.rb | 18 +++--- test/sync/protected_attributes_test.rb | 4 +- test/sync/reactor_test.rb | 8 +-- test/sync/refetch_model_test.rb | 12 ++-- test/sync/refetch_partial_creator_test.rb | 6 +- test/sync/refetch_partial_test.rb | 22 +++---- test/sync/renderer_test.rb | 4 +- test/sync/resource_test.rb | 56 +++++++++--------- test/sync/scope_definition_test.rb | 12 ++-- test/sync/scope_test.rb | 18 +++--- test/test_helper.rb | 18 +++--- test/travis/sync.ru | 4 +- 53 files changed, 315 insertions(+), 317 deletions(-) create mode 100644 app/helpers/render_sync/config_helper.rb delete mode 100644 app/helpers/sync/config_helper.rb diff --git a/app/assets/javascripts/sync.coffee b/app/assets/javascripts/sync.coffee index 819656f..847615b 100644 --- a/app/assets/javascripts/sync.coffee +++ b/app/assets/javascripts/sync.coffee @@ -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() @@ -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: [] @@ -90,12 +90,12 @@ 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: [] @@ -103,12 +103,12 @@ class Sync.Faye extends Sync.Adapter !!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 @@ -118,7 +118,7 @@ class Sync.Faye.Subscription @fayeSub.cancel() -class Sync.Pusher extends Sync.Adapter +class RenderSync.Pusher extends RenderSync.Adapter subscriptions: [] @@ -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 @@ -155,7 +155,7 @@ class Sync.Pusher.Subscription @client.unsubscribe(@channel) if @client.channel(@channel)? -class Sync.View +class RenderSync.View removed: false @@ -202,7 +202,7 @@ class Sync.View -class Sync.Partial +class RenderSync.Partial attributes: name: null @@ -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: -> @@ -287,7 +287,7 @@ class Sync.Partial success: (data) -> callback(data.html) -class Sync.PartialCreator +class RenderSync.PartialCreator attributes: name: null @@ -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: -> @@ -338,7 +338,7 @@ class Sync.PartialCreator """ - partial = new Sync.Partial( + partial = new RenderSync.Partial( name: @name resourceName: @resourceName resourceId: resourceId @@ -352,4 +352,4 @@ class Sync.PartialCreator partial.subscribe() partial.insert(html) -Sync.init() +RenderSync.init() diff --git a/app/controllers/sync/refetches_controller.rb b/app/controllers/sync/refetches_controller.rb index 2c752fe..f2a17d7 100644 --- a/app/controllers/sync/refetches_controller.rb +++ b/app/controllers/sync/refetches_controller.rb @@ -1,4 +1,4 @@ -class Sync::RefetchesController < ApplicationController +class RenderSync::RefetchesController < ApplicationController before_filter :require_valid_request before_filter :find_resource @@ -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, diff --git a/app/helpers/render_sync/config_helper.rb b/app/helpers/render_sync/config_helper.rb new file mode 100644 index 0000000..59b8a03 --- /dev/null +++ b/app/helpers/render_sync/config_helper.rb @@ -0,0 +1,15 @@ +module RenderSync::ConfigHelper + def include_sync_config(opts = {}) + return unless RenderSync.adapter + + str = '' + + unless opts[:skip_adapter] + str << %{} + end + + str << %{} + + str.html_safe + end +end diff --git a/app/helpers/sync/config_helper.rb b/app/helpers/sync/config_helper.rb deleted file mode 100644 index 581d48e..0000000 --- a/app/helpers/sync/config_helper.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Sync::ConfigHelper - def include_sync_config(opts = {}) - return unless Sync.adapter - - str = '' - - unless opts[:skip_adapter] - str << %{} - end - - str << %{} - - str.html_safe - end -end diff --git a/lib/generators/sync/install_generator.rb b/lib/generators/sync/install_generator.rb index 611dd40..4c698ff 100644 --- a/lib/generators/sync/install_generator.rb +++ b/lib/generators/sync/install_generator.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync module Generators class InstallGenerator < Rails::Generators::Base def self.source_root diff --git a/lib/generators/sync/templates/sync.ru b/lib/generators/sync/templates/sync.ru index 1e219a5..28cc52c 100644 --- a/lib/generators/sync/templates/sync.ru +++ b/lib/generators/sync/templates/sync.ru @@ -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 \ No newline at end of file +run RenderSync.pubsub_app diff --git a/lib/sync.rb b/lib/sync.rb index 218e038..b97721f 100644 --- a/lib/sync.rb +++ b/lib/sync.rb @@ -34,7 +34,7 @@ require 'sync/engine' end -module Sync +module RenderSync class << self attr_accessor :config, :client, :logger @@ -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 diff --git a/lib/sync/action.rb b/lib/sync/action.rb index fb098c3..0804adf 100644 --- a/lib/sync/action.rb +++ b/lib/sync/action.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync class Action include Actions @@ -36,4 +36,4 @@ def get_scope_from_options(options) end end -end \ No newline at end of file +end diff --git a/lib/sync/actions.rb b/lib/sync/actions.rb index 300494a..9eff030 100644 --- a/lib/sync/actions.rb +++ b/lib/sync/actions.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync module Actions # Render all sync'd partials for resource to string and publish update action @@ -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 # @@ -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 # @@ -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 = {}) @@ -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 @@ -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 # @@ -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 diff --git a/lib/sync/channel.rb b/lib/sync/channel.rb index 9c2f4d2..c4a314a 100644 --- a/lib/sync/channel.rb +++ b/lib/sync/channel.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync class Channel @@ -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 diff --git a/lib/sync/clients/dummy.rb b/lib/sync/clients/dummy.rb index 496ae9c..e65b944 100644 --- a/lib/sync/clients/dummy.rb +++ b/lib/sync/clients/dummy.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync module Clients class Dummy def method_missing(*args, &block) diff --git a/lib/sync/clients/faye.rb b/lib/sync/clients/faye.rb index 6b637c8..8f7bd33 100644 --- a/lib/sync/clients/faye.rb +++ b/lib/sync/clients/faye.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync module Clients class Faye @@ -30,7 +30,7 @@ class Message attr_accessor :channel, :data def self.batch_publish(messages) - if Sync.async? + if RenderSync.async? batch_publish_asynchronous(messages) else batch_publish_synchronous(messages) @@ -39,14 +39,14 @@ def self.batch_publish(messages) def self.batch_publish_synchronous(messages) Net::HTTP.post_form( - URI.parse(Sync.server), + URI.parse(RenderSync.server), message: batch_messages_query_hash(messages).to_json ) end def self.batch_publish_asynchronous(messages) - Sync.reactor.perform do - EM::HttpRequest.new(Sync.server).post(body: { + RenderSync.reactor.perform do + EM::HttpRequest.new(RenderSync.server).post(body: { message: batch_messages_query_hash(messages).to_json }) end @@ -56,7 +56,7 @@ def self.batch_messages_query_hash(messages) { channel: "/batch_publish", data: messages.collect(&:to_hash), - ext: { auth_token: Sync.auth_token } + ext: { auth_token: RenderSync.auth_token } } end @@ -70,7 +70,7 @@ def to_hash channel: channel, data: data, ext: { - auth_token: Sync.auth_token + auth_token: RenderSync.auth_token } } end @@ -80,7 +80,7 @@ def to_json end def publish - if Sync.async? + if RenderSync.async? publish_asynchronous else publish_synchronous @@ -88,12 +88,12 @@ def publish end def publish_synchronous - Net::HTTP.post_form URI.parse(Sync.server), message: to_json + Net::HTTP.post_form URI.parse(RenderSync.server), message: to_json end def publish_asynchronous - Sync.reactor.perform do - EM::HttpRequest.new(Sync.server).post(body: { + RenderSync.reactor.perform do + EM::HttpRequest.new(RenderSync.server).post(body: { message: self.to_json }) end @@ -101,4 +101,4 @@ def publish_asynchronous end end end -end \ No newline at end of file +end diff --git a/lib/sync/clients/pusher.rb b/lib/sync/clients/pusher.rb index f25b43a..85e6f7e 100644 --- a/lib/sync/clients/pusher.rb +++ b/lib/sync/clients/pusher.rb @@ -1,23 +1,23 @@ -module Sync +module RenderSync module Clients class Pusher def setup require 'pusher' - ::Pusher.app_id = Sync.app_id - ::Pusher.key = Sync.api_key - ::Pusher.secret = Sync.auth_token + ::Pusher.app_id = RenderSync.app_id + ::Pusher.key = RenderSync.api_key + ::Pusher.secret = RenderSync.auth_token - if Sync.pusher_api_scheme - ::Pusher.scheme = Sync.pusher_api_scheme + if RenderSync.pusher_api_scheme + ::Pusher.scheme = RenderSync.pusher_api_scheme end - if Sync.pusher_api_host - ::Pusher.host = Sync.pusher_api_host + if RenderSync.pusher_api_host + ::Pusher.host = RenderSync.pusher_api_host end - if Sync.pusher_api_port - ::Pusher.port = Sync.pusher_api_port + if RenderSync.pusher_api_port + ::Pusher.port = RenderSync.pusher_api_port end end @@ -55,7 +55,7 @@ def initialize(channel, data) end def publish - if Sync.async? + if RenderSync.async? publish_asynchronous else publish_synchronous @@ -67,7 +67,7 @@ def publish_synchronous end def publish_asynchronous - Sync.reactor.perform do + RenderSync.reactor.perform do ::Pusher.trigger_async([channel], 'sync', data) end end diff --git a/lib/sync/controller_helpers.rb b/lib/sync/controller_helpers.rb index b226756..d845794 100644 --- a/lib/sync/controller_helpers.rb +++ b/lib/sync/controller_helpers.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync module ControllerHelpers @@ -18,7 +18,7 @@ def enable_sync(options = {}) private def enable_sync - Sync::Model.enable(sync_render_context) do + RenderSync::Model.enable(sync_render_context) do yield end end diff --git a/lib/sync/engine.rb b/lib/sync/engine.rb index ccb4c63..769629a 100644 --- a/lib/sync/engine.rb +++ b/lib/sync/engine.rb @@ -1,10 +1,10 @@ -module Sync +module RenderSync class Engine < Rails::Engine # Loads the sync.yml file if it exists. initializer "sync.config", group: :all do path = Rails.root.join("config/sync.yml") - Sync.load_config(path, Rails.env) if path.exist? + RenderSync.load_config(path, Rails.env) if path.exist? end initializer "sync.activerecord" do @@ -18,7 +18,7 @@ class Engine < Rails::Engine # Adds the ControllerHelpers into ActionConroller::Base initializer "sync.controller_helpers" do - ActionController::Base.send :include, Sync::ControllerHelpers + ActionController::Base.send :include, RenderSync::ControllerHelpers end end end diff --git a/lib/sync/erb_tracker.rb b/lib/sync/erb_tracker.rb index feef11c..149d490 100644 --- a/lib/sync/erb_tracker.rb +++ b/lib/sync/erb_tracker.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync tracker_class = nil begin require 'action_view/dependency_tracker' diff --git a/lib/sync/faye_extension.rb b/lib/sync/faye_extension.rb index 7aeebe3..9f05f0f 100644 --- a/lib/sync/faye_extension.rb +++ b/lib/sync/faye_extension.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync class FayeExtension def incoming(message, callback) @@ -39,7 +39,7 @@ def handle_eror(message, callback) def message_authenticated?(message) !(message['channel'] !~ %r{^/meta/} && - message['ext']['auth_token'] != Sync.auth_token) + message['ext']['auth_token'] != RenderSync.auth_token) end end end diff --git a/lib/sync/model.rb b/lib/sync/model.rb index 1d7575d..0bee0f4 100644 --- a/lib/sync/model.rb +++ b/lib/sync/model.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync module Model def self.enabled? @@ -36,7 +36,7 @@ module ClassMethods def sync(*actions) include ModelActions unless include?(ModelActions) include ModelChangeTracking unless include?(ModelChangeTracking) - include ModelSyncing + include ModelRenderSyncing if actions.last.is_a? Hash @sync_default_scope = actions.last.fetch :default_scope @@ -46,15 +46,15 @@ def sync(*actions) actions.flatten! if actions.include? :create - after_create :prepare_sync_create, if: -> { Sync::Model.enabled? } + after_create :prepare_sync_create, if: -> { RenderSync::Model.enabled? } end if actions.include? :update - after_update :prepare_sync_update, if: -> { Sync::Model.enabled? } + after_update :prepare_sync_update, if: -> { RenderSync::Model.enabled? } end if actions.include? :destroy - after_destroy :prepare_sync_destroy, if: -> { Sync::Model.enabled? } + after_destroy :prepare_sync_destroy, if: -> { RenderSync::Model.enabled? } end end @@ -128,10 +128,10 @@ def sync_scope(name, lambda) raise ArgumentError, "invalid scope name '#{name}'. Already defined on #{self.name}" end - @sync_scope_definitions[name] = Sync::ScopeDefinition.new(self, name, lambda) + @sync_scope_definitions[name] = RenderSync::ScopeDefinition.new(self, name, lambda) singleton_class.send(:define_method, name) do |*args| - Sync::Scope.new_from_args(@sync_scope_definitions[name], args) + RenderSync::Scope.new_from_args(@sync_scope_definitions[name], args) end end @@ -157,9 +157,9 @@ def sync_touch(*args) @sync_touches ||= [] - after_create :prepare_sync_touches, if: -> { Sync::Model.enabled? } - after_update :prepare_sync_touches, if: -> { Sync::Model.enabled? } - after_destroy :prepare_sync_touches, if: -> { Sync::Model.enabled? } + after_create :prepare_sync_touches, if: -> { RenderSync::Model.enabled? } + after_update :prepare_sync_touches, if: -> { RenderSync::Model.enabled? } + after_destroy :prepare_sync_touches, if: -> { RenderSync::Model.enabled? } end options = args.extract_options! @@ -171,4 +171,4 @@ def sync_touch(*args) end end -end \ No newline at end of file +end diff --git a/lib/sync/model_actions.rb b/lib/sync/model_actions.rb index 0210c70..d88dcaa 100644 --- a/lib/sync/model_actions.rb +++ b/lib/sync/model_actions.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync module ModelActions # Set up instance variable holding the collected sync actions # to be published later on. @@ -12,11 +12,11 @@ def self.included(base) base.class_eval do @sync_scope_definitions ||= {} - before_create :prepare_sync_actions, if: -> { Sync::Model.enabled? } - before_update :prepare_sync_actions, if: -> { Sync::Model.enabled? } - before_destroy :prepare_sync_actions, if: -> { Sync::Model.enabled? } + before_create :prepare_sync_actions, if: -> { RenderSync::Model.enabled? } + before_update :prepare_sync_actions, if: -> { RenderSync::Model.enabled? } + before_destroy :prepare_sync_actions, if: -> { RenderSync::Model.enabled? } - after_commit :publish_sync_actions, if: -> { Sync::Model.enabled? } + after_commit :publish_sync_actions, if: -> { RenderSync::Model.enabled? } end end @@ -28,7 +28,7 @@ def sync_default_scope private def sync_render_context - Sync::Model.context || super + RenderSync::Model.context || super end def prepare_sync_actions @@ -53,7 +53,7 @@ def sync_scope_definitions end def sync_render_context - Sync::Model.context || super + RenderSync::Model.context || super end end diff --git a/lib/sync/model_change_tracking.rb b/lib/sync/model_change_tracking.rb index b6bb8fc..d32ec51 100644 --- a/lib/sync/model_change_tracking.rb +++ b/lib/sync/model_change_tracking.rb @@ -1,11 +1,11 @@ -module Sync +module RenderSync module ModelChangeTracking private # Set up callback to store record and sync scope states prior # the update action def self.included(base) base.class_eval do - before_update :store_state_before_update, if: -> { Sync::Model.enabled? } + before_update :store_state_before_update, if: -> { RenderSync::Model.enabled? } end end @@ -28,7 +28,7 @@ def store_state_before_update @scopes_before_update = {} sync_scope_definitions.each do |definition| - scope = Sync::Scope.new_from_model(definition, record) + scope = RenderSync::Scope.new_from_model(definition, record) @scopes_before_update[definition.name] = { scope: scope, contains_record: scope.contains?(record) @@ -74,7 +74,7 @@ def scope_before_update(definition) end def scope_after_update(definition) - Sync::Scope.new_from_model(definition, record_after_update) + RenderSync::Scope.new_from_model(definition, record_after_update) end def old_record_in_old_scope?(definition) diff --git a/lib/sync/model_syncing.rb b/lib/sync/model_syncing.rb index 2087ecc..7b38991 100644 --- a/lib/sync/model_syncing.rb +++ b/lib/sync/model_syncing.rb @@ -1,5 +1,5 @@ -module Sync - module ModelSyncing +module RenderSync + module ModelRenderSyncing private @@ -7,7 +7,7 @@ def prepare_sync_create add_sync_action(:new, self, default_scope: sync_default_scope) sync_scope_definitions.each do |definition| - scope = Sync::Scope.new_from_model(definition, self) + scope = RenderSync::Scope.new_from_model(definition, self) if scope.contains?(self) add_sync_action :new, self, scope: scope, default_scope: sync_default_scope end @@ -26,7 +26,7 @@ def prepare_sync_destroy add_sync_action :destroy, self, default_scope: sync_default_scope sync_scope_definitions.each do |definition| - scope = Sync::Scope.new_from_model(definition, self) + scope = RenderSync::Scope.new_from_model(definition, self) if scope.valid? add_sync_action :destroy, self, scope: scope, diff --git a/lib/sync/model_touching.rb b/lib/sync/model_touching.rb index bb977ca..76ed067 100644 --- a/lib/sync/model_touching.rb +++ b/lib/sync/model_touching.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync module ModelTouching private @@ -32,4 +32,4 @@ def sync_touches end end -end \ No newline at end of file +end diff --git a/lib/sync/partial.rb b/lib/sync/partial.rb index 57c9355..ee6e6aa 100644 --- a/lib/sync/partial.rb +++ b/lib/sync/partial.rb @@ -1,11 +1,11 @@ -module Sync +module RenderSync class Partial attr_accessor :name, :resource, :context def self.all(model, context, scope = nil) resource = Resource.new(model, scope) - Dir["#{Sync.views_root}/#{resource.plural_name}/_*.*"].map do |partial| + Dir["#{RenderSync.views_root}/#{resource.plural_name}/_*.*"].map do |partial| partial_name = File.basename(partial) Partial.new(partial_name[1...partial_name.index('.')], resource.model, scope, context) end @@ -38,7 +38,7 @@ def sync(action) end def message(action) - Sync.client.build_message channel_for_action(action), + RenderSync.client.build_message channel_for_action(action), html: (render_to_string unless action.to_s == "destroy") end diff --git a/lib/sync/partial_creator.rb b/lib/sync/partial_creator.rb index a64b409..2ba74c5 100644 --- a/lib/sync/partial_creator.rb +++ b/lib/sync/partial_creator.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync class PartialCreator attr_accessor :name, :resource, :context, :partial @@ -26,7 +26,7 @@ def sync_new end def message - Sync.client.build_message(channel, + RenderSync.client.build_message(channel, html: partial.render_to_string, resourceId: resource.id, authToken: partial.auth_token, diff --git a/lib/sync/reactor.rb b/lib/sync/reactor.rb index 047e94d..cd732a5 100644 --- a/lib/sync/reactor.rb +++ b/lib/sync/reactor.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync class Reactor include MonitorMixin @@ -45,4 +45,4 @@ def cleanly_shutdown_reactor end end end -end \ No newline at end of file +end diff --git a/lib/sync/refetch_model.rb b/lib/sync/refetch_model.rb index eb94133..2cb1664 100644 --- a/lib/sync/refetch_model.rb +++ b/lib/sync/refetch_model.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync class RefetchModel def self.find_by_class_name_and_id(resource_name, id) @@ -18,4 +18,4 @@ def self.supported_classes end end end -end \ No newline at end of file +end diff --git a/lib/sync/refetch_partial.rb b/lib/sync/refetch_partial.rb index 715c82c..a2f620b 100644 --- a/lib/sync/refetch_partial.rb +++ b/lib/sync/refetch_partial.rb @@ -1,10 +1,10 @@ -module Sync +module RenderSync class RefetchPartial < Partial def self.all(model, context, scope = nil) resource = Resource.new(model) - Dir["#{Sync.views_root}/#{resource.plural_name}/refetch/_*.*"].map do |partial| + Dir["#{RenderSync.views_root}/#{resource.plural_name}/refetch/_*.*"].map do |partial| partial_name = File.basename(partial) RefetchPartial.new(partial_name[1...partial_name.index('.')], resource.model, scope, context) end @@ -13,7 +13,7 @@ def self.all(model, context, scope = nil) def self.find(model, partial_name, context) resource = Resource.new(model) plural_name = resource.plural_name - partial = Dir["#{Sync.views_root}/#{plural_name}/refetch/_#{partial_name}.*"].first + partial = Dir["#{RenderSync.views_root}/#{plural_name}/refetch/_#{partial_name}.*"].first return unless partial RefetchPartial.new(partial_name, resource.model, nil, context) end @@ -26,7 +26,7 @@ def self.find_by_authorized_resource(model, partial_name, context, auth_token) end def message(action) - Sync.client.build_message channel_for_action(action), refetch: true + RenderSync.client.build_message channel_for_action(action), refetch: true end def creator_for_scope(scope) diff --git a/lib/sync/refetch_partial_creator.rb b/lib/sync/refetch_partial_creator.rb index 6a24991..ce237e0 100644 --- a/lib/sync/refetch_partial_creator.rb +++ b/lib/sync/refetch_partial_creator.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync class RefetchPartialCreator < PartialCreator def initialize(name, resource, scoped_resource, context) @@ -7,7 +7,7 @@ def initialize(name, resource, scoped_resource, context) end def message - Sync.client.build_message(channel, + RenderSync.client.build_message(channel, refetch: true, resourceId: resource.id, authToken: partial.auth_token, diff --git a/lib/sync/renderer.rb b/lib/sync/renderer.rb index aa0ea45..74f0865 100644 --- a/lib/sync/renderer.rb +++ b/lib/sync/renderer.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync class Renderer attr_accessor :context @@ -16,4 +16,4 @@ def render_to_string(options) context.render(options) end end -end \ No newline at end of file +end diff --git a/lib/sync/resource.rb b/lib/sync/resource.rb index da1bb94..3e60063 100644 --- a/lib/sync/resource.rb +++ b/lib/sync/resource.rb @@ -1,6 +1,6 @@ require 'pathname' -module Sync +module RenderSync class Resource attr_accessor :model, :scopes @@ -8,7 +8,7 @@ class Resource # # model - The ActiveModel instace for this Resource # scopes - The optional scopes to prefix polymorphic paths with. - # Can be a Symbol/String, a parent model or an Sync::Scope + # Can be a Symbol/String, a parent model or an RenderSync::Scope # or an Array with any combination. # # Examples @@ -83,7 +83,7 @@ def scopes_path path = Pathname.new('/') unless scopes.nil? paths = scopes.map do |scope| - if scope.is_a?(Sync::Scope) + if scope.is_a?(RenderSync::Scope) scope.polymorphic_path.relative_path_from(path) elsif scope.class.respond_to? :model_name Resource.new(scope).polymorphic_path.relative_path_from(path) diff --git a/lib/sync/scope.rb b/lib/sync/scope.rb index 31e11fc..1ddbb1b 100644 --- a/lib/sync/scope.rb +++ b/lib/sync/scope.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync class Scope attr_accessor :scope_definition, :args, :valid diff --git a/lib/sync/scope_definition.rb b/lib/sync/scope_definition.rb index 190cc31..ec4d738 100644 --- a/lib/sync/scope_definition.rb +++ b/lib/sync/scope_definition.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync class ScopeDefinition attr_accessor :klass, :name, :lambda, :parameters, :args diff --git a/lib/sync/view_helpers.rb b/lib/sync/view_helpers.rb index 72de825..49c0bd8 100644 --- a/lib/sync/view_helpers.rb +++ b/lib/sync/view_helpers.rb @@ -1,4 +1,4 @@ -module Sync +module RenderSync module ViewHelpers @@ -17,7 +17,7 @@ module ViewHelpers # def sync(options = {}) collection = options[:collection] || [options.fetch(:resource)] - scope = options[:channel] || options[:scope] || (collection.is_a?(Sync::Scope) ? collection : nil) + scope = options[:channel] || options[:scope] || (collection.is_a?(RenderSync::Scope) ? collection : nil) partial_name = options.fetch(:partial, scope) refetch = options.fetch(:refetch, false) @@ -30,8 +30,8 @@ def sync(options = {}) end results << "