reactive-record 0.7.11 → 0.7.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06aea49de3ad2b4cecc3fd5361411b9caaa9f8c1
4
- data.tar.gz: ac539741bf1817ffccdac4fb2a05be56a9a73575
3
+ metadata.gz: 20ba896842b898324934f9ede8523629f9ea8ca8
4
+ data.tar.gz: 1ca9086a7a22e06608995599e5e66145b939c43f
5
5
  SHA512:
6
- metadata.gz: 9bc27fd3212e4384b081582bcd7a020fa8de5e33e45cdf02222d46a978ca5e8adf60d2c42b123cef47505d1a923662809a5e9fe70c547b8cb776be2323abf4cf
7
- data.tar.gz: ca69357ef64c353040b7fd18498e25369a3e940edd128d120896a9474a30b00148ae05463de692021e5f0cf88bd0063804d0a0da653d1bf2bb972c50beaaee5e
6
+ metadata.gz: b36afcbffd5e424ccb005cf321d3f830df588c259e198f3b7dc465b62476d7687761c4486f54e6ddc43b2bdb0b7fb51d8835c0b2c90d5c2609f178782abf1341
7
+ data.tar.gz: 77b1454fb5434af9d1b69ee4763eb1ed5e25b302117f889a0e9d3986c8c525fc50e711138bb5880a2bb6e5cd4ca40e8a3f9b5937b712b3b44e14ecd5a0139729
@@ -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) == self
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.each { |key, value| param[key] = [value] }
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
@@ -13,6 +13,10 @@ module ActiveModel
13
13
  messages[attribute]
14
14
  end
15
15
 
16
+ def delete(attribute)
17
+ messages.delete(attribute)
18
+ end
19
+
16
20
  def empty?
17
21
  messages.empty?
18
22
  end
@@ -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
- response.json[:models] = response.json[:saved_models].collect do |item|
249
- backing_records[item[0]].ar_instance
250
- end
248
+ response.json[:models] = response.json[:saved_models].collect do |item|
249
+ backing_records[item[0]].ar_instance
250
+ end
251
251
 
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]
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
- yield response.json[:success], response.json[:message], response.json[:models] if block
263
- promise.resolve response.json
262
+ yield response.json[:success], response.json[:message], response.json[:models] if block
263
+ promise.resolve response.json
264
264
 
265
- backing_records.each { |id, record| record.saved! } if response.json(:success)
266
- rescue Exception => e
267
- puts "whahhh #{e}"
268
- end
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
@@ -1,3 +1,3 @@
1
1
  module ReactiveRecord
2
- VERSION = "0.7.11"
2
+ VERSION = "0.7.12"
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.11
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-04 00:00:00.000000000 Z
11
+ date: 2015-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails