volt 0.9.4.pre3 → 0.9.4.pre5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/CODE_OF_CONDUCT.md +15 -0
- data/README.md +2 -0
- data/app/volt/models/user.rb +6 -4
- data/lib/volt/boot.rb +0 -2
- data/lib/volt/cli/bundle.rb +29 -0
- data/lib/volt/cli/console.rb +2 -2
- data/lib/volt/cli/generate.rb +2 -0
- data/lib/volt/cli/new_gem.rb +23 -0
- data/lib/volt/cli.rb +15 -2
- data/lib/volt/controllers/collection_helpers.rb +34 -3
- data/lib/volt/controllers/http_controller.rb +1 -1
- data/lib/volt/controllers/model_controller.rb +9 -33
- data/lib/volt/helpers/time.rb +43 -0
- data/lib/volt/models/array_model.rb +96 -90
- data/lib/volt/models/buffer.rb +42 -7
- data/lib/volt/models/helpers/array_model.rb +15 -0
- data/lib/volt/models/helpers/base.rb +113 -0
- data/lib/volt/models/helpers/change_helpers.rb +91 -0
- data/lib/volt/models/helpers/dirty.rb +93 -0
- data/lib/volt/models/helpers/listener_tracker.rb +19 -0
- data/lib/volt/models/helpers/model.rb +15 -0
- data/lib/volt/models/model.rb +17 -12
- data/lib/volt/models/permissions.rb +1 -1
- data/lib/volt/models/persistors/array_store.rb +4 -0
- data/lib/volt/models/persistors/base.rb +10 -0
- data/lib/volt/models/persistors/cookies.rb +2 -0
- data/lib/volt/models/persistors/local_store.rb +3 -0
- data/lib/volt/models/persistors/model_store.rb +7 -0
- data/lib/volt/models/persistors/params.rb +4 -1
- data/lib/volt/models/persistors/query/query_listener.rb +1 -1
- data/lib/volt/models/url.rb +12 -7
- data/lib/volt/models/validators/unique_validator.rb +1 -1
- data/lib/volt/page/bindings/base_binding.rb +2 -2
- data/lib/volt/page/bindings/event_binding.rb +2 -2
- data/lib/volt/page/bindings/view_binding/controller_handler.rb +20 -0
- data/lib/volt/page/bindings/view_binding/view_lookup_for_path.rb +6 -4
- data/lib/volt/page/bindings/view_binding.rb +7 -7
- data/lib/volt/page/path_string_renderer.rb +2 -4
- data/lib/volt/page/targets/base_section.rb +3 -3
- data/lib/volt/page/targets/dom_template.rb +2 -2
- data/lib/volt/page/tasks.rb +6 -6
- data/lib/volt/page/template_renderer.rb +1 -1
- data/lib/volt/page/url_tracker.rb +4 -4
- data/lib/volt/reactive/reactive_array.rb +31 -20
- data/lib/volt/server/component_templates.rb +5 -5
- data/lib/volt/server/forking_server.rb +2 -2
- data/lib/volt/server/message_bus/peer_to_peer/server_tracker.rb +3 -3
- data/lib/volt/server/message_bus/peer_to_peer.rb +7 -7
- data/lib/volt/server/rack/asset_files.rb +28 -8
- data/lib/volt/server/rack/component_paths.rb +4 -4
- data/lib/volt/server/rack/opal_files.rb +0 -1
- data/lib/volt/server/socket_connection_handler.rb +5 -2
- data/lib/volt/server.rb +0 -1
- data/lib/volt/spec/setup.rb +4 -5
- data/lib/volt/tasks/task.rb +2 -3
- data/lib/volt/utils/promise_extensions.rb +22 -6
- data/lib/volt/utils/time_patch.rb +12 -0
- data/lib/volt/utils/timers.rb +14 -2
- data/lib/volt/version.rb +1 -1
- data/lib/volt/volt/app.rb +44 -12
- data/lib/volt/volt/client_setup/browser.rb +113 -0
- data/lib/volt/volt/repos.rb +48 -0
- data/lib/volt/volt/server_setup/app.rb +1 -2
- data/lib/volt/volt/templates.rb +39 -0
- data/lib/volt/volt/users.rb +4 -4
- data/lib/volt.rb +1 -0
- data/spec/apps/file_loading/app/disable_auto/assets/css/test1.css.scss +0 -0
- data/spec/apps/file_loading/app/disable_auto/assets/css/test2.css.scss +0 -0
- data/spec/apps/file_loading/app/disable_auto/assets/js/test1.js +0 -0
- data/spec/apps/file_loading/app/disable_auto/assets/js/test2.js +0 -0
- data/spec/apps/file_loading/app/disable_auto/config/dependencies.rb +3 -0
- data/spec/apps/file_loading/app/main/assets/css/test3.css +0 -0
- data/spec/apps/file_loading/app/shared/config/dependencies.rb +1 -1
- data/spec/controllers/model_controller_spec.rb +7 -0
- data/spec/models/{model_helpers/model_helpers_spec.rb → helpers/base_spec.rb} +1 -1
- data/spec/models/helpers/model_spec.rb +26 -0
- data/spec/models/model_spec.rb +9 -0
- data/spec/models/persistors/params_spec.rb +1 -1
- data/spec/models/persistors/store_spec.rb +1 -0
- data/spec/page/bindings/content_binding_spec.rb +2 -4
- data/spec/page/bindings/each_binding_spec.rb +1 -4
- data/spec/page/bindings/if_binding_spec.rb +1 -4
- data/spec/page/bindings/template_binding/view_lookup_for_path_spec.rb +17 -27
- data/spec/page/path_string_renderer_spec.rb +15 -4
- data/spec/server/rack/asset_files_spec.rb +88 -8
- data/spec/tasks/user_tasks_spec.rb +1 -1
- data/spec/utils/promise_extensions_spec.rb +22 -0
- data/spec/volt/repos_spec.rb +11 -0
- data/templates/newgem/CODE_OF_CONDUCT.md.tt +13 -0
- data/templates/project/app/main/config/routes.rb +4 -1
- metadata +34 -10
- data/lib/volt/models/model_helpers/dirty.rb +0 -88
- data/lib/volt/models/model_helpers/listener_tracker.rb +0 -15
- data/lib/volt/models/model_helpers/model_change_helpers.rb +0 -87
- data/lib/volt/models/model_helpers/model_helpers.rb +0 -110
- data/lib/volt/models/state_helpers.rb +0 -11
- data/lib/volt/page/page.rb +0 -190
@@ -65,12 +65,12 @@ module Volt
|
|
65
65
|
# end
|
66
66
|
|
67
67
|
end
|
68
|
-
@listener =
|
68
|
+
@listener = browser.events.add(@event_name, self, handler)
|
69
69
|
end
|
70
70
|
|
71
71
|
# Remove the event binding
|
72
72
|
def remove
|
73
|
-
|
73
|
+
browser.events.remove(@event_name, self)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -2,9 +2,23 @@ module Volt
|
|
2
2
|
class ControllerHandler
|
3
3
|
attr_reader :controller, :action
|
4
4
|
|
5
|
+
# Checks to see if a controller has a handler, and if not creates one.
|
6
|
+
def self.fetch(controller, action)
|
7
|
+
inst = controller.instance_variable_get('@__handler')
|
8
|
+
|
9
|
+
unless inst
|
10
|
+
inst = new(controller, action)
|
11
|
+
controller.instance_variable_set('@__handler', inst)
|
12
|
+
end
|
13
|
+
|
14
|
+
inst
|
15
|
+
end
|
16
|
+
|
5
17
|
def initialize(controller, action)
|
6
18
|
@controller = controller
|
7
19
|
@action = action.to_sym if action
|
20
|
+
|
21
|
+
@called_methods = {}
|
8
22
|
end
|
9
23
|
|
10
24
|
def call_action(stage_prefix = nil, stage_suffix = nil)
|
@@ -22,6 +36,12 @@ module Volt
|
|
22
36
|
method_name = @action
|
23
37
|
end
|
24
38
|
|
39
|
+
# Don't call if its already been called
|
40
|
+
return if @called_methods[method_name]
|
41
|
+
|
42
|
+
# Track that this method got called
|
43
|
+
@called_methods[method_name] = true
|
44
|
+
|
25
45
|
# If no stage, then we are calling the main action method,
|
26
46
|
# so we should call the before/after actions
|
27
47
|
unless has_stage
|
@@ -5,10 +5,10 @@ module Volt
|
|
5
5
|
# Takes in the path of the current view file. This allows for relative paths
|
6
6
|
# to be run.
|
7
7
|
#
|
8
|
-
# @param [
|
8
|
+
# @param [Hash] the templates object from a Volt::App
|
9
9
|
# @param [String] the path of the current view
|
10
|
-
def initialize(
|
11
|
-
@
|
10
|
+
def initialize(templates, binding_in_path)
|
11
|
+
@templates = templates
|
12
12
|
path_parts = binding_in_path.split('/')
|
13
13
|
@collection_name = path_parts[0]
|
14
14
|
@controller_name = path_parts[1]
|
@@ -17,7 +17,7 @@ module Volt
|
|
17
17
|
|
18
18
|
# Returns true if there is a template at the path
|
19
19
|
def check_for_template?(path)
|
20
|
-
@
|
20
|
+
@templates[path]
|
21
21
|
end
|
22
22
|
|
23
23
|
# Takes in a lookup path and returns the full path for the matching
|
@@ -45,6 +45,8 @@ module Volt
|
|
45
45
|
parts = lookup_path.split('/')
|
46
46
|
parts_size = parts.size
|
47
47
|
|
48
|
+
return nil, nil if parts_size == 0
|
49
|
+
|
48
50
|
default_parts = %w(main main index body)
|
49
51
|
|
50
52
|
# When forcing a sub template, we can default the sub template section
|
@@ -16,7 +16,7 @@ module Volt
|
|
16
16
|
@content_template_path = content_template_path
|
17
17
|
|
18
18
|
# Setup the view lookup helper
|
19
|
-
@view_lookup = Volt::ViewLookupForPath.new(
|
19
|
+
@view_lookup = Volt::ViewLookupForPath.new(volt_app.templates, binding_in_path)
|
20
20
|
|
21
21
|
@current_template = nil
|
22
22
|
|
@@ -105,9 +105,9 @@ module Volt
|
|
105
105
|
@controller = @current_controller_handler.controller if full_path
|
106
106
|
|
107
107
|
render_template(full_path || path)
|
108
|
-
rescue => e
|
109
|
-
|
110
|
-
|
108
|
+
# rescue => e
|
109
|
+
# Volt.logger.error("Error during render of template at #{path}: #{e.inspect}")
|
110
|
+
# Volt.logger.error(e.backtrace)
|
111
111
|
end
|
112
112
|
|
113
113
|
def stop_waiting_for_load
|
@@ -201,7 +201,7 @@ module Volt
|
|
201
201
|
controller = new_controller.call
|
202
202
|
end
|
203
203
|
|
204
|
-
handler = ControllerHandler.
|
204
|
+
handler = ControllerHandler.fetch(controller, action)
|
205
205
|
|
206
206
|
if generated_new
|
207
207
|
# Call the action
|
@@ -216,8 +216,8 @@ module Volt
|
|
216
216
|
end
|
217
217
|
|
218
218
|
# The context for templates can be either a controller, or the original context.
|
219
|
-
def render_template(full_path
|
220
|
-
@current_template = TemplateRenderer.new(@volt_app, @target, @controller, @binding_name, full_path
|
219
|
+
def render_template(full_path)
|
220
|
+
@current_template = TemplateRenderer.new(@volt_app, @target, @controller, @binding_name, full_path)
|
221
221
|
|
222
222
|
call_ready
|
223
223
|
end
|
@@ -9,14 +9,12 @@ module Volt
|
|
9
9
|
class ViewLookupException < Exception; end
|
10
10
|
class PathStringRenderer
|
11
11
|
attr_reader :html
|
12
|
-
def initialize(volt_app, path, attrs = nil,
|
12
|
+
def initialize(volt_app, path, attrs = nil, render_from_path = nil)
|
13
13
|
# where to do the path lookup from
|
14
14
|
render_from_path ||= 'main/main/main/body'
|
15
15
|
|
16
|
-
page ||= volt_app.page
|
17
|
-
|
18
16
|
# Make path into a full path
|
19
|
-
@view_lookup = Volt::ViewLookupForPath.new(
|
17
|
+
@view_lookup = Volt::ViewLookupForPath.new(volt_app.templates, render_from_path)
|
20
18
|
full_path, controller_path = @view_lookup.path_for_template(path, nil)
|
21
19
|
|
22
20
|
if full_path.nil?
|
@@ -21,14 +21,14 @@ module Volt
|
|
21
21
|
fail 'set_template is not implemented'
|
22
22
|
end
|
23
23
|
|
24
|
-
def set_content_to_template(
|
24
|
+
def set_content_to_template(volt_app, template_name)
|
25
25
|
if self.is_a?(DomSection)
|
26
26
|
# DomTemplates are an optimization when working with the DOM (as opposed to other targets)
|
27
|
-
dom_template = (@@template_cache[template_name] ||= DomTemplate.new(
|
27
|
+
dom_template = (@@template_cache[template_name] ||= DomTemplate.new(volt_app, template_name))
|
28
28
|
|
29
29
|
set_template(dom_template)
|
30
30
|
else
|
31
|
-
template =
|
31
|
+
template = volt_app.templates[template_name]
|
32
32
|
|
33
33
|
if template
|
34
34
|
html = template['html']
|
@@ -9,8 +9,8 @@ module Volt
|
|
9
9
|
class DomTemplate
|
10
10
|
include CommentSearchers
|
11
11
|
|
12
|
-
def initialize(
|
13
|
-
template =
|
12
|
+
def initialize(volt_app, template_name)
|
13
|
+
template = volt_app.templates[template_name]
|
14
14
|
|
15
15
|
if template
|
16
16
|
html = template['html']
|
data/lib/volt/page/tasks.rb
CHANGED
@@ -4,12 +4,12 @@ module Volt
|
|
4
4
|
# The tasks class provides an interface to call tasks on
|
5
5
|
# the backend server. This class is setup as page.task (as a singleton)
|
6
6
|
class Tasks
|
7
|
-
def initialize(
|
8
|
-
@
|
7
|
+
def initialize(volt_app)
|
8
|
+
@volt_app = volt_app
|
9
9
|
@promise_id = 0
|
10
10
|
@promises = {}
|
11
11
|
|
12
|
-
|
12
|
+
volt_app.channel.on('message') do |*args|
|
13
13
|
received_message(*args)
|
14
14
|
end
|
15
15
|
end
|
@@ -23,7 +23,7 @@ module Volt
|
|
23
23
|
@promises[promise_id] = promise
|
24
24
|
|
25
25
|
# TODO: Timeout on these callbacks
|
26
|
-
@
|
26
|
+
@volt_app.channel.send_message([promise_id, class_name, method_name, meta_data, *args])
|
27
27
|
|
28
28
|
promise
|
29
29
|
end
|
@@ -65,13 +65,13 @@ module Volt
|
|
65
65
|
|
66
66
|
def reload
|
67
67
|
# Stash the current page value
|
68
|
-
value = EJSON.stringify(
|
68
|
+
value = EJSON.stringify(Volt.current_app.page.to_h)
|
69
69
|
|
70
70
|
# If this browser supports session storage, store the page, so it will
|
71
71
|
# be in the same state when we reload.
|
72
72
|
`sessionStorage.setItem('___page', value);` if `sessionStorage`
|
73
73
|
|
74
|
-
|
74
|
+
Volt.current_app.page._reloading = true
|
75
75
|
`window.location.reload(false);`
|
76
76
|
end
|
77
77
|
end
|
@@ -9,7 +9,7 @@ module Volt
|
|
9
9
|
|
10
10
|
@sub_bindings = []
|
11
11
|
|
12
|
-
bindings = dom_section.set_content_to_template(volt_app
|
12
|
+
bindings = dom_section.set_content_to_template(volt_app, template_name)
|
13
13
|
|
14
14
|
bindings.each_pair do |id, bindings_for_id|
|
15
15
|
bindings_for_id.each do |binding|
|
@@ -3,8 +3,8 @@ module Volt
|
|
3
3
|
# a param changes, or updating the url model/params when
|
4
4
|
# the browser url changes.
|
5
5
|
class UrlTracker
|
6
|
-
def initialize(
|
7
|
-
@
|
6
|
+
def initialize(volt_app)
|
7
|
+
@volt_app = volt_app
|
8
8
|
|
9
9
|
if Volt.client?
|
10
10
|
that = self
|
@@ -21,8 +21,8 @@ module Volt
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def url_updated(first_call = false)
|
24
|
-
@
|
25
|
-
@
|
24
|
+
@volt_app.url.parse(`document.location.href`)
|
25
|
+
@volt_app.url.update! unless first_call
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -160,31 +160,17 @@ module Volt
|
|
160
160
|
end
|
161
161
|
|
162
162
|
def clear
|
163
|
-
|
164
|
-
|
165
|
-
deps = @array_deps
|
166
|
-
@array_deps = []
|
167
|
-
|
168
|
-
# Trigger remove for each cell
|
169
|
-
old_size.times do |index|
|
170
|
-
trigger_removed!(old_size - index - 1)
|
171
|
-
end
|
172
|
-
|
173
|
-
# Trigger on each cell since we are clearing out the array
|
174
|
-
if deps
|
175
|
-
deps.each do |dep|
|
176
|
-
dep.changed! if dep
|
177
|
-
end
|
178
|
-
end
|
163
|
+
__clear
|
179
164
|
|
180
165
|
@persistor.clear if @persistor
|
181
|
-
|
182
|
-
# clear the array
|
183
|
-
@array = []
|
184
166
|
end
|
185
167
|
|
186
168
|
# alias :__old_append :<<
|
187
|
-
def <<(
|
169
|
+
def <<(*args)
|
170
|
+
append(*args)
|
171
|
+
end
|
172
|
+
|
173
|
+
def append(value)
|
188
174
|
result = (@array << value)
|
189
175
|
|
190
176
|
trigger_for_index!(@array.size - 1)
|
@@ -236,6 +222,31 @@ module Volt
|
|
236
222
|
|
237
223
|
private
|
238
224
|
|
225
|
+
# used internally, clears out the array, triggers the change events, but
|
226
|
+
# does not call clear on the persistors. Used when models are updated
|
227
|
+
# externally.
|
228
|
+
def __clear
|
229
|
+
old_size = @array.size
|
230
|
+
|
231
|
+
deps = @array_deps
|
232
|
+
@array_deps = []
|
233
|
+
|
234
|
+
# Trigger remove for each cell
|
235
|
+
old_size.times do |index|
|
236
|
+
trigger_removed!(old_size - index - 1)
|
237
|
+
end
|
238
|
+
|
239
|
+
# Trigger on each cell since we are clearing out the array
|
240
|
+
if deps
|
241
|
+
deps.each do |dep|
|
242
|
+
dep.changed! if dep
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
# clear the array
|
247
|
+
@array = []
|
248
|
+
end
|
249
|
+
|
239
250
|
# Check to see if the size has changed, trigger a change on size if it has
|
240
251
|
def trigger_size_change!
|
241
252
|
new_size = @array.size
|
@@ -63,11 +63,11 @@ module Volt
|
|
63
63
|
code
|
64
64
|
end
|
65
65
|
|
66
|
-
def
|
66
|
+
def app_reference
|
67
67
|
if @client
|
68
|
-
'
|
68
|
+
'Volt.current_app'
|
69
69
|
else
|
70
|
-
'
|
70
|
+
'volt_app'
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -111,7 +111,7 @@ module Volt
|
|
111
111
|
|
112
112
|
binding_code = "{#{binding_code.join(', ')}}"
|
113
113
|
|
114
|
-
code << "#{
|
114
|
+
code << "#{app_reference}.add_template(#{name.inspect}, #{template['html'].inspect}, #{binding_code})\n"
|
115
115
|
# template_calls << "template(#{name.inspect}, #{template['html'].inspect}, #{binding_code})"
|
116
116
|
end
|
117
117
|
end
|
@@ -172,7 +172,7 @@ module Volt
|
|
172
172
|
routes_path = "#{@component_path}/config/routes.rb"
|
173
173
|
|
174
174
|
if File.exist?(routes_path)
|
175
|
-
code << "#{
|
175
|
+
code << "#{app_reference}.add_routes do\n"
|
176
176
|
code << "\n" + File.read(routes_path) + "\n"
|
177
177
|
code << "end\n\n"
|
178
178
|
end
|
@@ -67,6 +67,8 @@ module Volt
|
|
67
67
|
# Running as child
|
68
68
|
@reader.close
|
69
69
|
|
70
|
+
watch_for_parent_exit
|
71
|
+
|
70
72
|
begin
|
71
73
|
volt_app = @server.boot_volt
|
72
74
|
@rack_app = volt_app.middleware
|
@@ -82,8 +84,6 @@ module Volt
|
|
82
84
|
|
83
85
|
@writer.puts(drb_object.uri)
|
84
86
|
|
85
|
-
watch_for_parent_exit
|
86
|
-
|
87
87
|
begin
|
88
88
|
DRb.thread.join
|
89
89
|
rescue Interrupt => e
|
@@ -8,8 +8,8 @@ module Volt
|
|
8
8
|
module MessageBus
|
9
9
|
class ServerTracker
|
10
10
|
UPDATE_INTERVAL = 10
|
11
|
-
def initialize(
|
12
|
-
@
|
11
|
+
def initialize(volt_app, server_id, port)
|
12
|
+
@volt_app = volt_app
|
13
13
|
@server_id = server_id
|
14
14
|
@port = port
|
15
15
|
|
@@ -33,7 +33,7 @@ module Volt
|
|
33
33
|
|
34
34
|
# Register this server as active with the database
|
35
35
|
def register
|
36
|
-
instances = @
|
36
|
+
instances = @volt_app.store._active_volt_instances
|
37
37
|
instances.where(server_id: @server_id).first.then do |item|
|
38
38
|
ips = local_ips.join(',')
|
39
39
|
time = Time.now.to_i
|
@@ -55,9 +55,11 @@ module Volt
|
|
55
55
|
# Use subscribe instead of on provided in Eventable
|
56
56
|
alias_method :subscribe, :on
|
57
57
|
|
58
|
-
attr_reader :server_id
|
58
|
+
attr_reader :server_id
|
59
59
|
|
60
60
|
def initialize(volt_app)
|
61
|
+
@volt_app = volt_app
|
62
|
+
|
61
63
|
if Volt::DataStore.fetch.connected?
|
62
64
|
# Generate a guid
|
63
65
|
@server_id = SecureRandom.uuid
|
@@ -66,8 +68,6 @@ module Volt
|
|
66
68
|
# The server id's for each peer we're connected to
|
67
69
|
@peer_server_ids = {}
|
68
70
|
|
69
|
-
@page = volt_app.page
|
70
|
-
|
71
71
|
setup_peer_server
|
72
72
|
start_tracker
|
73
73
|
|
@@ -77,7 +77,7 @@ module Volt
|
|
77
77
|
connect_to_peers
|
78
78
|
end
|
79
79
|
else
|
80
|
-
Volt.logger.error('Unable to connect to the database. Volt will still run, but the message bus requires a database connection to setup connections between nodes, so the message bus has been disabled. This means updates will not be
|
80
|
+
Volt.logger.error('Unable to connect to the database. Volt will still run, but the message bus requires a database connection to setup connections between nodes, so the message bus has been disabled. This means updates will not be propagated between instances (server, console, runners, etc...)')
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
@@ -90,7 +90,7 @@ module Volt
|
|
90
90
|
# database every minute. If the timestamp is more than 2 minutes old,
|
91
91
|
# an instance is marked as "dead" and removed.
|
92
92
|
def start_tracker
|
93
|
-
@server_tracker = ServerTracker.new(
|
93
|
+
@server_tracker = ServerTracker.new(@volt_app, @server_id, @peer_server.port)
|
94
94
|
|
95
95
|
# Do the initial registration, and wait until its done before connecting
|
96
96
|
# to peers.
|
@@ -112,7 +112,7 @@ module Volt
|
|
112
112
|
|
113
113
|
# Return an array of peer records.
|
114
114
|
def peers
|
115
|
-
instances = @
|
115
|
+
instances = @volt_app.store._active_volt_instances
|
116
116
|
|
117
117
|
instances.where(server_id: {'$ne' => @server_id}).all.sync
|
118
118
|
end
|
@@ -183,7 +183,7 @@ module Volt
|
|
183
183
|
def still_alive?(peer_server_id)
|
184
184
|
# Unable to write to the socket, retry until the instance is no
|
185
185
|
# longer marking its self as active in the database
|
186
|
-
peer_table = @
|
186
|
+
peer_table = @volt_app.store._active_volt_instances
|
187
187
|
peer = peer_table.where(server_id: peer_server_id).first.sync
|
188
188
|
if peer
|
189
189
|
# Found the peer, retry if it has reported in in the last 2
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
1
3
|
# Used to get a list of the assets and other included components
|
2
4
|
# from the dependencies.rb files.
|
3
5
|
module Volt
|
@@ -7,7 +9,8 @@ module Volt
|
|
7
9
|
@assets = []
|
8
10
|
@included_components = {}
|
9
11
|
@components = []
|
10
|
-
|
12
|
+
@disable_auto_import = []
|
13
|
+
|
11
14
|
# Include each of the default included components
|
12
15
|
Volt.config.default_components.each do |def_comp_name|
|
13
16
|
component(def_comp_name)
|
@@ -16,7 +19,11 @@ module Volt
|
|
16
19
|
component(component_name)
|
17
20
|
end
|
18
21
|
|
19
|
-
def
|
22
|
+
def disable_auto_import
|
23
|
+
@disable_auto_import.push(*@current_component).uniq
|
24
|
+
end
|
25
|
+
|
26
|
+
def load_dependencies(path, component_name)
|
20
27
|
if path
|
21
28
|
dependencies_file = File.join(path, 'config/dependencies.rb')
|
22
29
|
else
|
@@ -26,6 +33,7 @@ module Volt
|
|
26
33
|
if File.exist?(dependencies_file)
|
27
34
|
# Run the dependencies file in this asset files context
|
28
35
|
code = File.read(dependencies_file)
|
36
|
+
@current_component = component_name
|
29
37
|
instance_eval(code, dependencies_file, 0)
|
30
38
|
end
|
31
39
|
end
|
@@ -44,10 +52,10 @@ module Volt
|
|
44
52
|
|
45
53
|
component_path.each do |path|
|
46
54
|
# Load the dependencies
|
47
|
-
load_dependencies(path)
|
55
|
+
load_dependencies(path, name)
|
48
56
|
|
49
57
|
# Add any assets
|
50
|
-
add_assets(path)
|
58
|
+
add_assets(path) unless @disable_auto_import.include?(name)
|
51
59
|
@components << [path, name]
|
52
60
|
end
|
53
61
|
end
|
@@ -57,14 +65,26 @@ module Volt
|
|
57
65
|
@included_components.keys
|
58
66
|
end
|
59
67
|
|
60
|
-
def javascript_file(
|
61
|
-
@assets << [:javascript_file,
|
68
|
+
def javascript_file(locator)
|
69
|
+
@assets << [:javascript_file, prepare_locator(locator, ['js'])]
|
62
70
|
end
|
63
71
|
|
64
|
-
def css_file(
|
65
|
-
@assets << [:css_file,
|
72
|
+
def css_file(locator)
|
73
|
+
@assets << [:css_file, prepare_locator(locator, ['css','scss'])]
|
66
74
|
end
|
67
75
|
|
76
|
+
def prepare_locator(locator, valid_extensions)
|
77
|
+
unless url_or_path?(locator)
|
78
|
+
locator = File.join('/assets', @current_component, '/assets', valid_extensions.first, "#{locator}")
|
79
|
+
locator += '.css' unless locator =~ /^.*\.(#{valid_extensions.join('|')})$/
|
80
|
+
end
|
81
|
+
locator
|
82
|
+
end
|
83
|
+
|
84
|
+
def url_or_path?(url)
|
85
|
+
(url =~ URI::regexp || url =~ /^\/(\/)?.*/) ? true : false
|
86
|
+
end
|
87
|
+
|
68
88
|
def component_paths
|
69
89
|
@components
|
70
90
|
end
|
@@ -55,7 +55,7 @@ module Volt
|
|
55
55
|
end
|
56
56
|
|
57
57
|
# Makes each components classes available on the load path, require classes.
|
58
|
-
def require_in_components(
|
58
|
+
def require_in_components(volt_app)
|
59
59
|
if RUBY_PLATFORM == 'opal'
|
60
60
|
else
|
61
61
|
app_folders do |app_folder|
|
@@ -69,11 +69,11 @@ module Volt
|
|
69
69
|
end
|
70
70
|
|
71
71
|
# Delay the loading of views
|
72
|
-
|
72
|
+
volt_app.templates.template_loader = -> { load_views_and_routes(volt_app) }
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
def load_views_and_routes(
|
76
|
+
def load_views_and_routes(volt_app)
|
77
77
|
component_names = []
|
78
78
|
app_folders do |app_folder|
|
79
79
|
Dir["#{app_folder}/*"].map { |cp| cp[/[^\/]+$/] }.each do |component_name|
|
@@ -85,7 +85,7 @@ module Volt
|
|
85
85
|
# TODO: Nested components listed twice are are loaded multiple times
|
86
86
|
component_names.uniq.each do |component_name|
|
87
87
|
code = Volt::ComponentCode.new(component_name, self, false).code
|
88
|
-
# Evaluate returned code, the ```
|
88
|
+
# Evaluate returned code, the ```volt_app``` variable is set for access.
|
89
89
|
eval(code)
|
90
90
|
end
|
91
91
|
end
|
@@ -35,9 +35,12 @@ module Volt
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def process_message(message)
|
38
|
-
# self.class.message_all(message)
|
39
38
|
# Messages are json and wrapped in an array
|
40
|
-
|
39
|
+
begin
|
40
|
+
message = EJSON.parse(message).first
|
41
|
+
rescue JSON::ParserError => e
|
42
|
+
Volt.logger.error("Unable to process task request message: #{message.inspect}")
|
43
|
+
end
|
41
44
|
|
42
45
|
begin
|
43
46
|
@@dispatcher.dispatch(self, message)
|
data/lib/volt/server.rb
CHANGED
@@ -12,7 +12,6 @@ require 'volt/tasks/dispatcher'
|
|
12
12
|
require 'volt/tasks/task'
|
13
13
|
require 'volt/server/component_handler'
|
14
14
|
require 'volt/server/rack/component_paths'
|
15
|
-
require 'volt/page/page'
|
16
15
|
|
17
16
|
require 'volt/server/websocket/websocket_handler'
|
18
17
|
require 'volt/utils/read_write_lock'
|
data/lib/volt/spec/setup.rb
CHANGED
@@ -35,7 +35,7 @@ module Volt
|
|
35
35
|
volt_app.database.drop_database
|
36
36
|
|
37
37
|
# Clear cached for a reset
|
38
|
-
volt_app.
|
38
|
+
volt_app.instance_variable_set('@store', nil)
|
39
39
|
volt_app.reset_query_pool!
|
40
40
|
end
|
41
41
|
|
@@ -56,15 +56,14 @@ module Volt
|
|
56
56
|
let(:the_page) { Model.new }
|
57
57
|
let(:store) do
|
58
58
|
@__store_accessed = true
|
59
|
-
|
60
|
-
$page.store
|
59
|
+
volt_app.store
|
61
60
|
end
|
62
61
|
let(:volt_app) { volt_app }
|
63
|
-
let(:params) { volt_app.
|
62
|
+
let(:params) { volt_app.params }
|
64
63
|
|
65
64
|
after do
|
66
65
|
# Clear params if used
|
67
|
-
url = volt_app.
|
66
|
+
url = volt_app.url
|
68
67
|
if url.instance_variable_get('@params')
|
69
68
|
url.instance_variable_set('@params', nil)
|
70
69
|
end
|
data/lib/volt/tasks/task.rb
CHANGED
@@ -10,10 +10,10 @@ module Volt
|
|
10
10
|
# things like who's logged in.
|
11
11
|
meta_data = {}
|
12
12
|
|
13
|
-
user_id =
|
13
|
+
user_id = Volt.current_app.cookies._user_id
|
14
14
|
meta_data['user_id'] = user_id unless user_id.nil?
|
15
15
|
|
16
|
-
|
16
|
+
Volt.current_app.tasks.call(self.name, name, meta_data, *args, &block)
|
17
17
|
end
|
18
18
|
else
|
19
19
|
include CollectionHelpers
|
@@ -22,7 +22,6 @@ module Volt
|
|
22
22
|
|
23
23
|
def initialize(volt_app, channel = nil, dispatcher = nil)
|
24
24
|
@volt_app = volt_app
|
25
|
-
@page = volt_app.page
|
26
25
|
@channel = channel
|
27
26
|
@dispatcher = dispatcher
|
28
27
|
end
|