module Synchronisable
Public Class Methods
config()
click to toggle source
# File lib/synchronisable.rb, line 26 def self.config @configuration ||= Configuration.new end
configure() { |config| ... }
click to toggle source
# File lib/synchronisable.rb, line 30 def self.configure yield config end
sync(*args)
click to toggle source
Syncs models that are defined in {Synchronisable#models}
@overload sync(models, options)
@param models [Array] array of models that should be synchronized. This take a precedence over models defined in {Synchronisable#models}. If this parameter is not specified and {Synchronisable#models} is empty, than it will try to sync only those models which have a corresponding synchronizers @param options [Hash] options that will be passed to controller
@overload sync(models) @overlaod sync(options)
@return [Array<>] array of synchronization contexts
# File lib/synchronisable.rb, line 48 def self.sync(*args) options = args.extract_options! source = source_models(args) source.map { |model| model.sync(options) } end
Private Class Methods
default_models()
click to toggle source
# File lib/synchronisable.rb, line 62 def self.default_models config.models.map(&:safe_constantize).compact end
find_models()
click to toggle source
# File lib/synchronisable.rb, line 66 def self.find_models # Need to preload models first Rails.application.eager_load! ActiveRecord::Base.descendants.select do |model| model.included_modules.include?(Synchronisable::Model) && model.synchronisable? end end
source_models(models)
click to toggle source
# File lib/synchronisable.rb, line 56 def self.source_models(models) source = models.present? ? models : default_models source = source.present? ? source : find_models source.sort { |lhs, rhs| lhs.synchronizer.order <=> rhs.synchronizer.order } end