volt 0.8.14 → 0.8.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/Readme.md +8 -2
  4. data/VERSION +1 -1
  5. data/app/volt/controllers/notices_controller.rb +1 -1
  6. data/app/volt/models/user.rb +2 -2
  7. data/app/volt/tasks/live_query/live_query_pool.rb +1 -1
  8. data/app/volt/tasks/query_tasks.rb +1 -1
  9. data/app/volt/tasks/store_tasks.rb +1 -1
  10. data/app/volt/tasks/user_tasks.rb +2 -2
  11. data/lib/volt/boot.rb +2 -2
  12. data/lib/volt/cli/asset_compile.rb +31 -27
  13. data/lib/volt/cli.rb +64 -65
  14. data/lib/volt/config.rb +25 -23
  15. data/lib/volt/console.rb +17 -16
  16. data/lib/volt/controllers/model_controller.rb +82 -80
  17. data/lib/volt/data_stores/data_store.rb +2 -2
  18. data/lib/volt/data_stores/mongo_driver.rb +2 -2
  19. data/lib/volt/extra_core/inflections.rb +2 -2
  20. data/lib/volt/extra_core/inflector/inflections.rb +185 -183
  21. data/lib/volt/extra_core/inflector/methods.rb +50 -48
  22. data/lib/volt/extra_core/string.rb +2 -2
  23. data/lib/volt/models/array_model.rb +93 -92
  24. data/lib/volt/models/cursor.rb +3 -2
  25. data/lib/volt/models/model.rb +248 -251
  26. data/lib/volt/models/model_hash_behaviour.rb +44 -44
  27. data/lib/volt/models/model_helpers.rb +38 -36
  28. data/lib/volt/models/model_state.rb +16 -17
  29. data/lib/volt/models/model_wrapper.rb +25 -24
  30. data/lib/volt/models/persistors/array_store.rb +145 -143
  31. data/lib/volt/models/persistors/base.rb +18 -16
  32. data/lib/volt/models/persistors/flash.rb +24 -22
  33. data/lib/volt/models/persistors/local_store.rb +46 -44
  34. data/lib/volt/models/persistors/model_identity_map.rb +10 -8
  35. data/lib/volt/models/persistors/model_store.rb +76 -76
  36. data/lib/volt/models/persistors/params.rb +19 -17
  37. data/lib/volt/models/persistors/query/query_listener.rb +65 -63
  38. data/lib/volt/models/persistors/query/query_listener_pool.rb +12 -10
  39. data/lib/volt/models/persistors/store.rb +28 -28
  40. data/lib/volt/models/persistors/store_factory.rb +12 -10
  41. data/lib/volt/models/persistors/store_state.rb +33 -31
  42. data/lib/volt/models/url.rb +96 -104
  43. data/lib/volt/models/validations.rb +56 -54
  44. data/lib/volt/models/validators/length_validator.rb +24 -22
  45. data/lib/volt/models/validators/presence_validator.rb +14 -12
  46. data/lib/volt/page/bindings/attribute_binding.rb +106 -106
  47. data/lib/volt/page/bindings/base_binding.rb +23 -21
  48. data/lib/volt/page/bindings/component_binding.rb +3 -1
  49. data/lib/volt/page/bindings/content_binding.rb +34 -34
  50. data/lib/volt/page/bindings/each_binding.rb +113 -113
  51. data/lib/volt/page/bindings/event_binding.rb +38 -34
  52. data/lib/volt/page/bindings/if_binding.rb +56 -54
  53. data/lib/volt/page/bindings/template_binding/grouped_controllers.rb +24 -22
  54. data/lib/volt/page/bindings/template_binding.rb +182 -185
  55. data/lib/volt/page/channel.rb +79 -77
  56. data/lib/volt/page/channel_stub.rb +29 -27
  57. data/lib/volt/page/document.rb +6 -5
  58. data/lib/volt/page/document_events.rb +54 -52
  59. data/lib/volt/page/page.rb +139 -138
  60. data/lib/volt/page/string_template_renderer.rb +36 -36
  61. data/lib/volt/page/sub_context.rb +26 -25
  62. data/lib/volt/page/targets/attribute_section.rb +27 -25
  63. data/lib/volt/page/targets/attribute_target.rb +7 -6
  64. data/lib/volt/page/targets/base_section.rb +27 -26
  65. data/lib/volt/page/targets/binding_document/base_node.rb +3 -1
  66. data/lib/volt/page/targets/binding_document/component_node.rb +85 -82
  67. data/lib/volt/page/targets/binding_document/html_node.rb +11 -9
  68. data/lib/volt/page/targets/dom_section.rb +78 -77
  69. data/lib/volt/page/targets/dom_target.rb +8 -6
  70. data/lib/volt/page/targets/dom_template.rb +90 -88
  71. data/lib/volt/page/targets/helpers/comment_searchers.rb +51 -49
  72. data/lib/volt/page/tasks.rb +59 -57
  73. data/lib/volt/page/template_renderer.rb +17 -14
  74. data/lib/volt/page/url_tracker.rb +26 -24
  75. data/lib/volt/reactive/computation.rb +87 -88
  76. data/lib/volt/reactive/dependency.rb +30 -28
  77. data/lib/volt/reactive/eventable.rb +64 -62
  78. data/lib/volt/reactive/hash_dependency.rb +25 -23
  79. data/lib/volt/reactive/reactive_accessors.rb +34 -32
  80. data/lib/volt/reactive/reactive_array.rb +162 -162
  81. data/lib/volt/reactive/reactive_hash.rb +37 -35
  82. data/lib/volt/router/routes.rb +99 -101
  83. data/lib/volt/server/component_handler.rb +20 -21
  84. data/lib/volt/server/component_templates.rb +72 -70
  85. data/lib/volt/server/html_parser/attribute_scope.rb +109 -99
  86. data/lib/volt/server/html_parser/each_scope.rb +17 -16
  87. data/lib/volt/server/html_parser/if_view_scope.rb +51 -49
  88. data/lib/volt/server/html_parser/sandlebars_parser.rb +184 -177
  89. data/lib/volt/server/html_parser/textarea_scope.rb +24 -22
  90. data/lib/volt/server/html_parser/view_handler.rb +66 -65
  91. data/lib/volt/server/html_parser/view_parser.rb +23 -21
  92. data/lib/volt/server/html_parser/view_scope.rb +142 -141
  93. data/lib/volt/server/rack/asset_files.rb +81 -79
  94. data/lib/volt/server/rack/component_code.rb +17 -15
  95. data/lib/volt/server/rack/component_html_renderer.rb +14 -12
  96. data/lib/volt/server/rack/component_paths.rb +72 -71
  97. data/lib/volt/server/rack/index_files.rb +36 -39
  98. data/lib/volt/server/rack/opal_files.rb +43 -41
  99. data/lib/volt/server/rack/source_map_server.rb +23 -21
  100. data/lib/volt/server/socket_connection_handler.rb +46 -45
  101. data/lib/volt/server/socket_connection_handler_stub.rb +21 -19
  102. data/lib/volt/server.rb +60 -58
  103. data/lib/volt/spec/setup.rb +3 -3
  104. data/lib/volt/tasks/dispatcher.rb +24 -23
  105. data/lib/volt/tasks/task_handler.rb +35 -33
  106. data/lib/volt/utils/ejson.rb +8 -6
  107. data/lib/volt/utils/generic_counting_pool.rb +33 -31
  108. data/lib/volt/utils/generic_pool.rb +73 -70
  109. data/lib/volt/utils/local_storage.rb +42 -38
  110. data/lib/volt/volt/environment.rb +1 -1
  111. data/lib/volt.rb +44 -42
  112. data/spec/apps/kitchen_sink/app/main/assets/css/todos.css +28 -0
  113. data/spec/apps/kitchen_sink/app/main/config/routes.rb +1 -0
  114. data/spec/apps/kitchen_sink/app/main/controllers/main_controller.rb +2 -2
  115. data/spec/apps/kitchen_sink/app/main/controllers/todos_controller.rb +17 -0
  116. data/spec/apps/kitchen_sink/app/main/views/main/main.html +1 -0
  117. data/spec/apps/kitchen_sink/app/main/views/todos/index.html +24 -0
  118. data/spec/apps/kitchen_sink/config.ru +1 -1
  119. data/spec/controllers/reactive_accessors_spec.rb +5 -5
  120. data/spec/extra_core/inflector_spec.rb +2 -2
  121. data/spec/integration/list_spec.rb +68 -0
  122. data/spec/models/model_spec.rb +57 -57
  123. data/spec/models/persistors/params_spec.rb +6 -6
  124. data/spec/models/persistors/store_spec.rb +7 -7
  125. data/spec/models/validations_spec.rb +3 -3
  126. data/spec/page/bindings/content_binding_spec.rb +7 -7
  127. data/spec/page/bindings/template_binding_spec.rb +4 -5
  128. data/spec/page/sub_context_spec.rb +2 -2
  129. data/spec/reactive/computation_spec.rb +10 -10
  130. data/spec/reactive/dependency_spec.rb +2 -2
  131. data/spec/reactive/eventable_spec.rb +4 -4
  132. data/spec/reactive/reactive_array_spec.rb +13 -13
  133. data/spec/router/routes_spec.rb +5 -5
  134. data/spec/server/html_parser/sandlebars_parser_spec.rb +9 -9
  135. data/spec/server/html_parser/view_parser_spec.rb +27 -27
  136. data/spec/server/rack/asset_files_spec.rb +5 -5
  137. data/spec/server/rack/component_paths_spec.rb +2 -2
  138. data/spec/tasks/live_query_spec.rb +2 -2
  139. data/spec/tasks/query_tasks.rb +1 -1
  140. data/spec/tasks/query_tracker_spec.rb +1 -1
  141. data/spec/templates/targets/binding_document/component_node_spec.rb +2 -2
  142. data/spec/utils/generic_counting_pool_spec.rb +2 -2
  143. data/spec/utils/generic_pool_spec.rb +2 -2
  144. data/templates/component/controllers/main_controller.rb +1 -1
  145. data/templates/model/model.rb.tt +2 -2
  146. data/templates/newgem/app/newgem/controllers/main_controller.rb.tt +2 -2
  147. data/templates/project/app/main/controllers/main_controller.rb +1 -1
  148. data/templates/project/config.ru +1 -1
  149. metadata +10 -3
  150. data/app/volt/assets/js/vertxbus.js +0 -216
