reactive-record 0.7.11 → 0.7.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reactive-record.rb +21 -0
- data/lib/reactive_record/active_record/class_methods.rb +5 -5
- data/lib/reactive_record/active_record/error.rb +4 -0
- data/lib/reactive_record/active_record/reactive_record/base.rb +6 -4
- data/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb +17 -17
- data/lib/reactive_record/version.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: 20ba896842b898324934f9ede8523629f9ea8ca8
|
4
|
+
data.tar.gz: 1ca9086a7a22e06608995599e5e66145b939c43f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b36afcbffd5e424ccb005cf321d3f830df588c259e198f3b7dc465b62476d7687761c4486f54e6ddc43b2bdb0b7fb51d8835c0b2c90d5c2609f178782abf1341
|
7
|
+
data.tar.gz: 77b1454fb5434af9d1b69ee4763eb1ed5e25b302117f889a0e9d3986c8c525fc50e711138bb5880a2bb6e5cd4ca40e8a3f9b5937b712b3b44e14ecd5a0139729
|
data/lib/reactive-record.rb
CHANGED
@@ -16,6 +16,27 @@ if RUBY_ENGINE == 'opal'
|
|
16
16
|
|
17
17
|
else
|
18
18
|
|
19
|
+
module ::ActiveRecord
|
20
|
+
module Core
|
21
|
+
module ClassMethods
|
22
|
+
def inherited(child_class)
|
23
|
+
begin
|
24
|
+
file = Rails.root.join('app','models',"#{child_class.name.underscore}.rb").to_s rescue nil
|
25
|
+
begin
|
26
|
+
require file
|
27
|
+
rescue LoadError
|
28
|
+
end
|
29
|
+
# from active record:
|
30
|
+
child_class.initialize_find_by_cache
|
31
|
+
rescue
|
32
|
+
end
|
33
|
+
super
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
19
40
|
require "opal"
|
20
41
|
require "reactive_record/version"
|
21
42
|
require "reactive_record/permissions"
|
@@ -81,7 +81,7 @@ module ActiveRecord
|
|
81
81
|
[:belongs_to, :has_many, :has_one].each do |macro|
|
82
82
|
define_method(macro) do |*args| # is this a bug in opal? saying name, scope=nil, opts={} does not work!
|
83
83
|
name = args.first
|
84
|
-
opts = args.last
|
84
|
+
opts = (args.count > 1 and args.last.is_a? Hash) ? args.last : {}
|
85
85
|
Associations::AssociationReflection.new(base_class, macro, name, opts)
|
86
86
|
end
|
87
87
|
end
|
@@ -92,7 +92,7 @@ module ActiveRecord
|
|
92
92
|
|
93
93
|
[
|
94
94
|
"table_name=", "before_validation", "with_options", "validates_presence_of", "validates_format_of",
|
95
|
-
"accepts_nested_attributes_for", "after_create", "before_save", "before_destroy", "where", "validate",
|
95
|
+
"accepts_nested_attributes_for", "before_create", "after_create", "before_save", "after_save", "before_destroy", "where", "validate",
|
96
96
|
"attr_protected", "validates_numericality_of", "default_scope", "has_attached_file", "attr_accessible",
|
97
97
|
"serialize"
|
98
98
|
].each do |method|
|
@@ -107,11 +107,11 @@ module ActiveRecord
|
|
107
107
|
param
|
108
108
|
elsif param.is_a? Hash
|
109
109
|
if opt == :validate_only
|
110
|
-
ReactiveRecord::Base.infer_type_from_hash(self, param)
|
110
|
+
klass = ReactiveRecord::Base.infer_type_from_hash(self, param)
|
111
|
+
klass == self or klass < self
|
111
112
|
else
|
112
113
|
target = find(param[primary_key])
|
113
|
-
param.
|
114
|
-
ReactiveRecord::Base.load_from_json(param, target)
|
114
|
+
ReactiveRecord::Base.load_from_json(Hash[param.collect { |key, value| [key, [value]] }], target)
|
115
115
|
target
|
116
116
|
end
|
117
117
|
else
|
@@ -64,9 +64,6 @@ module ReactiveRecord
|
|
64
64
|
model = model.base_class
|
65
65
|
# already have a record with this attribute-value pair?
|
66
66
|
record = @records[model].detect { |record| record.attributes[attribute] == value}
|
67
|
-
if !record and attribute == 'id' and !@disabled_debugging
|
68
|
-
# `debugger`
|
69
|
-
end
|
70
67
|
unless record
|
71
68
|
# if not, and then the record may be loaded, but not have this attribute set yet,
|
72
69
|
# so find the id of of record with the attribute-value pair, and see if that is loaded.
|
@@ -244,8 +241,13 @@ module ReactiveRecord
|
|
244
241
|
|
245
242
|
def saved!(errors = nil) # sets saving to false AND notifies
|
246
243
|
@saving = false
|
247
|
-
React::State.set_state(self, self, :saved) unless data_loading? or errors
|
248
244
|
@errors = ActiveModel::Error.new(errors)
|
245
|
+
if errors
|
246
|
+
#errors.each { |attribute, error| React::State.set_state(self, attribute, attributes[attribute]) }
|
247
|
+
React::State.set_state(self, self, :errors)
|
248
|
+
elsif !data_loading?
|
249
|
+
React::State.set_state(self, self, :saved)
|
250
|
+
end
|
249
251
|
self
|
250
252
|
end
|
251
253
|
|
@@ -245,27 +245,27 @@ module ReactiveRecord
|
|
245
245
|
|
246
246
|
HTTP.post(`window.ReactiveRecordEnginePath`+"/save", payload: {models: models, associations: associations}).then do |response|
|
247
247
|
begin
|
248
|
-
|
249
|
-
|
250
|
-
|
248
|
+
response.json[:models] = response.json[:saved_models].collect do |item|
|
249
|
+
backing_records[item[0]].ar_instance
|
250
|
+
end
|
251
251
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
252
|
+
if response.json[:success]
|
253
|
+
response.json[:saved_models].each { | item | backing_records[item[0]].sync!(item[2]) }
|
254
|
+
else
|
255
|
+
response.json[:saved_models].each { | item | backing_records[item[0]].saved! item[3] }
|
256
|
+
log("Reactive Record Save Failed: #{response.json[:message]}", :error)
|
257
|
+
response.json[:saved_models].each do | item |
|
258
|
+
log(" Model: #{item[1]}[#{item[0]}] Attributes: #{item[2]} Errors: #{item[3]}", :error) if item[3]
|
259
|
+
end
|
259
260
|
end
|
260
|
-
end
|
261
261
|
|
262
|
-
|
263
|
-
|
262
|
+
yield response.json[:success], response.json[:message], response.json[:models] if block
|
263
|
+
promise.resolve response.json
|
264
264
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
265
|
+
backing_records.each { |id, record| record.saved! } if response.json[:success]
|
266
|
+
rescue Exception => e
|
267
|
+
puts "Save Failed: #{e}"
|
268
|
+
end
|
269
269
|
end
|
270
270
|
promise
|
271
271
|
else
|
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.
|
4
|
+
version: 0.7.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mitch VanDuyn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|