module RenderSync

Attributes

client[RW]
config[RW]
logger[RW]

Public Class Methods

adapter() click to toggle source
# File lib/render_sync.rb, line 112
def adapter
  config[:adapter]
end
adapter_javascript_url() click to toggle source
# File lib/render_sync.rb, line 104
def adapter_javascript_url
  config[:adapter_javascript_url]
end
api_key() click to toggle source
# File lib/render_sync.rb, line 120
def api_key
  config[:api_key]
end
app_id() click to toggle source
# File lib/render_sync.rb, line 116
def app_id
  config[:app_id]
end
async?() click to toggle source
# File lib/render_sync.rb, line 96
def async?
  config[:async]
end
auth_token() click to toggle source
# File lib/render_sync.rb, line 108
def auth_token
  config[:auth_token]
end
config_json() click to toggle source
# File lib/render_sync.rb, line 46
def config_json
  @config_json ||= begin
    {
      server: server,
      api_key: api_key,
      pusher_ws_host: pusher_ws_host,
      pusher_ws_port: pusher_ws_port,
      pusher_wss_port: pusher_wss_port,
      pusher_encrypted: pusher_encrypted,
      adapter: adapter
    }.reject { |k, v| v.nil? }.to_json
  end
end
load_config(filename, environment) click to toggle source

Loads the configuration from a given YAML file and environment (such as production)

# File lib/render_sync.rb, line 67
def load_config(filename, environment)
  reset_config
  yaml = YAML.load(ERB.new(File.read(filename)).result)[environment.to_s]
  raise ArgumentError, "The #{environment} environment does not exist in #{filename}" if yaml.nil?
  yaml.each{|key, value| config[key.to_sym] = value }
  setup_logger

  if adapter
    setup_client
  else
    setup_dummy_client
  end
end
pubsub_app(options = {}) click to toggle source

Returns the Faye Rack application. Any options given are passed to the Faye::RackAdapter.

# File lib/render_sync.rb, line 162
def pubsub_app(options = {})
  Faye::RackAdapter.new({
    mount: config[:mount] || "/faye",
    timeout: config[:timeout] || 45,
    extensions: [FayeExtension.new]
  }.merge(options))
end
pusher_api_host() click to toggle source
# File lib/render_sync.rb, line 128
def pusher_api_host
  config[:pusher_api_host]
end
pusher_api_port() click to toggle source
# File lib/render_sync.rb, line 132
def pusher_api_port
  config[:pusher_api_port]
end
pusher_api_scheme() click to toggle source
# File lib/render_sync.rb, line 124
def pusher_api_scheme
  config[:pusher_api_scheme]
end
pusher_encrypted() click to toggle source
# File lib/render_sync.rb, line 148
def pusher_encrypted
  if config[:pusher_encrypted].nil?
    true
  else
    config[:pusher_encrypted]
  end
end
pusher_ws_host() click to toggle source
# File lib/render_sync.rb, line 136
def pusher_ws_host
  config[:pusher_ws_host]
end
pusher_ws_port() click to toggle source
# File lib/render_sync.rb, line 140
def pusher_ws_port
  config[:pusher_ws_port]
end
pusher_wss_port() click to toggle source
# File lib/render_sync.rb, line 144
def pusher_wss_port
  config[:pusher_wss_port]
end
reactor() click to toggle source
# File lib/render_sync.rb, line 156
def reactor
  @reactor ||= Reactor.new
end
reset_config() click to toggle source

Resets the configuration to the default (empty hash)

# File lib/render_sync.rb, line 61
def reset_config
  @config = {}
  @config_json = nil
end
server() click to toggle source
# File lib/render_sync.rb, line 100
def server
  config[:server]
end
setup_client() click to toggle source
# File lib/render_sync.rb, line 81
def setup_client
  raise ArgumentError, "auth_token missing" if config[:auth_token].nil?
  @client = RenderSync::Clients.const_get(adapter).new
  @client.setup
end
setup_dummy_client() click to toggle source
# File lib/render_sync.rb, line 87
def setup_dummy_client
  config[:auth_token] = 'dummy_auth_token'
  @client = RenderSync::Clients::Dummy.new
end
setup_logger() click to toggle source
# File lib/render_sync.rb, line 92
def setup_logger
  @logger = (defined?(Rails) && Rails.logger) ? Rails.logger : Logger.new(STDOUT)
end
views_root() click to toggle source
# File lib/render_sync.rb, line 170
def views_root
  Rails.root.join('app', 'views', 'sync')
end