@@ -1,98 +1,99 @@
1
1
  # ComponentPaths gives an array of every folder where you find a component.
2
- class ComponentPaths
3
- def initialize(root=nil)
4
- @root = root || Dir.pwd
5
- end
6
-
7
- # Yield for every folder where we might find components
8
- def app_folders
9
- # Find all app folders
10
- @app_folders ||= begin
11
- volt_app = File.expand_path(File.join(File.dirname(__FILE__), "../../../../app"))
12
- app_folders = [volt_app, "#{@root}/app", "#{@root}/vendor/app"].map {|f| File.expand_path(f) }
13
-
14
- # Gem folders with volt in them
15
- # TODO: we should probably qualify this a bit more
16
- app_folders += Gem.loaded_specs.values.map { |g| g.full_gem_path }.reject {|g| g !~ /volt/ }.map {|f| f + '/app' }
17
-
18
- app_folders
2
+ module Volt
3
+ class ComponentPaths
4
+ def initialize(root=nil)
5
+ @root = root || Dir.pwd
19
6
  end
20
7
 
21
- # Yield each app folder and return a flattened array with
22
- # the results
8
+ # Yield for every folder where we might find components
9
+ def app_folders
10
+ # Find all app folders
11
+ @app_folders ||= begin
12
+ volt_app = File.expand_path(File.join(File.dirname(__FILE__), "../../../../app"))
13
+ app_folders = [volt_app, "#{@root}/app", "#{@root}/vendor/app"].map { |f| File.expand_path(f) }
23
14
 
