reactive-record 0.7.43 → 0.8.1

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: 86d52b07368a6c876967105bd2fb568be5f096c4
4
- data.tar.gz: 4c6d750fa88d8b911c49c82e71dc2b0dbd310f9a
3
+ metadata.gz: a836715dff414352aca8fa4fbe91d987d4ac219d
4
+ data.tar.gz: e7077d62b8071a21c0ea4289ccd3a7b9dd5e3938
5
5
  SHA512:
6
- metadata.gz: cfeb1ad43df431279b4f5bf1ad111ebbc3bc46b490570b3a8851807e30ba017ecdd00ddc1304130fce24b357386a24924bbcbbd0acee54db413d0ff210861e5c
7
- data.tar.gz: 0475c3f0213a39db32e12e4c1e471ca4dddbfd387d9e7b8641efc9839fbca37c221e887a3ae9bf3dd8b04846c5c5b99aaa4dae0818389900f5c93d8eaee2dd77
6
+ metadata.gz: ec0ca8663425dd46831d51cbb029897f51394c1432055d5f05f01063d2e7eb8fc5716e0111d664e6bab423998c3a70e9a3de4f0077bd3a230ca80b84351375c4
7
+ data.tar.gz: 10819073b864f14caea7934d1e79b7f1d605b40a47b6bf6ee454f9c42fe555a8fe034c5d083f6bc4e7f2b3453b7bbaaaff789c6a464037c180c54ef9fb798508
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Reactive Record
2
+
3
+ [![Join the chat at https://gitter.im/catprintlabs/reactive-record](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/reactrb/chat?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
+ [![Code Climate](https://codeclimate.com/github/reactrb/reactive-record/badges/gpa.svg)](https://codeclimate.com/github/reactrb/reactive-record)
5
+ [![Gem Version](https://badge.fury.io/rb/reactive-record.svg)](https://badge.fury.io/rb/reactive-record)
6
+
7
+
8
+ #### reactive-record gives you active-record models on the client integrated with reactrb.
9
+
10
+ *"So simple its almost magic" (Amazed developer)*
11
+
12
+ #### NOTE: reactive-record >= 0.8.x depends on the reactrb gem. You must [upgrade to reactrb](https://github.com/reactrb/reactrb#upgrading-to-reactrb)
13
+
14
+ You do nothing to your current active-record models except move them to the models/public directory (so they are compiled on the client as well as the server.)
15
+
16
+ * Fully integrated with [Reactrb](https://github.com/reactrb/reactrb) (which is React with a beautiful ruby dsl.)
17
+ * Takes advantage of React prerendering, and afterwards additional data is *lazy loaded* as it is needed by the client.
18
+ * Supports full CRUD access using standard Active Record features, including associations, aggregations, and errors.
19
+ * Uses model based authorization mechanism for security similar to [Hobo](http://www.hobocentral.net/manual/permissions) or [Pundit](https://github.com/elabs/pundit).
20
+ * Models and even methods within models can be selectively implemented "server-side" only.
21
+
22
+ There are no docs yet, but you may consider the test cases as a starting point, or have a look at [reactrb todo](https://reactiverb-todo.herokuapp.com/) (live demo [here.](https://reactiverb-todo.herokuapp.com/))
23
+
24
+ For best results simply use the [reactrb-rails-installer](https://github.com/reactrb/reactrb-rails-installer) to install everything you need into a new or existing rails app.
25
+
26
+ Head on over to [gitter.im](https://gitter.im/reactrb/chat) to ask any questions you might have!
27
+
28
+ Note: We have dropped suppport for the ability to load the same Class from two different files. If you need this functionality load the following code to your config/application.rb file.
29
+
30
+ ```ruby
31
+ module ::ActiveRecord
32
+ module Core
33
+ module ClassMethods
34
+ def inherited(child_class)
35
+ begin
36
+ file = Rails.root.join('app','models',"#{child_class.name.underscore}.rb").to_s rescue nil
37
+ begin
38
+ require file
39
+ rescue LoadError
40
+ end
41
+ # from active record:
42
+ child_class.initialize_find_by_cache
43
+ rescue
44
+ end # if File.exist?(Rails.root.join('app', 'view', 'models.rb'))
45
+ super
46
+ end
47
+ end
48
+ end
49
+ end
50
+ ```
@@ -6,9 +6,9 @@ module ReactiveRecord
6
6
 
7
7
  def fetch
8
8
  render :json => ReactiveRecord::ServerDataCache[
9
- (params[:models] || []).map(&:with_indifferent_access),
10
- (params[:associations] || []).map(&:with_indifferent_access),
11
- params[:pending_fetches],
9
+ (json_params[:models] || []).map(&:with_indifferent_access),
10
+ (json_params[:associations] || []).map(&:with_indifferent_access),
11
+ json_params[:pending_fetches],
12
12
  acting_user
13
13
  ]
14
14
  rescue Exception => e
@@ -17,10 +17,10 @@ module ReactiveRecord
17
17
 
18
18
  def save
19
19
  render :json => ReactiveRecord::Base.save_records(
20
- (params[:models] || []).map(&:with_indifferent_access),
21
- (params[:associations] || []).map(&:with_indifferent_access),
20
+ (json_params[:models] || []).map(&:with_indifferent_access),
21
+ (json_params[:associations] || []).map(&:with_indifferent_access),
22
22
  acting_user,
23
- params[:validate],
23
+ json_params[:validate],
24
24
  true
25
25
  )
26
26
  rescue Exception => e
@@ -29,15 +29,21 @@ module ReactiveRecord
29
29
 
30
30
  def destroy
31
31
  render :json => ReactiveRecord::Base.destroy_record(
32
- params[:model],
33
- params[:id],
34
- params[:vector],
32
+ json_params[:model],
33
+ json_params[:id],
34
+ json_params[:vector],
35
35
  acting_user
36
36
  )
37
37
  rescue Exception => e
38
38
  render json: {error: e.message, backtrace: e.backtrace}, status: 500
39
39
  end
40
40
 
41
+ private
42
+
43
+ def json_params
44
+ JSON.parse(params[:json]).symbolize_keys
45
+ end
46
+
41
47
  end
42
48
 
43
49
  end
@@ -1,6 +1,6 @@
1
1
  if RUBY_ENGINE == 'opal'
2
2
 
3
- require "reactive-ruby"
3
+ require "reactrb"
4
4
  require "reactive_record/active_record/error"
5
5
  require "reactive_record/server_data_cache"
6
6
  require "reactive_record/active_record/reactive_record/while_loading"
@@ -421,9 +421,9 @@ module ReactiveRecord
421
421
  elsif aggregation = @model.reflect_on_aggregation(method) and (aggregation.klass < ActiveRecord::Base)
422
422
  new_from_vector(aggregation.klass, self, *vector, method)
423
423
  elsif id and id != ""
424
- self.class.fetch_from_db([@model, [:find, id], *method]) || self.class.load_from_db(self, *vector, method)
424
+ self.class.fetch_from_db([@model, [:find, id], *method]) || self.class.load_from_db(self, *(vector ? vector : [nil]), method)
425
425
  else # its a attribute in an aggregate or we are on the client and don't know the id
426
- self.class.fetch_from_db([*vector, *method]) || self.class.load_from_db(self, *vector, method)
426
+ self.class.fetch_from_db([*vector, *method]) || self.class.load_from_db(self, *(vector ? vector : [nil]), method)
427
427
  end
428
428
  new_value = @attributes[method] if new_value.is_a? DummyValue and @attributes.has_key?(method)
429
429
  sync_attribute(method, new_value)
@@ -439,7 +439,7 @@ module ReactiveRecord
439
439
  unless @attributes.has_key?(method)
440
440
  log("Warning: reading from new #{model.name}.#{method} before assignment. Will fetch value from server. This may not be what you expected!!", :warning)
441
441
  end
442
- new_value = self.class.load_from_db(self, *vector, method)
442
+ new_value = self.class.load_from_db(self, *(vector ? vector : [nil]), method)
443
443
  new_value = @attributes[method] if new_value.is_a? DummyValue and @attributes.has_key?(method)
444
444
  sync_attribute(method, new_value)
445
445
  end
@@ -167,6 +167,10 @@ module ReactiveRecord
167
167
  @dummy_collection.loading?
168
168
  end
169
169
 
170
+ def empty? # should be handled by method missing below, but opal-rspec does not deal well with method missing, so to test...
171
+ all.empty?
172
+ end
173
+
170
174
  def method_missing(method, *args, &block)
171
175
  if [].respond_to? method
172
176
  all.send(method, *args, &block)
@@ -167,6 +167,11 @@ module ReactiveRecord
167
167
  0
168
168
  end
169
169
 
170
+ def to_number
171
+ notify
172
+ 0
173
+ end
174
+
170
175
  def to_date
171
176
  notify
172
177
  "2001-01-01T00:00:00.000-00:00".to_date
@@ -196,7 +201,14 @@ module ReactiveRecord
196
201
  log(["Server Fetching: %o", pending_fetches.to_n])
197
202
  start_time = Time.now
198
203
  HTTP.post(`window.ReactiveRecordEnginePath`,
199
- payload: {models: models, associations: associations, pending_fetches: pending_fetches}).then do |response|
204
+ payload: {
205
+ json: {
206
+ models: models,
207
+ associations: associations,
208
+ pending_fetches: pending_fetches
209
+ }.to_json
210
+ }
211
+ ).then do |response|
200
212
  fetch_time = Time.now
201
213
  log(" Fetched in: #{(fetch_time-start_time).to_i}s")
202
214
  begin
@@ -301,7 +313,15 @@ module ReactiveRecord
301
313
 
302
314
  promise = Promise.new
303
315
 
304
- HTTP.post(`window.ReactiveRecordEnginePath`+"/save", payload: {models: models, associations: associations, validate: validate}).then do |response|
316
+ HTTP.post(`window.ReactiveRecordEnginePath`+"/save",
317
+ payload: {
318
+ json: {
319
+ models: models,
320
+ associations: associations,
321
+ validate: validate
322
+ }.to_json
323
+ }
324
+ ).then do |response|
305
325
  begin
306
326
  response.json[:models] = response.json[:saved_models].collect do |item|
307
327
  backing_records[item[0]].ar_instance
@@ -548,7 +568,15 @@ module ReactiveRecord
548
568
  promise = Promise.new
549
569
 
550
570
  if !data_loading? and (id or vector)
551
- HTTP.post(`window.ReactiveRecordEnginePath`+"/destroy", payload: {model: ar_instance.model_name, id: id, vector: vector}).then do |response|
571
+ HTTP.post(`window.ReactiveRecordEnginePath`+"/destroy",
572
+ payload: {
573
+ json: {
574
+ model: ar_instance.model_name,
575
+ id: id,
576
+ vector: vector
577
+ }.to_json
578
+ }
579
+ ).then do |response|
552
580
  sync_scopes
553
581
  yield response.json[:success], response.json[:message] if block
554
582
  promise.resolve response.json
@@ -158,7 +158,7 @@ module ReactiveRecord
158
158
  @waiting_on_resources = loading
159
159
  WhileLoading.add_style_sheet
160
160
  %x{
161
- var node = #{@native}.getDOMNode();
161
+ var node = #{dom_node};
162
162
  $(node).children(':nth-child(-1n+'+#{loaded_children.count}+')').addClass('reactive_record_show_when_loaded');
163
163
  $(node).children(':nth-child(1n+'+#{loaded_children.count+1}+')').addClass('reactive_record_show_while_loading');
164
164
  }
@@ -240,7 +240,7 @@ module React
240
240
  # Fyi, the while_loading container is responsible for setting its own link to itself
241
241
 
242
242
  %x{
243
- var node = #{@native}.getDOMNode();
243
+ var node = #{dom_node};
244
244
  if (!$(node).is('[data-reactive_record_enclosing_while_loading_container_id]')) {
245
245
  var while_loading_container = $(node).closest('[data-reactive_record_while_loading_container_id]')
246
246
  if (while_loading_container.length > 0) {
@@ -256,7 +256,7 @@ module React
256
256
 
257
257
  %x{
258
258
 
259
- var node = #{@native}.getDOMNode();
259
+ var node = #{dom_node};
260
260
  var while_loading_container_id = $(node).attr('data-reactive_record_enclosing_while_loading_container_id');
261
261
  if (while_loading_container_id) {
262
262
  var while_loading_container = $('[data-reactive_record_while_loading_container_id='+while_loading_container_id+']');
@@ -1,3 +1,3 @@
1
1
  module ReactiveRecord
2
- VERSION = "0.7.43"
2
+ VERSION = "0.8.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reactive-record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.43
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitch VanDuyn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-10 00:00:00.000000000 Z
11
+ date: 2016-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: reactive-ruby
126
+ name: reactrb
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -136,7 +136,8 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- description: Description of ReactiveRecord.
139
+ description: Access active-record models inside Reactrb components. Model data is
140
+ calculated during pre-rerendering, and then dynamically loaded as components update.
140
141
  email:
141
142
  - mitch@catprint.com
142
143
  executables: []
@@ -144,7 +145,7 @@ extensions: []
144
145
  extra_rdoc_files: []
145
146
  files:
146
147
  - MIT-LICENSE
147
- - README.rdoc
148
+ - README.md
148
149
  - Rakefile
149
150
  - app/controllers/reactive_record/application_controller.rb
150
151
  - app/controllers/reactive_record/reactive_record_controller.rb
@@ -172,7 +173,8 @@ files:
172
173
  homepage:
173
174
  licenses: []
174
175
  metadata: {}
175
- post_install_message:
176
+ post_install_message: As of version 0.8.x, reactive-record depends on reactrb instead
177
+ of reactive-ruby. If you have already switched, you can ignore this message.
176
178
  rdoc_options: []
177
179
  require_paths:
178
180
  - lib
@@ -188,8 +190,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
190
  version: '0'
189
191
  requirements: []
190
192
  rubyforge_project:
191
- rubygems_version: 2.4.8
193
+ rubygems_version: 2.5.1
192
194
  signing_key:
193
195
  specification_version: 4
194
- summary: Summary of ReactiveRecord.
196
+ summary: Access active-record models inside Reactrb components.
195
197
  test_files: []
data/README.rdoc DELETED
@@ -1,3 +0,0 @@
1
- = ReactiveRecord
2
-
3
- This project rocks and uses MIT-LICENSE.