couch_potato 1.6.5 → 1.10.0

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.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +44 -0
  3. data/.gitignore +3 -0
  4. data/CHANGES.md +197 -122
  5. data/Gemfile +4 -0
  6. data/README.md +61 -85
  7. data/Rakefile +11 -10
  8. data/couch_potato-rspec.gemspec +3 -2
  9. data/couch_potato.gemspec +9 -7
  10. data/gemfiles/active_support_5_0 +6 -0
  11. data/gemfiles/active_support_5_1 +7 -0
  12. data/gemfiles/active_support_5_2 +6 -0
  13. data/gemfiles/active_support_6_0 +6 -0
  14. data/gemfiles/active_support_6_1 +6 -0
  15. data/gemfiles/active_support_7_0 +6 -0
  16. data/lib/couch_potato/database.rb +168 -71
  17. data/lib/couch_potato/persistence/dirty_attributes.rb +3 -21
  18. data/lib/couch_potato/persistence/magic_timestamps.rb +3 -3
  19. data/lib/couch_potato/persistence/properties.rb +15 -10
  20. data/lib/couch_potato/persistence/revisions.rb +14 -0
  21. data/lib/couch_potato/persistence/simple_property.rb +0 -4
  22. data/lib/couch_potato/persistence/type_caster.rb +11 -6
  23. data/lib/couch_potato/persistence.rb +5 -3
  24. data/lib/couch_potato/railtie.rb +7 -12
  25. data/lib/couch_potato/validation.rb +8 -0
  26. data/lib/couch_potato/version.rb +2 -2
  27. data/lib/couch_potato/view/base_view_spec.rb +8 -32
  28. data/lib/couch_potato/view/custom_views.rb +4 -3
  29. data/lib/couch_potato/view/flex_view_spec.rb +121 -0
  30. data/lib/couch_potato/view/view_parameters.rb +34 -0
  31. data/lib/couch_potato.rb +37 -16
  32. data/spec/callbacks_spec.rb +45 -19
  33. data/spec/conflict_handling_spec.rb +1 -2
  34. data/spec/property_spec.rb +12 -3
  35. data/spec/railtie_spec.rb +17 -1
  36. data/spec/revisions_spec.rb +25 -0
  37. data/spec/spec_helper.rb +4 -3
  38. data/spec/unit/active_model_compliance_spec.rb +7 -3
  39. data/spec/unit/attributes_spec.rb +54 -1
  40. data/spec/unit/caching_spec.rb +105 -0
  41. data/spec/unit/couch_potato_spec.rb +70 -5
  42. data/spec/unit/create_spec.rb +5 -4
  43. data/spec/unit/database_spec.rb +235 -135
  44. data/spec/unit/dirty_attributes_spec.rb +5 -26
  45. data/spec/unit/flex_view_spec_spec.rb +17 -0
  46. data/spec/unit/model_view_spec_spec.rb +1 -1
  47. data/spec/unit/rspec_stub_db_spec.rb +31 -0
  48. data/spec/unit/validation_spec.rb +42 -2
  49. data/spec/views_spec.rb +214 -103
  50. data/vendor/pouchdb-collate/LICENSE +202 -0
  51. data/vendor/pouchdb-collate/pouchdb-collate.js +430 -0
  52. metadata +47 -33
  53. data/.ruby-version +0 -1
  54. data/.travis.yml +0 -20
  55. data/gemfiles/active_support_4_0 +0 -11
  56. data/gemfiles/active_support_4_1 +0 -11
  57. data/gemfiles/active_support_4_2 +0 -11
  58. data/lib/couch_potato/persistence/deep_dirty_attributes.rb +0 -180
  59. 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.6.5
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Lang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-16 00:00:00.000000000 Z
11
+ date: 2021-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: json
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.6'
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.6'
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.rc3
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.rc3
46
+ version: 2.0.0
41
47
  - !ruby/object:Gem::Dependency
42
- name: activemodel
48
+ name: json
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '4.0'
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: '4.0'
60
+ version: '2.3'
55
61
  - !ruby/object:Gem::Dependency
56
- name: rspec
62
+ name: rake
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: 3.2.0
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: 3.2.0
74
+ version: '12.0'
69
75
  - !ruby/object:Gem::Dependency
70
- name: timecop
76
+ name: rspec
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
- - - ">="
79
+ - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '0'
81
+ version: 3.5.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: '0'
88
+ version: 3.5.0
83
89
  - !ruby/object:Gem::Dependency
84
- name: tzinfo
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: rake
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/active_support_4_0
129
- - gemfiles/active_support_4_1
130
- - gemfiles/active_support_4_2
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,13 +147,13 @@ 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
146
153
  - lib/couch_potato/persistence/json.rb
147
154
  - lib/couch_potato/persistence/magic_timestamps.rb
148
155
  - lib/couch_potato/persistence/properties.rb
156
+ - lib/couch_potato/persistence/revisions.rb
149
157
  - lib/couch_potato/persistence/simple_property.rb
150
158
  - lib/couch_potato/persistence/type_caster.rb
151
159
  - lib/couch_potato/railtie.rb
@@ -154,10 +162,12 @@ files:
154
162
  - lib/couch_potato/view/base_view_spec.rb
155
163
  - lib/couch_potato/view/custom_view_spec.rb
156
164
  - lib/couch_potato/view/custom_views.rb
165
+ - lib/couch_potato/view/flex_view_spec.rb
157
166
  - lib/couch_potato/view/lists.rb
158
167
  - lib/couch_potato/view/model_view_spec.rb
159
168
  - lib/couch_potato/view/properties_view_spec.rb
160
169
  - lib/couch_potato/view/raw_view_spec.rb