24
- files = []
25
- @app_folders.each do |app_folder|
26
- files << yield(app_folder)
27
- end
28
-
29
- return files.flatten
30
- end
15
+ # Gem folders with volt in them
16
+ # TODO: we should probably qualify this a bit more
17
+ app_folders += Gem.loaded_specs.values.map { |g| g.full_gem_path }.reject { |g| g !~ /volt/ }.map { |f| f + '/app' }
31
18
 
32
- # returns an array of every folder that is a component
33
- def components
34
- return @components if @components
19
+ app_folders
20
+ end
35
21
 
36
- @components = {}
37
- app_folders do |app_folder|
38
- Dir["#{app_folder}/*"].sort.each do |folder|
39
- if File.directory?(folder)
40
- folder_name = folder[/[^\/]+$/]
22
+ # Yield each app folder and return a flattened array with
23
+ # the results
41
24
 
42
- @components[folder_name] ||= []
43
- @components[folder_name] << folder
44
- end
25
+ files = []
26
+ @app_folders.each do |app_folder|
27
+ files << yield(app_folder)
45
28
  end
29
+
30
+ return files.flatten
46
31
  end
47
32
 
48
- return @components
49
- end
33
+ # returns an array of every folder that is a component
34
+ def components
35
+ return @components if @components
50
36
 
51
- # Makes each components classes available on the load path, require classes.
52
- def require_in_components
53
- if RUBY_PLATFORM == 'opal'
54
- else
37
+ @components = {}
55
38
  app_folders do |app_folder|
56
- $LOAD_PATH.unshift(app_folder)
39
+ Dir["#{app_folder}/*"].sort.each do |folder|
40
+ if File.directory?(folder)
41
+ folder_name = folder[/[^\/]+$/]
57
42
 
58
- # Sort so we get consistent load order across platforms
59
- Dir["#{app_folder}/*/{controllers,models,tasks}/*.rb"].each do |ruby_file|
60
- path = ruby_file.gsub(/^#{app_folder}\//, '')[0..-4]
61
- require(path)
43
+ @components[folder_name] ||= []
44
+ @components[folder_name] << folder
45
+ end
62
46
  end
47
+ end
63
48
 
64
- if Volt.server?
65
- # Add models to page
66
- Dir["#{app_folder}/*/models/*.rb"].each do |ruby_file|
67
- class_name = File.basename(ruby_file).gsub(/[.]rb$/, '')
68
- $page.add_model(class_name)
49
+ return @components
50
+ end
51
+
52
+ # Makes each components classes available on the load path, require classes.
53
+ def require_in_components
54
+ if RUBY_PLATFORM == 'opal'
55
+ else
56
+ app_folders do |app_folder|
57
+ $LOAD_PATH.unshift(app_folder)
58
+
59
+ # Sort so we get consistent load order across platforms
60
+ Dir["#{app_folder}/*/{controllers,models,tasks}/*.rb"].each do |ruby_file|
61
+ path = ruby_file.gsub(/^#{app_folder}\//, '')[0..-4]
62
+ require(path)
63
+ end
64
+
65
+ if Volt.server?
66
+ # Add models to page
67
+ Dir["#{app_folder}/*/models/*.rb"].each do |ruby_file|
68
+ class_name = File.basename(ruby_file).gsub(/[.]rb$/, '')
69
+ $page.add_model(class_name)
70
+ end
69
71
  end
70
72
  end
71
73
  end
72
74
  end
73
- end
74
75
 
75
- # Returns the path for a specific component
76
- def component_path(name)
77
- folders = components[name]
76
+ # Returns the path for a specific component
77
+ def component_path(name)
78
+ folders = components[name]
78
79
 
79
- if folders
80
- return folders.first
81
- else
82
- return nil
80
+ if folders
81
+ return folders.first
82
+ else
83
+ return nil
84
+ end
83
85
  end
84
- end
85
86
 
86
- # Return every asset folder we need to serve from
87
- def asset_folders
88
- folders = []
89
- app_folders do |app_folder|
90
- Dir["#{app_folder}/*/assets"].sort.each do |asset_folder|
91
- folders << yield(asset_folder)
87
+ # Return every asset folder we need to serve from
88
+ def asset_folders
89
+ folders = []
90
+ app_folders do |app_folder|
91
+ Dir["#{app_folder}/*/assets"].sort.each do |asset_folder|
92
+ folders << yield(asset_folder)
93
+ end
92
94
  end
93
- end
94
95
 
95
- folders.flatten
96
+ folders.flatten
97
+ end
96
98
  end
97
-
98
99
  end
@@ -2,54 +2,51 @@ require 'volt/server/rack/asset_files'
2
2
  require 'volt/router/routes'
3
3
 
4
4
  # Serves the main pages
5
- class IndexFiles
6
- def initialize(app, component_paths, opal_files)
7
- @app = app
8
- @component_paths = component_paths
9
- @opal_files = opal_files
10
-
11
- @@router ||= Routes.new.define do
12
- # Find the route file
13
- home_path = component_paths.component_path('main')
14
- route_file = File.read("#{home_path}/config/routes.rb")
15
- eval(route_file)
5
+ module Volt
6
+ class IndexFiles
7
+ def initialize(app, component_paths, opal_files)
8
+ @app = app
9
+ @component_paths = component_paths
10
+ @opal_files = opal_files
11
+
12
+ @@router ||= Routes.new.define do
13
+ # Find the route file
14
+ home_path = component_paths.component_path('main')
15
+ route_file = File.read("#{home_path}/config/routes.rb")
16
+ eval(route_file)
17
+ end
16
18
  end
17
- end
18
19
 
19
- def route_match?(path)
20
- params = @@router.url_to_params(path)
20
+ def route_match?(path)
21
+ params = @@router.url_to_params(path)
21
22
 
22
- return params if params
23
+ return params if params
23
24
 
24
- return false
25
- end
25
+ return false
26
+ end
26
27
 
27
- def call(env)
28
- if route_match?(env['PATH_INFO'])
29
- [200, { 'Content-Type' => 'text/html; charset=utf-8' }, [html]]
30
- else
31
- @app.call env
28
+ def call(env)
29
+ if route_match?(env['PATH_INFO'])
30
+ [200, {'Content-Type' => 'text/html; charset=utf-8'}, [html]]
31
+ else
32
+ @app.call env
33
+ end
32
34
  end
33
- end
34
35
 
35
- def html
36
- index_path = File.expand_path(File.join(Volt.root, "public/index.html"))
37
- html = File.read(index_path)
36
+ def html
37
+ index_path = File.expand_path(File.join(Volt.root, "public/index.html"))
38
+ html = File.read(index_path)
38
39
 
39
- ERB.new(html).result(binding)
40
- end
40
+ ERB.new(html).result(binding)
41
+ end
41
42
 
42
- def javascript_files
43
- # TODO: Cache somehow, this is being loaded every time
44
- AssetFiles.new('main', @component_paths).javascript_files(@opal_files)
45
- end
43
+ def javascript_files
44
+ # TODO: Cache somehow, this is being loaded every time
45
+ AssetFiles.new('main', @component_paths).javascript_files(@opal_files)
46
+ end
46
47
 
47
- def css_files
48
- AssetFiles.new('main', @component_paths).css_files
48
+ def css_files
49
+ AssetFiles.new('main', @component_paths).css_files
50
+ end
49
51
  end
50
-
51
-
52
-
53
52
  end
54
-
55
-
@@ -5,64 +5,66 @@ if Volt.env.production?
5
5
  end
6
6
 
7
7
  # Sets up the maps for the opal assets, and source maps if enabled.
8
- class OpalFiles
9
- attr_reader :environment
8
+ module Volt
9
+ class OpalFiles
10
+ attr_reader :environment
10
11
 
11
- def initialize(builder, app_path, component_paths)
12
- Opal::Processor.source_map_enabled = Volt.source_maps?
12
+ def initialize(builder, app_path, component_paths)
13
+ Opal::Processor.source_map_enabled = Volt.source_maps?
13
14
 
14
- # Don't run arity checks in production
15
- # Opal::Processor.arity_check_enabled = !Volt.env.production?
16
- # Opal::Processor.dynamic_require_severity = :raise
15
+ # Don't run arity checks in production
16
+ # Opal::Processor.arity_check_enabled = !Volt.env.production?
17
+ # Opal::Processor.dynamic_require_severity = :raise
17
18
 
18
- @component_paths = component_paths
19
- @environment = Opal::Environment.new
19
+ @component_paths = component_paths
20
+ @environment = Opal::Environment.new
20
21
 
21
- # Since the scope changes in builder blocks, we need to capture
22
- # environment in closure
23
- environment = @environment
22
+ # Since the scope changes in builder blocks, we need to capture
23
+ # environment in closure
24
+ environment = @environment
24
25
 
25
- environment.cache = Sprockets::Cache::FileStore.new("./tmp")
26
+ environment.cache = Sprockets::Cache::FileStore.new("./tmp")
26
27
 
27
- if Volt.env.production?
28
- # Compress in production
29
- environment.js_compressor = Sprockets::UglifierCompressor
30
- environment.css_compressor = Sprockets::YUICompressor
31
- end
28
+ if Volt.env.production?
29
+ # Compress in production
30
+ environment.js_compressor = Sprockets::UglifierCompressor
31
+ environment.css_compressor = Sprockets::YUICompressor
32
+ end
32
33
 
33
- environment.append_path(app_path)
34
+ environment.append_path(app_path)
34
35
 
35
- volt_gem_lib_path = File.expand_path(File.join(File.dirname(__FILE__), "../../.."))
36
- environment.append_path(volt_gem_lib_path)
36
+ volt_gem_lib_path = File.expand_path(File.join(File.dirname(__FILE__), "../../.."))
37
+ environment.append_path(volt_gem_lib_path)
37
38
 
38
- add_asset_folders(environment)
39
+ add_asset_folders(environment)
39
40
 
40
- # Add the opal load paths
41
- Opal.paths.each do |path|
42
- environment.append_path(path)
43
- end
41
+ # Add the opal load paths
42
+ Opal.paths.each do |path|
43
+ environment.append_path(path)
44
+ end
44
45
 
45
- # opal-jquery gem
46
- spec = Gem::Specification.find_by_name("opal-jquery")
47
- environment.append_path(spec.gem_dir + "/opal")
46
+ # opal-jquery gem
47
+ spec = Gem::Specification.find_by_name("opal-jquery")
48
+ environment.append_path(spec.gem_dir + "/opal")
48
49
 
49
- builder.map '/assets' do
50
- run environment
51
- end
50
+ builder.map '/assets' do
51
+ run environment
52
+ end
52
53
 
53
- if Volt.source_maps?
54
- source_maps = SourceMapServer.new(environment)
54
+ if Volt.source_maps?
55
+ source_maps = SourceMapServer.new(environment)
55
56
 
56
- builder.map(source_maps.prefix) do
57
- run source_maps
57
+ builder.map(source_maps.prefix) do
58
+ run source_maps
59
+ end
58
60
  end
59
61
  end
60
- end
61
62
 
62
- def add_asset_folders(environment)
63
- @component_paths.asset_folders do |asset_folder|
64
- environment.append_path(asset_folder)
63
+ def add_asset_folders(environment)
64
+ @component_paths.asset_folders do |asset_folder|
65
+ environment.append_path(asset_folder)
66
+ end
65
67
  end
66
- end
67
68
 
69
+ end
68
70
  end
@@ -1,31 +1,33 @@
1
- class SourceMapServer
2
- def initialize sprockets
3
- @sprockets = sprockets
4
- end
1
+ module Volt
2
+ class SourceMapServer
3
+ def initialize sprockets
4
+ @sprockets = sprockets
5
+ end
5
6
 
6
- attr_reader :sprockets
7
+ attr_reader :sprockets
7
8
 
8
- attr_writer :prefix
9
+ attr_writer :prefix
9
10
 
10
- def prefix
11
- @prefix ||= '/__opal_source_maps__'
12
- end
11
+ def prefix
12
+ @prefix ||= '/__opal_source_maps__'
13
+ end
13
14
 
14
- def inspect
15
- "#<#{self.class}:#{object_id}>"
16
- end
15
+ def inspect
16
+ "#<#{self.class}:#{object_id}>"
17
+ end
17
18
 
18
- def call(env)
19
- path_info = env['PATH_INFO']
19
+ def call(env)
20
+ path_info = env['PATH_INFO']
20
21
 
21
- if path_info =~ /\.js\.map$/
22
- path = env['PATH_INFO'].gsub(/^\/|\.js\.map$/, '')
23
- asset = sprockets[path]
24
- return [404, {}, []] if asset.nil?
22
+ if path_info =~ /\.js\.map$/
23
+ path = env['PATH_INFO'].gsub(/^\/|\.js\.map$/, '')
24
+ asset = sprockets[path]
25
+ return [404, {}, []] if asset.nil?
25
26
 
26
- return [200, {"Content-Type" => "text/json"}, [$OPAL_SOURCE_MAPS[asset.pathname].to_s]]
27
- else
28
- return [200, {"Content-Type" => "text/text"}, [File.read(sprockets.resolve(path_info))]]
27
+ return [200, {"Content-Type" => "text/json"}, [$OPAL_SOURCE_MAPS[asset.pathname].to_s]]
28
+ else
29
+ return [200, {"Content-Type" => "text/text"}, [File.read(sprockets.resolve(path_info))]]
30
+ end
29
31
  end
30
32
  end
31
33
  end
@@ -2,67 +2,68 @@ require 'json'
2
2
  require 'sockjs/session'
3
3
  require File.join(File.dirname(__FILE__), "../../../app/volt/tasks/query_tasks")
4
4
 
5
- class SocketConnectionHandler < SockJS::Session
6
- # Create one instance of the dispatcher
5
+ module Volt
6
+ class SocketConnectionHandler < SockJS::Session
7
+ # Create one instance of the dispatcher
7
8
 
8
- def self.dispatcher=(val)
9
- @@dispatcher = val
10
- end
9
+ def self.dispatcher=(val)
10
+ @@dispatcher = val
11
+ end
11
12
 
12
- def self.dispatcher
13
- @@dispatcher
14
- end
13
+ def self.dispatcher
14
+ @@dispatcher
15
+ end
15
16
 
16
- # Sends a message to all, optionally skipping a users channel
17
- def self.send_message_all(skip_channel=nil, *args)
18
- @@channels.each do |channel|
19
- if skip_channel && channel == skip_channel
20
- next
17
+ # Sends a message to all, optionally skipping a users channel
18
+ def self.send_message_all(skip_channel=nil, *args)
19
+ @@channels.each do |channel|
20
+ if skip_channel && channel == skip_channel
21
+ next
22
+ end
23
+ channel.send_message(*args)
21
24
  end
22
- channel.send_message(*args)
23
- end
24
25
 
25
- end
26
+ end
26
27
 
27
- def initialize(session, *args)
28
- @session = session
28
+ def initialize(session, *args)
29
+ @session = session
29
30
 
30
- @@channels ||= []
31
- @@channels << self
31
+ @@channels ||= []
32
+ @@channels << self
32
33
 
33
- super
34
- end
34
+ super
35
+ end
35
36
 
36
- def process_message(message)
37
- # self.class.message_all(message)
38
- # Messages are json and wrapped in an array
39
- message = JSON.parse(message).first
37
+ def process_message(message)
38
+ # self.class.message_all(message)
39
+ # Messages are json and wrapped in an array
40
+ message = JSON.parse(message).first
40
41
 
41
- @@dispatcher.dispatch(self, message)
42
- end
42
+ @@dispatcher.dispatch(self, message)
43
+ end
43
44
 
44
- def send_message(*args)
45
- str = JSON.dump([*args])
45
+ def send_message(*args)
46
+ str = JSON.dump([*args])
46
47
 
47
- begin
48
- send(str)
49
- rescue MetaState::WrongStateError => e
50
- puts "Tried to send to closed connection: #{e.inspect}"
48
+ begin
49
+ send(str)
50
+ rescue MetaState::WrongStateError => e
51
+ puts "Tried to send to closed connection: #{e.inspect}"
51
52
 
52
- # Mark this channel as closed
53
- closed
53
+ # Mark this channel as closed
54
+ closed
55
+ end
54
56
  end
55
- end
56
57
 
57
- def closed
58
- # Remove ourself from the available channels
59
- @@channels.delete(self)
58
+ def closed
59
+ # Remove ourself from the available channels
60
+ @@channels.delete(self)
60
61
 
61
- QueryTasks.new(self).close!
62
- end
62
+ QueryTasks.new(self).close!
63
+ end
63
64
 
64
- def inspect
65
- "<#{self.class.to_s}:#{object_id}>"
65
+ def inspect
66
+ "<#{self.class.to_s}:#{object_id}>"
67
+ end
66
68
  end
67
-
68
69
  end
@@ -1,26 +1,28 @@
1
- class SocketConnectionHandlerStub
2
- def self.dispatcher=(val)
3
- @@dispatcher = val
4
- end
1
+ module Volt
2
+ class SocketConnectionHandlerStub
3
+ def self.dispatcher=(val)
4
+ @@dispatcher = val
5
+ end
5
6
 
6
- def self.dispatcher
7
- @@dispatcher
8
- end
7
+ def self.dispatcher
8
+ @@dispatcher
9
+ end
9
10
 
10
- def initialize(channel_stub)
11
- @channel_stub = channel_stub
12
- end
11
+ def initialize(channel_stub)
12
+ @channel_stub = channel_stub
13
+ end
13
14
 
14
- # Sends a message to all, optionally skipping a users channel
15
- def self.send_message_all(skip_channel=nil, *args)
16
- # Stub
17
- end
15
+ # Sends a message to all, optionally skipping a users channel
16
+ def self.send_message_all(skip_channel=nil, *args)
17
+ # Stub
18
+ end
18
19
 
19
- def process_message(message)
20
- @@dispatcher.dispatch(self, message)
21
- end
20
+ def process_message(message)
21
+ @@dispatcher.dispatch(self, message)
22
+ end
22
23
 
23
- def send_message(*args)
24
- @channel_stub.message_received(*args)
24
+ def send_message(*args)
25
+ @channel_stub.message_received(*args)
26
+ end
25
27
  end
26
28
  end