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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16b909f645dc9943c62dcd512df36371ac4c1dfc
4
- data.tar.gz: 3b1bc0f0bdeef3eef63f9f7fbcbf47042a9f3fbe
3
+ metadata.gz: af40ada934fde21bab3077199e52634e939d0316
4
+ data.tar.gz: 6029344175c2e1fb6004226f3b7a83cc04420d90
5
5
  SHA512:
6
- metadata.gz: af36ac78914b63e4c3a1c9161a64ec36e85f317320540461bb5008852261a9c0f66a2016f9130d4578122fd4eab8f1bba62eff2e8c48746d9451d87bab66c09e
7
- data.tar.gz: 909e57f674271f32315f0f987cb28035703ed949bd704fe601c7ad547a287b9262a10f45525964796f8c92d557102cb3e232f44a82761f7a6da43acf854b12f6
6
+ metadata.gz: a83fff0163894a9d6bb91d2d50a4e746632c6650420522cd5c08442442de3ab71ca710e2b146bbd328990a9f9303e3e54e3bb43599458c4745532df8219e3773
7
+ data.tar.gz: 9587b05a0126bc352bc1d003d53380b3cd1ae0fb3f0ac9c2a02e2ba83c39c2aa2bd35e11a745c8e9a2cafc76ae8f4dc0673a8187d3ff5da611a91026ed47f866
data/.gitignore CHANGED
@@ -22,3 +22,4 @@ tmp
22
22
  sauce_connect.log
23
23
  .ruby-gemset
24
24
  tags
25
+ config/db/
data/Gemfile CHANGED
@@ -33,7 +33,6 @@ end
33
33
 
34
34
  group :development, :test do
35
35
  platform :mri do
36
- gem 'bson_ext'
37
36
 
38
37
  # For running tests
39
38
  gem 'thin'
@@ -55,7 +55,6 @@ class LiveQuery
55
55
  end
56
56
 
57
57
  def notify_changed(id, data, skip_channel)
58
- # puts "NOTIFY CHANGED"
59
58
  model = nil
60
59
 
61
60
  notify!(skip_channel) do |channel|
@@ -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
 
@@ -38,7 +38,7 @@ module Volt
38
38
  socket_url = "://#{socket_url}"
39
39
  end
40
40
 
41
- ws_proto = (`document.location.protocol` == 'https://') ? 'wss' : 'ws'
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
@@ -1,5 +1,5 @@
1
1
  module Volt
2
2
  module Version
3
- STRING = '0.9.6.pre2'
3
+ STRING = '0.9.6.pre3'
4
4
  end
5
5
  end
@@ -51,5 +51,4 @@ platform :mri do
51
51
  # Thin is the default volt server, you Puma is also supported
52
52
  gem 'thin', '~> 1.6.0'
53
53
  # gem 'puma'
54
- gem 'bson_ext', '~> 1.9.0'
55
54
  end
@@ -2,4 +2,5 @@ class Post < Volt::Model
2
2
  field :title, String
3
3
 
4
4
  validate :title, length: 5
5
- end
5
+
6
+ end
@@ -8,20 +8,20 @@ class User < Volt::User
8
8
  validate :email, email: true
9
9
 
10
10
  unless RUBY_PLATFORM == "opal"
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
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
- Volt.current_app.on("user_disconnect") do |user_id|
20
- begin
21
- Volt.current_app.store.users.where(id: user_id).first.sync._event_triggered = "user_disconnect"
22
- rescue
23
- #we rescue as this callback will also get called from the SocketConnectionHandler specs (and will fail)
24
- end
25
- end
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
- 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
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
- 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 '/'
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
- click_link 'Login'
14
+ click_link 'Login'
15
15
 
16
- fields = all(:css, 'form .form-control')
17
- fields[0].set('test@test.com')
18
- fields[1].set('awes0mesEcRet')
19
- click_button 'Login'
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
- visit '/callbacks'
21
+ visit '/callbacks'
22
22
 
23
- expect(page).to have_content('user_connect')
23
+ expect(page).to have_content('user_connect')
24
24
 
25
- click_link 'Test Account 9550'
26
- click_link 'Logout'
25
+ click_link 'Test Account 9550'
26
+ click_link 'Logout'
27
27
 
28
- expect(page).to have_content('user_disconnect')
29
- end
30
- end
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
@@ -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.
@@ -44,7 +44,6 @@ platform :mri, :mingw, :x64_mingw do
44
44
 
45
45
  # Thin is the default volt server, Puma is also supported
46
46
  gem 'thin', '~> 1.6.0'
47
- gem 'bson_ext', '~> 1.9.0'
48
47
  end
49
48
 
50
49
  group :production do
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.pre2
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-08 00:00:00.000000000 Z
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
@@ -1,5 +0,0 @@
1
- require 'mongo'
2
-
3
- mongo_client = Mongo::MongoClient.new('localhost', 27_017)
4
-
5
- db = mongo_client.db('test1')
@@ -1,7 +0,0 @@
1
- # require 'mongo'
2
- # include Mongo
3
- #
4
- # mongo_client = MongoClient.new("localhost", 27017)
5
- # items = mongo_client['docs']['items']
6
- #
7
- # items