couch_potato 1.7.0 → 1.10.1
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 +5 -5
- data/.github/workflows/ruby.yml +50 -0
- data/.gitignore +3 -0
- data/CHANGES.md +180 -130
- data/Gemfile +4 -0
- data/README.md +61 -85
- data/Rakefile +11 -10
- data/couch_potato-rspec.gemspec +2 -1
- data/couch_potato.gemspec +9 -7
- data/gemfiles/active_support_5_0 +6 -0
- data/gemfiles/active_support_5_1 +7 -0
- data/gemfiles/active_support_5_2 +6 -0
- data/gemfiles/active_support_6_0 +6 -0
- data/gemfiles/active_support_6_1 +6 -0
- data/gemfiles/active_support_7_0 +6 -0
- data/lib/couch_potato/database.rb +170 -71
- data/lib/couch_potato/persistence/dirty_attributes.rb +3 -21
- data/lib/couch_potato/persistence/magic_timestamps.rb +3 -3
- data/lib/couch_potato/persistence/properties.rb +15 -10
- data/lib/couch_potato/persistence/simple_property.rb +0 -4
- data/lib/couch_potato/persistence/type_caster.rb +11 -6
- data/lib/couch_potato/persistence.rb +0 -1
- data/lib/couch_potato/railtie.rb +6 -11
- data/lib/couch_potato/validation.rb +8 -0
- data/lib/couch_potato/version.rb +2 -2
- data/lib/couch_potato/view/base_view_spec.rb +8 -32
- data/lib/couch_potato/view/custom_views.rb +4 -3
- data/lib/couch_potato/view/flex_view_spec.rb +121 -0
- data/lib/couch_potato/view/view_parameters.rb +34 -0
- data/lib/couch_potato.rb +37 -16
- data/spec/callbacks_spec.rb +45 -19
- data/spec/conflict_handling_spec.rb +1 -2
- data/spec/property_spec.rb +12 -3
- data/spec/railtie_spec.rb +10 -0
- data/spec/spec_helper.rb +4 -3
- data/spec/unit/active_model_compliance_spec.rb +7 -3
- data/spec/unit/attributes_spec.rb +54 -1
- data/spec/unit/caching_spec.rb +105 -0
- data/spec/unit/couch_potato_spec.rb +70 -5
- data/spec/unit/create_spec.rb +5 -4
- data/spec/unit/database_spec.rb +239 -135
- data/spec/unit/dirty_attributes_spec.rb +5 -26
- data/spec/unit/flex_view_spec_spec.rb +17 -0
- data/spec/unit/model_view_spec_spec.rb +1 -1
- data/spec/unit/rspec_stub_db_spec.rb +31 -0
- data/spec/unit/validation_spec.rb +42 -2
- data/spec/unit/view_query_spec.rb +12 -7
- data/spec/views_spec.rb +214 -103
- data/vendor/pouchdb-collate/LICENSE +202 -0
- data/vendor/pouchdb-collate/pouchdb-collate.js +430 -0
- metadata +47 -36
- data/.ruby-version +0 -1
- data/.travis.yml +0 -21
- data/gemfiles/active_support_4_0 +0 -11
- data/gemfiles/active_support_4_1 +0 -11
- data/gemfiles/active_support_4_2 +0 -11
- data/lib/couch_potato/persistence/deep_dirty_attributes.rb +0 -180
- data/spec/unit/deep_dirty_attributes_spec.rb +0 -434
metadata
CHANGED
@@ -1,87 +1,93 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couch_potato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Lang
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activemodel
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1
|
22
|
+
version: '7.1'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.0'
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1
|
32
|
+
version: '7.1'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: couchrest
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.0.0
|
39
|
+
version: 2.0.0
|
34
40
|
type: :runtime
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: 2.0.0
|
46
|
+
version: 2.0.0
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
48
|
+
name: json
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
53
|
+
version: '2.3'
|
48
54
|
type: :runtime
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
60
|
+
version: '2.3'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
62
|
+
name: rake
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
65
|
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
67
|
+
version: '12.0'
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
72
|
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
74
|
+
version: '12.0'
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
76
|
+
name: rspec
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
72
78
|
requirements:
|
73
|
-
- - "
|
79
|
+
- - "~>"
|
74
80
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
81
|
+
version: 3.10.0
|
76
82
|
type: :development
|
77
83
|
prerelease: false
|
78
84
|
version_requirements: !ruby/object:Gem::Requirement
|
79
85
|
requirements:
|
80
|
-
- - "
|
86
|
+
- - "~>"
|
81
87
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
88
|
+
version: 3.10.0
|
83
89
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
90
|
+
name: timecop
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
93
|
- - ">="
|
@@ -95,7 +101,7 @@ dependencies:
|
|
95
101
|
- !ruby/object:Gem::Version
|
96
102
|
version: '0'
|
97
103
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
104
|
+
name: tzinfo
|
99
105
|
requirement: !ruby/object:Gem::Requirement
|
100
106
|
requirements:
|
101
107
|
- - ">="
|
@@ -114,9 +120,8 @@ executables: []
|
|
114
120
|
extensions: []
|
115
121
|
extra_rdoc_files: []
|
116
122
|
files:
|
123
|
+
- ".github/workflows/ruby.yml"
|
117
124
|
- ".gitignore"
|
118
|
-
- ".ruby-version"
|
119
|
-
- ".travis.yml"
|
120
125
|
- CHANGES.md
|
121
126
|
- CREDITS
|
122
127
|
- Gemfile
|
@@ -125,9 +130,12 @@ files:
|
|
125
130
|
- Rakefile
|
126
131
|
- couch_potato-rspec.gemspec
|
127
132
|
- couch_potato.gemspec
|
128
|
-
- gemfiles/
|
129
|
-
- gemfiles/
|
130
|
-
- gemfiles/
|
133
|
+
- gemfiles/active_support_5_0
|
134
|
+
- gemfiles/active_support_5_1
|
135
|
+
- gemfiles/active_support_5_2
|
136
|
+
- gemfiles/active_support_6_0
|
137
|
+
- gemfiles/active_support_6_1
|
138
|
+
- gemfiles/active_support_7_0
|
131
139
|
- init.rb
|
132
140
|
- lib/core_ext/date.rb
|
133
141
|
- lib/core_ext/time.rb
|
@@ -139,7 +147,6 @@ files:
|
|
139
147
|
- lib/couch_potato/persistence/active_model_compliance.rb
|
140
148
|
- lib/couch_potato/persistence/attachments.rb
|
141
149
|
- lib/couch_potato/persistence/callbacks.rb
|
142
|
-
- lib/couch_potato/persistence/deep_dirty_attributes.rb
|
143
150
|
- lib/couch_potato/persistence/deep_tracked_property.rb
|
144
151
|
- lib/couch_potato/persistence/dirty_attributes.rb
|
145
152
|
- lib/couch_potato/persistence/ghost_attributes.rb
|
@@ -155,10 +162,12 @@ files:
|
|
155
162
|
- lib/couch_potato/view/base_view_spec.rb
|
156
163
|
- lib/couch_potato/view/custom_view_spec.rb
|
157
164
|
- lib/couch_potato/view/custom_views.rb
|
165
|
+
- lib/couch_potato/view/flex_view_spec.rb
|
158
166
|
- lib/couch_potato/view/lists.rb
|
159
167
|
- lib/couch_potato/view/model_view_spec.rb
|
160
168
|
- lib/couch_potato/view/properties_view_spec.rb
|
161
169
|
- lib/couch_potato/view/raw_view_spec.rb
|
170
|
+
- lib/couch_potato/view/view_parameters.rb
|
162
171
|
- lib/couch_potato/view/view_query.rb
|
163
172
|
- rails/reload_classes.rb
|
164
173
|
- spec/attachments_spec.rb
|
@@ -179,6 +188,7 @@ files:
|
|
179
188
|
- spec/unit/active_model_compliance_spec.rb
|
180
189
|
- spec/unit/attributes_spec.rb
|
181
190
|
- spec/unit/base_view_spec_spec.rb
|
191
|
+
- spec/unit/caching_spec.rb
|
182
192
|
- spec/unit/callbacks_spec.rb
|
183
193
|
- spec/unit/couch_potato_spec.rb
|
184
194
|
- spec/unit/create_spec.rb
|
@@ -186,8 +196,8 @@ files:
|
|
186
196
|
- spec/unit/custom_views_spec.rb
|
187
197
|
- spec/unit/database_spec.rb
|
188
198
|
- spec/unit/date_spec.rb
|
189
|
-
- spec/unit/deep_dirty_attributes_spec.rb
|
190
199
|
- spec/unit/dirty_attributes_spec.rb
|
200
|
+
- spec/unit/flex_view_spec_spec.rb
|
191
201
|
- spec/unit/forbidden_attributes_protection_spec.rb
|
192
202
|
- spec/unit/initialize_spec.rb
|
193
203
|
- spec/unit/json_spec.rb
|
@@ -204,10 +214,12 @@ files:
|
|
204
214
|
- spec/update_spec.rb
|
205
215
|
- spec/view_updates_spec.rb
|
206
216
|
- spec/views_spec.rb
|
217
|
+
- vendor/pouchdb-collate/LICENSE
|
218
|
+
- vendor/pouchdb-collate/pouchdb-collate.js
|
207
219
|
homepage: http://github.com/langalex/couch_potato
|
208
220
|
licenses: []
|
209
221
|
metadata: {}
|
210
|
-
post_install_message:
|
222
|
+
post_install_message:
|
211
223
|
rdoc_options: []
|
212
224
|
require_paths:
|
213
225
|
- lib
|
@@ -222,9 +234,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
222
234
|
- !ruby/object:Gem::Version
|
223
235
|
version: '0'
|
224
236
|
requirements: []
|
225
|
-
|
226
|
-
|
227
|
-
signing_key:
|
237
|
+
rubygems_version: 3.2.32
|
238
|
+
signing_key:
|
228
239
|
specification_version: 4
|
229
240
|
summary: Ruby persistence layer for CouchDB
|
230
241
|
test_files:
|
@@ -246,6 +257,7 @@ test_files:
|
|
246
257
|
- spec/unit/active_model_compliance_spec.rb
|
247
258
|
- spec/unit/attributes_spec.rb
|
248
259
|
- spec/unit/base_view_spec_spec.rb
|
260
|
+
- spec/unit/caching_spec.rb
|
249
261
|
- spec/unit/callbacks_spec.rb
|
250
262
|
- spec/unit/couch_potato_spec.rb
|
251
263
|
- spec/unit/create_spec.rb
|
@@ -253,8 +265,8 @@ test_files:
|
|
253
265
|
- spec/unit/custom_views_spec.rb
|
254
266
|
- spec/unit/database_spec.rb
|
255
267
|
- spec/unit/date_spec.rb
|
256
|
-
- spec/unit/deep_dirty_attributes_spec.rb
|
257
268
|
- spec/unit/dirty_attributes_spec.rb
|
269
|
+
- spec/unit/flex_view_spec_spec.rb
|
258
270
|
- spec/unit/forbidden_attributes_protection_spec.rb
|
259
271
|
- spec/unit/initialize_spec.rb
|
260
272
|
- spec/unit/json_spec.rb
|
@@ -270,4 +282,3 @@ test_files:
|
|
270
282
|
- spec/update_spec.rb
|
271
283
|
- spec/view_updates_spec.rb
|
272
284
|
- spec/views_spec.rb
|
273
|
-
has_rdoc:
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.2.2
|
data/.travis.yml
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
rvm:
|
2
|
-
- 2.0.0
|
3
|
-
- 2.1.2
|
4
|
-
- 2.2.2
|
5
|
-
- 2.3.0
|
6
|
-
- jruby-9.0.1.0
|
7
|
-
- rbx-2.5.8
|
8
|
-
services:
|
9
|
-
- couchdb
|
10
|
-
gemfile:
|
11
|
-
- gemfiles/active_support_4_0
|
12
|
-
- gemfiles/active_support_4_1
|
13
|
-
- gemfiles/active_support_4_2
|
14
|
-
before_install:
|
15
|
-
gem install bundler --version 1.11.2
|
16
|
-
before_script:
|
17
|
-
- sudo sh -c 'echo "[native_query_servers]" >> /etc/couchdb/local.ini'
|
18
|
-
- sudo sh -c 'echo "erlang = {couch_native_process, start_link, []}" >> /etc/couchdb/local.ini'
|
19
|
-
- sudo /etc/init.d/couchdb restart
|
20
|
-
- bundle
|
21
|
-
script: bundle exec rake
|
data/gemfiles/active_support_4_0
DELETED
data/gemfiles/active_support_4_1
DELETED
data/gemfiles/active_support_4_2
DELETED
@@ -1,180 +0,0 @@
|
|
1
|
-
module CouchPotato
|
2
|
-
module Persistence
|
3
|
-
module DeepDirtyAttributes
|
4
|
-
|
5
|
-
def self.included(base) #:nodoc:
|
6
|
-
base.send :extend, ClassMethods
|
7
|
-
end
|
8
|
-
|
9
|
-
def initialize(*args, &block)
|
10
|
-
super(*args, &block)
|
11
|
-
reset_deep_dirty_attributes
|
12
|
-
end
|
13
|
-
|
14
|
-
def changed?
|
15
|
-
super || self.class.deep_tracked_properties.any? do |property|
|
16
|
-
send("#{property.name}_changed?")
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def changes
|
21
|
-
changes = super
|
22
|
-
if @original_deep_values
|
23
|
-
self.class.deep_tracked_properties.each do |property|
|
24
|
-
if send("#{property.name}_changed?")
|
25
|
-
changes[property.name] = send("#{property.name}_change")
|
26
|
-
else
|
27
|
-
changes.delete property.name
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
changes
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def reset_dirty_attributes
|
37
|
-
super
|
38
|
-
reset_deep_dirty_attributes
|
39
|
-
end
|
40
|
-
|
41
|
-
def reset_deep_dirty_attributes
|
42
|
-
@original_deep_values = HashWithIndifferentAccess.new
|
43
|
-
self.class.deep_tracked_properties.each do |property|
|
44
|
-
value = send(property.name)
|
45
|
-
if value
|
46
|
-
if doc?(value)
|
47
|
-
value.send(:reset_dirty_attributes)
|
48
|
-
elsif value.respond_to?(:each)
|
49
|
-
value.each do |item|
|
50
|
-
item.send(:reset_dirty_attributes) if doc?(item)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
@original_deep_values[property.name] = clone_attribute(value)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def doc_changed?(name)
|
59
|
-
old, new = @original_deep_values[name], send(name)
|
60
|
-
if old.nil? && new.nil?
|
61
|
-
false
|
62
|
-
elsif old.nil? ^ new.nil?
|
63
|
-
true
|
64
|
-
else
|
65
|
-
(doc?(new) && new.changed?) || old.to_hash != new.to_hash
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def simple_array_changed?(name)
|
70
|
-
@original_deep_values[name] != send(name)
|
71
|
-
end
|
72
|
-
|
73
|
-
def doc_array_changed?(name)
|
74
|
-
old, new = @original_deep_values[name], send(name)
|
75
|
-
if old.blank? && new.blank?
|
76
|
-
false
|
77
|
-
elsif old.blank? ^ new.blank?
|
78
|
-
true
|
79
|
-
else
|
80
|
-
old != new || old.map(&:to_hash) != new.map(&:to_hash)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def doc?(value)
|
85
|
-
value && value.respond_to?(:changed?)
|
86
|
-
end
|
87
|
-
|
88
|
-
def doc_change(name)
|
89
|
-
old, new = @original_deep_values[name], send(name)
|
90
|
-
if !old || !new || old != new
|
91
|
-
[old, new]
|
92
|
-
else
|
93
|
-
[old, doc_diff(old, new)]
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def doc_diff(old, new)
|
98
|
-
clone = clone_attribute(old)
|
99
|
-
clone.attributes = new.attributes
|
100
|
-
clone.changes
|
101
|
-
end
|
102
|
-
|
103
|
-
def simple_array_change(name)
|
104
|
-
value = send(name) || []
|
105
|
-
old = @original_deep_values[name] || []
|
106
|
-
changes = HashWithIndifferentAccess.new :added => value - old, :removed => old - value
|
107
|
-
[old, changes]
|
108
|
-
end
|
109
|
-
|
110
|
-
def doc_array_change(name)
|
111
|
-
old = @original_deep_values[name] || []
|
112
|
-
value = send(name)
|
113
|
-
|
114
|
-
added = value - old
|
115
|
-
removed = old - value
|
116
|
-
changed = value.map do |value_item|
|
117
|
-
old_item = old.detect {|i| i == value_item}
|
118
|
-
if old_item
|
119
|
-
changes = doc_diff(old_item, value_item)
|
120
|
-
unless changes.empty?
|
121
|
-
[old_item, changes]
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end.compact
|
125
|
-
changes = HashWithIndifferentAccess.new(:added => added, :removed => removed, :changed => changed)
|
126
|
-
|
127
|
-
[old, changes]
|
128
|
-
end
|
129
|
-
|
130
|
-
module ClassMethods #:nodoc:
|
131
|
-
def property(name, options = {})
|
132
|
-
super
|
133
|
-
if deep_trackable_type?(options[:type])
|
134
|
-
index = properties.find_index {|p| p.name == name}
|
135
|
-
properties.list[index] = DeepTrackedProperty.new(self, name, options)
|
136
|
-
end
|
137
|
-
remove_attribute_dirty_methods_from_activesupport_module
|
138
|
-
end
|
139
|
-
|
140
|
-
def remove_attribute_dirty_methods_from_activesupport_module
|
141
|
-
methods = deep_tracked_property_names.flat_map {|n| ["#{n}_changed?", "#{n}_change", "#{n}_was"]}.map(&:to_sym)
|
142
|
-
activesupport_modules = ancestors.select {|m| m.name.nil? && (methods - m.instance_methods).empty?}
|
143
|
-
activesupport_modules.each do |mod|
|
144
|
-
methods.each do |method|
|
145
|
-
mod.send :remove_method, method if mod.instance_methods.include?(method)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
def doc_array_type?(type)
|
151
|
-
type && type.is_a?(Array) && doc_type?(type[0])
|
152
|
-
end
|
153
|
-
|
154
|
-
def simple_array_type?(type)
|
155
|
-
type && type.is_a?(Array) && !doc_type?(type[0])
|
156
|
-
end
|
157
|
-
|
158
|
-
def doc_type?(type)
|
159
|
-
type &&
|
160
|
-
type.respond_to?(:included_modules) &&
|
161
|
-
type.included_modules.include?(DirtyAttributes)
|
162
|
-
end
|
163
|
-
|
164
|
-
def deep_trackable_type?(type)
|
165
|
-
type && type.is_a?(Array) || doc_type?(type)
|
166
|
-
end
|
167
|
-
|
168
|
-
def deep_tracked_properties
|
169
|
-
properties.select do |property|
|
170
|
-
property.is_a? DeepTrackedProperty
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
def deep_tracked_property_names
|
175
|
-
deep_tracked_properties.map(&:name)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|