Module: RenderSync
- Defined in:
- lib/render_sync.rb,
lib/render_sync/model.rb,
lib/render_sync/scope.rb,
lib/render_sync/action.rb,
lib/render_sync/engine.rb,
lib/render_sync/actions.rb,
lib/render_sync/channel.rb,
lib/render_sync/partial.rb,
lib/render_sync/reactor.rb,
lib/render_sync/renderer.rb,
lib/render_sync/resource.rb,
lib/render_sync/erb_tracker.rb,
lib/render_sync/clients/faye.rb,
lib/render_sync/view_helpers.rb,
lib/render_sync/clients/dummy.rb,
lib/render_sync/model_actions.rb,
lib/render_sync/model_syncing.rb,
lib/render_sync/refetch_model.rb,
lib/render_sync/clients/pusher.rb,
lib/render_sync/faye_extension.rb,
lib/render_sync/model_touching.rb,
lib/render_sync/partial_creator.rb,
lib/render_sync/refetch_partial.rb,
lib/render_sync/scope_definition.rb,
lib/render_sync/controller_helpers.rb,
lib/render_sync/model_change_tracking.rb,
lib/render_sync/refetch_partial_creator.rb,
lib/generators/render_sync/install_generator.rb
Defined Under Namespace
Modules: Actions, Clients, ConfigHelper, ControllerHelpers, Generators, Model, ModelActions, ModelChangeTracking, ModelRenderSyncing, ModelTouching, ViewHelpers
Classes: Action, Channel, ERBTracker, Engine, FayeExtension, Partial, PartialCreator, Reactor, RefetchModel, RefetchPartial, RefetchPartialCreator, RefetchesController, Renderer, Resource, Scope, ScopeDefinition
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.client ⇒ Object
Returns the value of attribute client.
40
41
42
|
# File 'lib/render_sync.rb', line 40
def client
@client
end
|
.config ⇒ Object
Returns the value of attribute config.
40
41
42
|
# File 'lib/render_sync.rb', line 40
def config
@config
end
|
.logger ⇒ Object
Returns the value of attribute logger.
40
41
42
|
# File 'lib/render_sync.rb', line 40
def logger
@logger
end
|
Class Method Details
.adapter ⇒ Object
112
113
114
|
# File 'lib/render_sync.rb', line 112
def adapter
config[:adapter]
end
|
.adapter_javascript_url ⇒ Object
104
105
106
|
# File 'lib/render_sync.rb', line 104
def adapter_javascript_url
config[:adapter_javascript_url]
end
|
.api_key ⇒ Object
120
121
122
|
# File 'lib/render_sync.rb', line 120
def api_key
config[:api_key]
end
|
.app_id ⇒ Object
116
117
118
|
# File 'lib/render_sync.rb', line 116
def app_id
config[:app_id]
end
|
.async? ⇒ Boolean
96
97
98
|
# File 'lib/render_sync.rb', line 96
def async?
config[:async]
end
|
.auth_token ⇒ Object
108
109
110
|
# File 'lib/render_sync.rb', line 108
def auth_token
config[:auth_token]
end
|
.config_json ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# 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) ⇒ Object
Loads the configuration from a given YAML file and environment (such as production)
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# 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 = {}) ⇒ Object
Returns the Faye Rack application. Any options given are passed to the Faye::RackAdapter.
162
163
164
165
166
167
168
|
# 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 ⇒ Object
128
129
130
|
# File 'lib/render_sync.rb', line 128
def pusher_api_host
config[:pusher_api_host]
end
|
.pusher_api_port ⇒ Object
132
133
134
|
# File 'lib/render_sync.rb', line 132
def pusher_api_port
config[:pusher_api_port]
end
|
.pusher_api_scheme ⇒ Object
124
125
126
|
# File 'lib/render_sync.rb', line 124
def pusher_api_scheme
config[:pusher_api_scheme]
end
|
.pusher_encrypted ⇒ Object
148
149
150
151
152
153
154
|
# 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 ⇒ Object
136
137
138
|
# File 'lib/render_sync.rb', line 136
def pusher_ws_host
config[:pusher_ws_host]
end
|
.pusher_ws_port ⇒ Object
140
141
142
|
# File 'lib/render_sync.rb', line 140
def pusher_ws_port
config[:pusher_ws_port]
end
|
.pusher_wss_port ⇒ Object
144
145
146
|
# File 'lib/render_sync.rb', line 144
def pusher_wss_port
config[:pusher_wss_port]
end
|
.reactor ⇒ Object
156
157
158
|
# File 'lib/render_sync.rb', line 156
def reactor
@reactor ||= Reactor.new
end
|
.reset_config ⇒ Object
Resets the configuration to the default (empty hash)
61
62
63
64
|
# File 'lib/render_sync.rb', line 61
def reset_config
@config = {}
@config_json = nil
end
|
.server ⇒ Object
100
101
102
|
# File 'lib/render_sync.rb', line 100
def server
config[:server]
end
|
.setup_client ⇒ Object
81
82
83
84
85
|
# 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 ⇒ Object
87
88
89
90
|
# 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 ⇒ Object
92
93
94
|
# File 'lib/render_sync.rb', line 92
def setup_logger
@logger = (defined?(Rails) && Rails.logger) ? Rails.logger : Logger.new(STDOUT)
end
|
.views_root ⇒ Object
170
171
172
|
# File 'lib/render_sync.rb', line 170
def views_root
Rails.root.join('app', 'views', 'sync')
end
|