live_record 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +8 -5
- data/app/assets/javascripts/live_record/model/create.coffee +3 -3
- data/app/channels/live_record/autoloads_channel.rb +2 -2
- data/lib/live_record/generators/templates/model.rb.rb +1 -1
- data/lib/live_record/version.rb +1 -1
- data/spec/features/live_record_syncing_spec.rb +1 -5
- data/spec/rails_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c61bf9ab10a4f26e259ef3750b09850b6327dfc0
|
4
|
+
data.tar.gz: b6e83b2a424ebf4933e97e10ce3333ed80a45c7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68339d0891798614e1570765aeca0a1069dcfbc76de04ba8c249afb14cd3f3309fdc139ef46c5feaae3257e382d922c1a971862d981bee9693a01bbc4be57d8a
|
7
|
+
data.tar.gz: aaee410eed406ac43b3f013759e8e45d0489ff08e553b5a2136403a8770d4a3346a19c699aed380e21de6735b22c663db48af48cec0a7f09cb6b35476c2e91be
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
> `live_record` is intentionally designed for read-only one-way syncing from the backend server, and does not support pushing changes to the Rails server from the client-side JS. Updates from client-side then is intended to use the normal HTTP REST requests.
|
12
12
|
|
13
|
-
*New Version 0.
|
13
|
+
*New Version 0.3!*
|
14
14
|
*See [Changelog below](#changelog)*
|
15
15
|
|
16
16
|
## Requirements
|
@@ -97,7 +97,7 @@
|
|
97
97
|
// `this` refers to the Book record that has been updated
|
98
98
|
|
99
99
|
console.log(this.attributes);
|
100
|
-
// this book record should have been updated with all other possible whitelisted attributes even if you just
|
100
|
+
// this book record should have been updated with all other possible whitelisted attributes even if you just initially passed in only the ID; thus console.log above would output below
|
101
101
|
// {id: 1, title: 'Harry Potter', author: 'J.K. Rowling', is_enabled: true, created_at: '2017-08-02T12:39:49.238Z', updated_at: '2017-08-02T12:39:49.238Z'}
|
102
102
|
|
103
103
|
console.log(this.changes)
|
@@ -132,7 +132,8 @@
|
|
132
132
|
end
|
133
133
|
|
134
134
|
def self.live_record_queryable_attributes(current_user)
|
135
|
-
# Add attributes to this array that you would like `current_user` to be able to query upon
|
135
|
+
# Add attributes to this array that you would like `current_user` to be able to query upon
|
136
|
+
# on the `subscribe({where: {...}})` and `autoload({where: {...}})` functions
|
136
137
|
# empty array means not-authorised
|
137
138
|
if current_user.isAdmin?
|
138
139
|
[:id, :title, :author, :created_at, :updated_at, :reference_id, :origin_address]
|
@@ -149,7 +150,7 @@
|
|
149
150
|
1. Add the following to your `Gemfile`:
|
150
151
|
|
151
152
|
```ruby
|
152
|
-
gem 'live_record', '~> 0.3.
|
153
|
+
gem 'live_record', '~> 0.3.2'
|
153
154
|
```
|
154
155
|
|
155
156
|
2. Run:
|
@@ -206,7 +207,7 @@
|
|
206
207
|
end
|
207
208
|
|
208
209
|
def self.live_record_queryable_attributes(current_user)
|
209
|
-
# Add attributes to this array that you would like current_user to query upon when using `.subscribe({where: {...})`
|
210
|
+
# Add attributes to this array that you would like current_user to query upon when using `.subscribe({where: {...})` and `.autoload({where: {...}})`
|
210
211
|
# Defaults to empty array, thereby blocking everything by default, only unless explicitly stated here so.
|
211
212
|
[:id, :title, :author, :created_at, :updated_at]
|
212
213
|
end
|
@@ -751,6 +752,8 @@ end
|
|
751
752
|
* MIT
|
752
753
|
|
753
754
|
## Changelog
|
755
|
+
* 0.3.2
|
756
|
+
* fixed `autoload()` `before:createOrUpdate` and `after:createOrUpdate` callbacks not triggering`
|
754
757
|
* 0.3.1
|
755
758
|
* removed a `console.log()` debugging code
|
756
759
|
* 0.3.0
|
@@ -96,7 +96,7 @@ LiveRecord.Model.create = (config) ->
|
|
96
96
|
@onAction[data.action].call(this, data)
|
97
97
|
|
98
98
|
onAction:
|
99
|
-
|
99
|
+
createOrUpdate: (data) ->
|
100
100
|
record = Model.all[data.attributes.id]
|
101
101
|
|
102
102
|
# if record already exists
|
@@ -107,12 +107,12 @@ LiveRecord.Model.create = (config) ->
|
|
107
107
|
record = new Model(data.attributes)
|
108
108
|
doesRecordAlreadyExist = false
|
109
109
|
|
110
|
-
config.callbacks['before:
|
110
|
+
config.callbacks['before:createOrUpdate'].call(this, record) if config.callbacks['before:createOrUpdate']
|
111
111
|
if doesRecordAlreadyExist
|
112
112
|
record.update(data.attributes)
|
113
113
|
else
|
114
114
|
record.create()
|
115
|
-
config.callbacks['after:
|
115
|
+
config.callbacks['after:createOrUpdate'].call(this, record) if config.callbacks['after:createOrUpdate']
|
116
116
|
|
117
117
|
# handler for received() callback above
|
118
118
|
onError:
|
@@ -46,7 +46,7 @@ class LiveRecord::AutoloadsChannel < LiveRecord::BaseChannel
|
|
46
46
|
whitelisted_attributes = LiveRecord::BaseChannel::Helpers.whitelisted_attributes(new_or_updated_record, current_user)
|
47
47
|
|
48
48
|
if whitelisted_attributes.size > 0
|
49
|
-
message = { 'action' => '
|
49
|
+
message = { 'action' => 'createOrUpdate', 'attributes' => new_or_updated_record.attributes }
|
50
50
|
response = filtered_message(message, whitelisted_attributes)
|
51
51
|
transmit response if response.present?
|
52
52
|
end
|
@@ -79,7 +79,7 @@ class LiveRecord::AutoloadsChannel < LiveRecord::BaseChannel
|
|
79
79
|
whitelisted_attributes = LiveRecord::BaseChannel::Helpers.whitelisted_attributes(record, current_user)
|
80
80
|
|
81
81
|
if whitelisted_attributes.size > 0
|
82
|
-
message = { 'action' => '
|
82
|
+
message = { 'action' => 'createOrUpdate', 'attributes' => record.attributes }
|
83
83
|
response = filtered_message(message, whitelisted_attributes)
|
84
84
|
transmit response if response.present?
|
85
85
|
end
|
@@ -31,7 +31,7 @@ class <%= class_name %> < <%= parent_class_name.classify %>
|
|
31
31
|
#
|
32
32
|
# Add attributes to this array that you would like current_user client to be able to query upon when "subscribing"
|
33
33
|
# Defaults to empty array, thereby blocking everything by default, only unless explicitly stated here so.
|
34
|
-
# i.e. if a current_user client subscribes
|
34
|
+
# i.e. if a current_user client subscribes using `.subscribe({where: {...}})` or `.autoload({where: {...}})`,
|
35
35
|
# then only these attributes will be considered in the "{where: ...}" argument
|
36
36
|
# if you're using `ransack` gem, use `ransackable_attributes`
|
37
37
|
# Empty array means unauthorized
|
data/lib/live_record/version.rb
CHANGED
@@ -8,11 +8,7 @@ RSpec.feature 'LiveRecord Syncing', type: :feature do
|
|
8
8
|
let(:post3) { create(:post, user: nil) }
|
9
9
|
let!(:users) { [user1, user2] }
|
10
10
|
let!(:posts) { [post1, post2, post3] }
|
11
|
-
|
12
|
-
# LiveRecord.helpers.loadRecords({ modelName: 'Post' });
|
13
|
-
# LiveRecord.helpers.loadRecords({ modelName: 'User', url: '<%= j users_path %>' });
|
14
|
-
# LiveRecord.Model.all.Post.subscribe({ where: { is_enabled_eq: true, content_eq: 'somecontent' }});
|
15
|
-
|
11
|
+
|
16
12
|
scenario 'User sees live changes (updates) of post records', js: true do
|
17
13
|
visit '/posts'
|
18
14
|
|
data/spec/rails_helper.rb
CHANGED
@@ -4,7 +4,7 @@ Dir[__dir__ + '/helpers/*.rb'].each {|file| require file }
|
|
4
4
|
|
5
5
|
ActiveRecord::Migration.maintain_test_schema!
|
6
6
|
|
7
|
-
Capybara.javascript_driver = :selenium_chrome_headless # :selenium_chrome
|
7
|
+
Capybara.javascript_driver = :selenium_chrome_headless # :selenium_chrome
|
8
8
|
Capybara.server = :puma
|
9
9
|
|
10
10
|
RSpec.configure do |config|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: live_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jules Roman B. Polidario
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|