170
+ - lib/couch_potato/view/view_parameters.rb
161
171
  - lib/couch_potato/view/view_query.rb
162
172
  - rails/reload_classes.rb
163
173
  - spec/attachments_spec.rb
@@ -172,11 +182,13 @@ files:
172
182
  - spec/rails_spec.rb
173
183
  - spec/railtie_spec.rb
174
184
  - spec/reload_spec.rb
185
+ - spec/revisions_spec.rb
175
186
  - spec/spec.opts
176
187
  - spec/spec_helper.rb
177
188
  - spec/unit/active_model_compliance_spec.rb
178
189
  - spec/unit/attributes_spec.rb
179
190
  - spec/unit/base_view_spec_spec.rb
191
+ - spec/unit/caching_spec.rb
180
192
  - spec/unit/callbacks_spec.rb
181
193
  - spec/unit/couch_potato_spec.rb
182
194
  - spec/unit/create_spec.rb
@@ -184,8 +196,8 @@ files:
184
196
  - spec/unit/custom_views_spec.rb
185
197
  - spec/unit/database_spec.rb
186
198
  - spec/unit/date_spec.rb
187
- - spec/unit/deep_dirty_attributes_spec.rb
188
199
  - spec/unit/dirty_attributes_spec.rb
200
+ - spec/unit/flex_view_spec_spec.rb
189
201
  - spec/unit/forbidden_attributes_protection_spec.rb
190
202
  - spec/unit/initialize_spec.rb
191
203
  - spec/unit/json_spec.rb
@@ -202,6 +214,8 @@ files:
202
214
  - spec/update_spec.rb
203
215
  - spec/view_updates_spec.rb
204
216
  - spec/views_spec.rb
217
+ - vendor/pouchdb-collate/LICENSE
218
+ - vendor/pouchdb-collate/pouchdb-collate.js
205
219
  homepage: http://github.com/langalex/couch_potato
206
220
  licenses: []
207
221
  metadata: {}
@@ -220,8 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
234
  - !ruby/object:Gem::Version
221
235
  version: '0'
222
236
  requirements: []
223
- rubyforge_project:
224
- rubygems_version: 2.4.7
237
+ rubygems_version: 3.1.6
225
238
  signing_key:
226
239
  specification_version: 4
227
240
  summary: Ruby persistence layer for CouchDB
@@ -238,11 +251,13 @@ test_files:
238
251
  - spec/rails_spec.rb
239
252
  - spec/railtie_spec.rb
240
253
  - spec/reload_spec.rb
254
+ - spec/revisions_spec.rb
241
255
  - spec/spec.opts
242
256
  - spec/spec_helper.rb
243
257
  - spec/unit/active_model_compliance_spec.rb
244
258
  - spec/unit/attributes_spec.rb
245
259
  - spec/unit/base_view_spec_spec.rb
260
+ - spec/unit/caching_spec.rb
246
261
  - spec/unit/callbacks_spec.rb
247
262
  - spec/unit/couch_potato_spec.rb
248
263
  - spec/unit/create_spec.rb
@@ -250,8 +265,8 @@ test_files:
250
265
  - spec/unit/custom_views_spec.rb
251
266
  - spec/unit/database_spec.rb
252
267
  - spec/unit/date_spec.rb
253
- - spec/unit/deep_dirty_attributes_spec.rb
254
268
  - spec/unit/dirty_attributes_spec.rb
269
+ - spec/unit/flex_view_spec_spec.rb
255
270
  - spec/unit/forbidden_attributes_protection_spec.rb
256
271
  - spec/unit/initialize_spec.rb
257
272
  - spec/unit/json_spec.rb
@@ -267,4 +282,3 @@ test_files:
267
282
  - spec/update_spec.rb
268
283
  - spec/view_updates_spec.rb
269
284
  - spec/views_spec.rb
270
- has_rdoc:
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.2.2
data/.travis.yml DELETED
@@ -1,20 +0,0 @@
1
- rvm:
2
- - 2.0.0
3
- - 2.1.2
4
- - 2.2.2
5
- - jruby-9.0.1.0
6
- - rbx-2.5.8
7
- services:
8
- - couchdb
9
- gemfile:
10
- - gemfiles/active_support_4_0
11
- - gemfiles/active_support_4_1
12
- - gemfiles/active_support_4_2
13
- before_install:
14
- gem install bundler --version 1.11.2
15
- before_script:
16
- - sudo sh -c 'echo "[native_query_servers]" >> /etc/couchdb/local.ini'
17
- - sudo sh -c 'echo "erlang = {couch_native_process, start_link, []}" >> /etc/couchdb/local.ini'
18
- - sudo /etc/init.d/couchdb restart
19
- - bundle
20
- script: bundle exec rake
@@ -1,11 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activemodel', '~>4.0.0'
4
- gem 'rails', '~>4.0.0'
5
- if RUBY_PLATFORM =~ /java/
6
- gem 'therubyrhino'
7
- else
8
- gem 'therubyracer'
9
- end
10
-
11
- gemspec name: 'couch_potato', path: '..'
@@ -1,11 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activemodel', '~>4.1.0'
4
- gem 'rails', '~>4.1.0'
5
- if RUBY_PLATFORM =~ /java/
6
- gem 'therubyrhino'
7
- else
8
- gem 'therubyracer'
9
- end
10
-
11
- gemspec name: 'couch_potato', path: '..'
@@ -1,11 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activemodel', '~>4.2.0'
4
- gem 'rails', '~>4.2.0'
5
- if RUBY_PLATFORM =~ /java/
6
- gem 'therubyrhino'
7
- else
8
- gem 'therubyracer'
9
- end
10
-
11
- gemspec name: 'couch_potato', path: '..'
@@ -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