volt 0.8.27.beta5 → 0.8.27.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/app/volt/tasks/store_tasks.rb +2 -2
- data/lib/volt/controllers/model_controller.rb +17 -0
- data/lib/volt/models/buffer.rb +11 -15
- data/lib/volt/models/model.rb +7 -6
- data/lib/volt/models/permissions.rb +2 -1
- data/lib/volt/models/persistors/model_store.rb +1 -0
- data/lib/volt/models/validations.rb +1 -0
- data/spec/models/model_spec.rb +4 -0
- data/spec/models/validations_spec.rb +1 -0
- 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: 664d87e842c6c03b483345d4771a71d72ad1567e
|
4
|
+
data.tar.gz: 8e82d85deddbc176c6cda90317b5a005f63f918d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8e1ffac496bf1ead1564de04a4dac9a48ccbc68776d5db3fa0b9bb8ed2fcb7b10a31c9e5869f1f521f6b0d0796c37937a041a4efbe398d674e0884cbf93e3c2
|
7
|
+
data.tar.gz: 5e54e036809c3d61f75de5a80f01658d46ef572aacc0193c45498a97b92c41dc665e2b761dcc848f7206a21240b18698557cc2df90be43cdf36b39b4594cce9c
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.27.
|
1
|
+
0.8.27.beta6
|
@@ -25,8 +25,8 @@ class StoreTasks < Volt::TaskHandler
|
|
25
25
|
# Create a buffer
|
26
26
|
buffer = model.buffer
|
27
27
|
|
28
|
-
# Assign the data
|
29
|
-
buffer.assign_attributes(data, true)
|
28
|
+
# Assign the changed data to the buffer
|
29
|
+
buffer.assign_attributes(data, false, true)
|
30
30
|
|
31
31
|
buffer
|
32
32
|
end
|
@@ -38,6 +38,23 @@ module Volt
|
|
38
38
|
|
39
39
|
# Sets the current model on this controller
|
40
40
|
def model=(val)
|
41
|
+
if val.is_a?(Promise)
|
42
|
+
# Resolve the promise before setting
|
43
|
+
@last_promise = val
|
44
|
+
|
45
|
+
val.then do |result|
|
46
|
+
# Only assign if nothing else has been assigned since we started the resolve
|
47
|
+
self.model = result if @last_promise == val
|
48
|
+
end.fail do |err|
|
49
|
+
Volt.logger.error("Unable to resolve promise assigned to model on #{inspect}")
|
50
|
+
end
|
51
|
+
|
52
|
+
return
|
53
|
+
end
|
54
|
+
|
55
|
+
# Clear
|
56
|
+
@last_promise = nil
|
57
|
+
|
41
58
|
# Start with a nil reactive value.
|
42
59
|
self.current_model ||= Model.new
|
43
60
|
|
data/lib/volt/models/buffer.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
module Volt
|
2
2
|
module Buffer
|
3
3
|
def save!
|
4
|
-
#
|
4
|
+
# TODO: this shouldn't need to be run, but if no attributes are assigned, then
|
5
|
+
# if needs to be run. Maybe there's a better way to handle it.
|
6
|
+
validate!
|
7
|
+
|
8
|
+
# Get errors from validate
|
5
9
|
errors = self.errors.to_h
|
6
10
|
|
7
11
|
if errors.size == 0
|
@@ -12,7 +16,7 @@ module Volt
|
|
12
16
|
promise = save_to.append(attributes)
|
13
17
|
else
|
14
18
|
# We have a saved model
|
15
|
-
promise = save_to.assign_attributes(attributes
|
19
|
+
promise = save_to.assign_attributes(attributes)
|
16
20
|
end
|
17
21
|
|
18
22
|
return promise.then do |new_model|
|
@@ -64,20 +68,12 @@ module Volt
|
|
64
68
|
model_klass = self.class
|
65
69
|
|
66
70
|
new_options = options.merge(path: model_path, save_to: self, buffer: true).reject { |k, _| k.to_sym == :persistor }
|
67
|
-
model = model_klass.new({}, new_options, :loading)
|
68
71
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end.fail do |err|
|
75
|
-
# TODO: right now this error gets ignored a lot, so lets log.
|
76
|
-
Volt.logger.error("error setting up buffer: #{err.inspect}")
|
77
|
-
Volt.logger.error(err.backtrace)
|
78
|
-
|
79
|
-
raise err
|
80
|
-
end
|
72
|
+
model = nil
|
73
|
+
Volt::Model.no_validate do
|
74
|
+
model = model_klass.new(attributes, new_options, :loaded)
|
75
|
+
|
76
|
+
model.instance_variable_set('@new', @new)
|
81
77
|
end
|
82
78
|
|
83
79
|
model
|
data/lib/volt/models/model.rb
CHANGED
@@ -124,16 +124,16 @@ module Volt
|
|
124
124
|
end
|
125
125
|
|
126
126
|
# Assign multiple attributes as a hash, directly.
|
127
|
-
def assign_attributes(attrs, initial_setup =
|
128
|
-
@attributes
|
127
|
+
def assign_attributes(attrs, initial_setup=false, skip_changes=false)
|
128
|
+
@attributes ||= {}
|
129
129
|
|
130
130
|
attrs = wrap_values(attrs)
|
131
131
|
|
132
132
|
if attrs
|
133
133
|
# When doing a mass-assign, we don't validate or save until the end.
|
134
|
-
if initial_setup
|
134
|
+
if initial_setup || skip_changes
|
135
135
|
Model.no_change_tracking do
|
136
|
-
assign_all_attributes(attrs)
|
136
|
+
assign_all_attributes(attrs, skip_changes)
|
137
137
|
end
|
138
138
|
else
|
139
139
|
assign_all_attributes(attrs)
|
@@ -403,13 +403,14 @@ module Volt
|
|
403
403
|
end
|
404
404
|
|
405
405
|
# Used internally from other methods that assign all attributes
|
406
|
-
def assign_all_attributes(attrs)
|
406
|
+
def assign_all_attributes(attrs, track_changes=false)
|
407
407
|
# Assign each attribute using setters
|
408
408
|
attrs.each_pair do |key, value|
|
409
409
|
key = key.to_sym
|
410
410
|
|
411
411
|
# Track the change, since assign_all_attributes runs with no_change_tracking
|
412
|
-
|
412
|
+
old_val = @attributes[key]
|
413
|
+
attribute_will_change!(key, old_val) if track_changes && old_val != value
|
413
414
|
|
414
415
|
if self.respond_to?(:"#{key}=")
|
415
416
|
# If a method without an underscore is defined, call that.
|
@@ -12,7 +12,8 @@ module Volt
|
|
12
12
|
def own_by_user(key=:user_id)
|
13
13
|
# When the model is created, assign it the user_id (if the user is logged in)
|
14
14
|
on(:new) do
|
15
|
-
|
15
|
+
# Only assign the user_id if there isn't already one and the user is logged in.
|
16
|
+
if _user_id.nil? && !(user_id = Volt.user_id).nil?
|
16
17
|
send(:"_#{key}=", user_id)
|
17
18
|
end
|
18
19
|
end
|
@@ -98,6 +98,7 @@ module Volt
|
|
98
98
|
# @return [Boolean] true if one of the changed fields has an error.
|
99
99
|
def error_in_changed_attributes?
|
100
100
|
errs = errors
|
101
|
+
|
101
102
|
changed_attributes.each_pair do |key, _|
|
102
103
|
# If any of the fields with errors are also the ones that were
|
103
104
|
return true if errs[key]
|
data/spec/models/model_spec.rb
CHANGED
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.8.27.
|
4
|
+
version: 0.8.27.beta6
|
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-04-
|
11
|
+
date: 2015-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|