volt 0.9.6.pre2 → 0.9.6.pre3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +0 -1
- data/app/volt/tasks/live_query/live_query.rb +0 -1
- data/lib/volt/models/persistors/model_store.rb +0 -4
- data/lib/volt/page/channel.rb +1 -1
- data/lib/volt/utils/data_transformer.rb +49 -0
- data/lib/volt/version.rb +1 -1
- data/spec/apps/kitchen_sink/Gemfile +0 -1
- data/spec/apps/kitchen_sink/app/main/models/post.rb +2 -1
- data/spec/apps/kitchen_sink/app/main/models/user.rb +14 -14
- data/spec/integration/callbacks_spec.rb +20 -20
- data/spec/utils/data_transformer_spec.rb +49 -0
- data/templates/newgem/Gemfile.tt +0 -3
- data/templates/project/Gemfile.tt +0 -1
- metadata +5 -5
- data/lib/volt/store/mongo.rb +0 -5
- data/spec/store/mongo_spec.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af40ada934fde21bab3077199e52634e939d0316
|
4
|
+
data.tar.gz: 6029344175c2e1fb6004226f3b7a83cc04420d90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a83fff0163894a9d6bb91d2d50a4e746632c6650420522cd5c08442442de3ab71ca710e2b146bbd328990a9f9303e3e54e3bb43599458c4745532df8219e3773
|
7
|
+
data.tar.gz: 9587b05a0126bc352bc1d003d53380b3cd1ae0fb3f0ac9c2a02e2ba83c39c2aa2bd35e11a745c8e9a2cafc76ae8f4dc0673a8187d3ff5da611a91026ed47f866
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -164,14 +164,10 @@ module Volt
|
|
164
164
|
|
165
165
|
# Do the actual writing of data to the database, only runs on the backend.
|
166
166
|
def save_to_db!(values)
|
167
|
-
# puts "SAVE TO DB: #{values.inspect}"
|
168
167
|
# Check to make sure the model has no validation errors.
|
169
168
|
errors = @model.errors
|
170
169
|
return errors if errors.present?
|
171
170
|
|
172
|
-
# Passed, save it
|
173
|
-
id = values[:id]
|
174
|
-
|
175
171
|
# Try to create
|
176
172
|
update_result = db.update(collection, values)
|
177
173
|
|
data/lib/volt/page/channel.rb
CHANGED
@@ -38,7 +38,7 @@ module Volt
|
|
38
38
|
socket_url = "://#{socket_url}"
|
39
39
|
end
|
40
40
|
|
41
|
-
ws_proto = (`document.location.protocol` == 'https
|
41
|
+
ws_proto = (`document.location.protocol` == 'https:') ? 'wss' : 'ws'
|
42
42
|
|
43
43
|
# Add wss? to the front
|
44
44
|
socket_url = "#{ws_proto}#{socket_url}"
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# DataTransformer is a singleton class that walks ruby data structures (nested
|
2
|
+
# hashes, arrays, etc..) and lets you transform them based on values or keys
|
3
|
+
#
|
4
|
+
# NOTE: DataTransformer is not automatically required, but can be when needed.
|
5
|
+
|
6
|
+
module Volt
|
7
|
+
class DataTransformer
|
8
|
+
# Takes a hash or array, and nested map's over the values, yielding to
|
9
|
+
# the block the value. The return value from the block replaces the
|
10
|
+
# previous value.
|
11
|
+
# NOTE: This does not yield hashes or arrays.
|
12
|
+
def self.transform(data, &block)
|
13
|
+
if data.is_a?(Hash)
|
14
|
+
data.map do |key, value|
|
15
|
+
key = transform(key, &block)
|
16
|
+
value = transform(value, &block)
|
17
|
+
[key, value]
|
18
|
+
end.to_h
|
19
|
+
elsif data.is_a?(Array)
|
20
|
+
data.map do |value|
|
21
|
+
transform(value, &block)
|
22
|
+
end
|
23
|
+
else
|
24
|
+
# yield to the trasnformer
|
25
|
+
yield(data)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Like #transform, except it only yields keys.
|
30
|
+
def self.transform_keys(data, &block)
|
31
|
+
if data.is_a?(Hash)
|
32
|
+
data.map do |key, value|
|
33
|
+
key = transform_keys(key, &block)
|
34
|
+
value = transform_keys(value, &block)
|
35
|
+
|
36
|
+
# map the key
|
37
|
+
[yield(key), value]
|
38
|
+
end.to_h
|
39
|
+
elsif data.is_a?(Array)
|
40
|
+
data.map do |value|
|
41
|
+
transform_keys(value, &block)
|
42
|
+
end
|
43
|
+
else
|
44
|
+
# no mapping
|
45
|
+
data
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/volt/version.rb
CHANGED
@@ -8,20 +8,20 @@ class User < Volt::User
|
|
8
8
|
validate :email, email: true
|
9
9
|
|
10
10
|
unless RUBY_PLATFORM == "opal"
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
Volt.current_app.on("user_connect") do |user_id|
|
12
|
+
begin
|
13
|
+
Volt.current_app.store.users.where(id: user_id).first.sync._event_triggered = "user_connect"
|
14
|
+
rescue
|
15
|
+
#we rescue as this callback will also get called from the SocketConnectionHandler specs (and will fail)
|
16
|
+
end
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
Volt.current_app.on("user_disconnect") do |user_id|
|
20
|
+
begin
|
21
|
+
user = Volt.current_app.store.users.where(id: user_id).first.sync._event_triggered = "user_disconnect"
|
22
|
+
rescue => e
|
23
|
+
#we rescue as this callback will also get called from the SocketConnectionHandler specs (and will fail)
|
24
|
+
end
|
25
|
+
end
|
26
26
|
end
|
27
27
|
end
|
@@ -2,30 +2,30 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'lifecycle callbacks', type: :feature, sauce: true do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
context 'with a user' do
|
6
|
+
before do
|
7
|
+
# Add the user
|
8
|
+
store._users! << { email: 'test@test.com', password: 'awes0mesEcRet', name: 'Test Account 9550' }
|
9
|
+
end
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
it 'should trigger a user_connect event when a user logs in and a user_disconnect event when a user logs out' do
|
12
|
+
visit '/'
|
13
13
|
|
14
|
-
|
14
|
+
click_link 'Login'
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
fields = all(:css, 'form .form-control')
|
17
|
+
fields[0].set('test@test.com')
|
18
|
+
fields[1].set('awes0mesEcRet')
|
19
|
+
click_button 'Login'
|
20
20
|
|
21
|
-
|
21
|
+
visit '/callbacks'
|
22
22
|
|
23
|
-
|
23
|
+
expect(page).to have_content('user_connect')
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
click_link 'Test Account 9550'
|
26
|
+
click_link 'Logout'
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
28
|
+
expect(page).to have_content('user_disconnect')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'volt/utils/data_transformer'
|
3
|
+
|
4
|
+
describe Volt::DataTransformer do
|
5
|
+
it 'should transform values' do
|
6
|
+
data = {
|
7
|
+
name: 'Bob',
|
8
|
+
stuff: [
|
9
|
+
{key: /regex/}
|
10
|
+
],
|
11
|
+
other: /another regex/,
|
12
|
+
/some reg/ => 'value'
|
13
|
+
}
|
14
|
+
|
15
|
+
transformed = {
|
16
|
+
:name=>"Bob",
|
17
|
+
:stuff=>[
|
18
|
+
{:key=>"a regex"}
|
19
|
+
],
|
20
|
+
:other=>"a regex",
|
21
|
+
"a regex"=>"value"
|
22
|
+
}
|
23
|
+
|
24
|
+
result = Volt::DataTransformer.transform(data) do |value|
|
25
|
+
if value.is_a?(Regexp)
|
26
|
+
'a regex'
|
27
|
+
else
|
28
|
+
value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
expect(result).to eq(transformed)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should transform keys' do
|
36
|
+
data = {
|
37
|
+
'name' => 'Ryan',
|
38
|
+
'info' => [
|
39
|
+
{'place' => 'Bozeman'}
|
40
|
+
]
|
41
|
+
}
|
42
|
+
transformed = {:name=>"Ryan", :info=>[{:place=>"Bozeman"}]}
|
43
|
+
result = Volt::DataTransformer.transform_keys(data) do |key|
|
44
|
+
key.to_sym
|
45
|
+
end
|
46
|
+
|
47
|
+
expect(result).to eq(transformed)
|
48
|
+
end
|
49
|
+
end
|
data/templates/newgem/Gemfile.tt
CHANGED
@@ -8,8 +8,5 @@ gemspec
|
|
8
8
|
# The implementation of ReadWriteLock in Volt uses concurrent ruby and ext helps performance.
|
9
9
|
gem 'concurrent-ruby-ext', '~> 0.8.0'
|
10
10
|
|
11
|
-
# For mongo (optional)
|
12
|
-
gem 'bson_ext', '~> 1.9.0'
|
13
|
-
|
14
11
|
# Gems you use for development should be added to the gemspec file as
|
15
12
|
# development dependencies.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: volt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.6.
|
4
|
+
version: 0.9.6.pre3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Stout
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -584,11 +584,11 @@ files:
|
|
584
584
|
- lib/volt/spec/capybara.rb
|
585
585
|
- lib/volt/spec/sauce_labs.rb
|
586
586
|
- lib/volt/spec/setup.rb
|
587
|
-
- lib/volt/store/mongo.rb
|
588
587
|
- lib/volt/tasks/dispatcher.rb
|
589
588
|
- lib/volt/tasks/task.rb
|
590
589
|
- lib/volt/utils/boolean_patch.rb
|
591
590
|
- lib/volt/utils/csso_patch.rb
|
591
|
+
- lib/volt/utils/data_transformer.rb
|
592
592
|
- lib/volt/utils/ejson.rb
|
593
593
|
- lib/volt/utils/event_counter.rb
|
594
594
|
- lib/volt/utils/generic_counting_pool.rb
|
@@ -767,13 +767,13 @@ files:
|
|
767
767
|
- spec/server/rack/sprockets_helpers_setup.rb
|
768
768
|
- spec/server/socket_connection_handler_spec.rb
|
769
769
|
- spec/spec_helper.rb
|
770
|
-
- spec/store/mongo_spec.rb
|
771
770
|
- spec/tasks/dispatcher_spec.rb
|
772
771
|
- spec/tasks/live_query_spec.rb
|
773
772
|
- spec/tasks/query_tasks.rb
|
774
773
|
- spec/tasks/query_tracker_spec.rb
|
775
774
|
- spec/tasks/user_tasks_spec.rb
|
776
775
|
- spec/templates/targets/binding_document/component_node_spec.rb
|
776
|
+
- spec/utils/data_transformer_spec.rb
|
777
777
|
- spec/utils/ejson_spec.rb
|
778
778
|
- spec/utils/generic_counting_pool_spec.rb
|
779
779
|
- spec/utils/generic_pool_spec.rb
|
@@ -1046,13 +1046,13 @@ test_files:
|
|
1046
1046
|
- spec/server/rack/sprockets_helpers_setup.rb
|
1047
1047
|
- spec/server/socket_connection_handler_spec.rb
|
1048
1048
|
- spec/spec_helper.rb
|
1049
|
-
- spec/store/mongo_spec.rb
|
1050
1049
|
- spec/tasks/dispatcher_spec.rb
|
1051
1050
|
- spec/tasks/live_query_spec.rb
|
1052
1051
|
- spec/tasks/query_tasks.rb
|
1053
1052
|
- spec/tasks/query_tracker_spec.rb
|
1054
1053
|
- spec/tasks/user_tasks_spec.rb
|
1055
1054
|
- spec/templates/targets/binding_document/component_node_spec.rb
|
1055
|
+
- spec/utils/data_transformer_spec.rb
|
1056
1056
|
- spec/utils/ejson_spec.rb
|
1057
1057
|
- spec/utils/generic_counting_pool_spec.rb
|
1058
1058
|
- spec/utils/generic_pool_spec.rb
|
data/lib/volt/store/mongo.rb
DELETED