couch_potato 1.7.1 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +38 -0
  3. data/.gitignore +3 -0
  4. data/CHANGES.md +169 -131
  5. data/Gemfile +4 -0
  6. data/README.md +55 -75
  7. data/Rakefile +11 -10
  8. data/couch_potato-rspec.gemspec +2 -1
  9. data/couch_potato.gemspec +8 -6
  10. data/gemfiles/active_support_5_0 +1 -5
  11. data/gemfiles/active_support_5_1 +7 -0
  12. data/gemfiles/active_support_5_2 +7 -0
  13. data/gemfiles/active_support_6_0 +7 -0
  14. data/gemfiles/active_support_6_1 +7 -0
  15. data/lib/couch_potato/database.rb +165 -70
  16. data/lib/couch_potato/persistence/dirty_attributes.rb +3 -21
  17. data/lib/couch_potato/persistence/magic_timestamps.rb +3 -3
  18. data/lib/couch_potato/persistence/properties.rb +15 -10
  19. data/lib/couch_potato/persistence/simple_property.rb +0 -4
  20. data/lib/couch_potato/persistence/type_caster.rb +9 -6
  21. data/lib/couch_potato/persistence.rb +0 -1
  22. data/lib/couch_potato/railtie.rb +6 -11
  23. data/lib/couch_potato/validation.rb +8 -0
  24. data/lib/couch_potato/version.rb +1 -1
  25. data/lib/couch_potato/view/base_view_spec.rb +8 -32
  26. data/lib/couch_potato/view/custom_views.rb +4 -3
  27. data/lib/couch_potato/view/flex_view_spec.rb +121 -0
  28. data/lib/couch_potato/view/view_parameters.rb +34 -0
  29. data/lib/couch_potato.rb +32 -9
  30. data/spec/callbacks_spec.rb +45 -19
  31. data/spec/conflict_handling_spec.rb +0 -1
  32. data/spec/property_spec.rb +2 -2
  33. data/spec/railtie_spec.rb +10 -0
  34. data/spec/spec_helper.rb +4 -3
  35. data/spec/unit/active_model_compliance_spec.rb +7 -3
  36. data/spec/unit/attributes_spec.rb +1 -1
  37. data/spec/unit/caching_spec.rb +105 -0
  38. data/spec/unit/couch_potato_spec.rb +70 -5
  39. data/spec/unit/create_spec.rb +5 -4
  40. data/spec/unit/database_spec.rb +235 -135
  41. data/spec/unit/dirty_attributes_spec.rb +5 -26
  42. data/spec/unit/flex_view_spec_spec.rb +17 -0
  43. data/spec/unit/model_view_spec_spec.rb +1 -1
  44. data/spec/unit/rspec_stub_db_spec.rb +31 -0
  45. data/spec/unit/validation_spec.rb +42 -2
  46. data/spec/views_spec.rb +214 -103
  47. data/vendor/pouchdb-collate/LICENSE +202 -0
  48. data/vendor/pouchdb-collate/pouchdb-collate.js +430 -0
  49. metadata +46 -42
  50. data/.ruby-version +0 -1
  51. data/.travis.yml +0 -21
  52. data/gemfiles/active_support_4_0 +0 -11
  53. data/gemfiles/active_support_4_1 +0 -11
  54. data/gemfiles/active_support_4_2 +0 -11
  55. data/lib/couch_potato/persistence/deep_dirty_attributes.rb +0 -180
  56. data/spec/unit/deep_dirty_attributes_spec.rb +0 -434
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couch_potato
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.9.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: 2017-07-12 00:00:00.000000000 Z
11
+ date: 2021-12-19 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.0'
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.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: couchrest
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -39,55 +45,49 @@ dependencies:
39
45
  - !ruby/object:Gem::Version
40
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
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '4.0'
48
- - - "<"
51
+ - - "~>"
49
52
  - !ruby/object:Gem::Version
50
- version: '6.0'
53
+ version: '2.3'
51
54
  type: :runtime
52
55
  prerelease: false
53
56
  version_requirements: !ruby/object:Gem::Requirement
54
57
  requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: '4.0'
58
- - - "<"
58
+ - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '6.0'
60
+ version: '2.3'
61
61
  - !ruby/object:Gem::Dependency
62
- name: rspec
62
+ name: rake
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: 3.2.0
67
+ version: '12.0'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: 3.2.0
74
+ version: '12.0'
75
75
  - !ruby/object:Gem::Dependency
76
- name: timecop
76
+ name: rspec
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - ">="
79
+ - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '0'
81
+ version: 3.5.0
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - ">="
86
+ - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '0'
88
+ version: 3.5.0
89
89
  - !ruby/object:Gem::Dependency
90
- name: tzinfo
90
+ name: timecop
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - ">="
@@ -101,28 +101,27 @@ dependencies:
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  - !ruby/object:Gem::Dependency
104
- name: rake
104
+ name: tzinfo
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - "<"
107
+ - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: '11.0'
109
+ version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - "<"
114
+ - - ">="
115
115
  - !ruby/object:Gem::Version
116
- version: '11.0'
116
+ version: '0'
117
117
  description: Ruby persistence layer for CouchDB
118
118
  email: alex@upstre.am
119
119
  executables: []
120
120
  extensions: []
121
121
  extra_rdoc_files: []
122
122
  files:
123
+ - ".github/workflows/ruby.yml"
123
124
  - ".gitignore"
124
- - ".ruby-version"
125
- - ".travis.yml"
126
125
  - CHANGES.md
127
126
  - CREDITS
128
127
  - Gemfile
@@ -131,10 +130,11 @@ files:
131
130
  - Rakefile
132
131
  - couch_potato-rspec.gemspec
133
132
  - couch_potato.gemspec
134
- - gemfiles/active_support_4_0
135
- - gemfiles/active_support_4_1
136
- - gemfiles/active_support_4_2
137
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
138
  - init.rb
139
139
  - lib/core_ext/date.rb
140
140
  - lib/core_ext/time.rb
@@ -146,7 +146,6 @@ files:
146
146
  - lib/couch_potato/persistence/active_model_compliance.rb
147
147
  - lib/couch_potato/persistence/attachments.rb
148
148
  - lib/couch_potato/persistence/callbacks.rb
149
- - lib/couch_potato/persistence/deep_dirty_attributes.rb
150
149
  - lib/couch_potato/persistence/deep_tracked_property.rb
151
150
  - lib/couch_potato/persistence/dirty_attributes.rb
152
151
  - lib/couch_potato/persistence/ghost_attributes.rb
@@ -162,10 +161,12 @@ files:
162
161
  - lib/couch_potato/view/base_view_spec.rb
163
162
  - lib/couch_potato/view/custom_view_spec.rb
164
163
  - lib/couch_potato/view/custom_views.rb
164
+ - lib/couch_potato/view/flex_view_spec.rb
165
165
  - lib/couch_potato/view/lists.rb
166
166
  - lib/couch_potato/view/model_view_spec.rb
167
167
  - lib/couch_potato/view/properties_view_spec.rb
168
168
  - lib/couch_potato/view/raw_view_spec.rb
169
+ - lib/couch_potato/view/view_parameters.rb
169
170
  - lib/couch_potato/view/view_query.rb
170
171
  - rails/reload_classes.rb
171
172
  - spec/attachments_spec.rb
@@ -186,6 +187,7 @@ files:
186
187
  - spec/unit/active_model_compliance_spec.rb
187
188
  - spec/unit/attributes_spec.rb
188
189
  - spec/unit/base_view_spec_spec.rb
190
+ - spec/unit/caching_spec.rb
189
191
  - spec/unit/callbacks_spec.rb
190
192
  - spec/unit/couch_potato_spec.rb
191
193
  - spec/unit/create_spec.rb
@@ -193,8 +195,8 @@ files:
193
195
  - spec/unit/custom_views_spec.rb
194
196
  - spec/unit/database_spec.rb
195
197
  - spec/unit/date_spec.rb
196
- - spec/unit/deep_dirty_attributes_spec.rb
197
198
  - spec/unit/dirty_attributes_spec.rb
199
+ - spec/unit/flex_view_spec_spec.rb
198
200
  - spec/unit/forbidden_attributes_protection_spec.rb
199
201
  - spec/unit/initialize_spec.rb
200
202
  - spec/unit/json_spec.rb
@@ -211,6 +213,8 @@ files:
211
213
  - spec/update_spec.rb
212
214
  - spec/view_updates_spec.rb
213
215
  - spec/views_spec.rb
216
+ - vendor/pouchdb-collate/LICENSE
217
+ - vendor/pouchdb-collate/pouchdb-collate.js
214
218
  homepage: http://github.com/langalex/couch_potato
215
219
  licenses: []
216
220
  metadata: {}
@@ -229,8 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
233
  - !ruby/object:Gem::Version
230
234
  version: '0'
231
235
  requirements: []
232
- rubyforge_project:
233
- rubygems_version: 2.4.5
236
+ rubygems_version: 3.1.6
234
237
  signing_key:
235
238
  specification_version: 4
236
239
  summary: Ruby persistence layer for CouchDB
@@ -253,6 +256,7 @@ test_files:
253
256
  - spec/unit/active_model_compliance_spec.rb
254
257
  - spec/unit/attributes_spec.rb
255
258
  - spec/unit/base_view_spec_spec.rb
259
+ - spec/unit/caching_spec.rb
256
260
  - spec/unit/callbacks_spec.rb
257
261
  - spec/unit/couch_potato_spec.rb
258
262
  - spec/unit/create_spec.rb
@@ -260,8 +264,8 @@ test_files:
260
264
  - spec/unit/custom_views_spec.rb
261
265
  - spec/unit/database_spec.rb
262
266
  - spec/unit/date_spec.rb
263
- - spec/unit/deep_dirty_attributes_spec.rb
264
267
  - spec/unit/dirty_attributes_spec.rb
268
+ - spec/unit/flex_view_spec_spec.rb
265
269
  - spec/unit/forbidden_attributes_protection_spec.rb
266
270
  - spec/unit/initialize_spec.rb
267
271
  - spec/unit/json_spec.rb
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.2.2
data/.travis.yml DELETED
@@ -1,21 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - "2.2"
4
- - "2.3.0"
5
- - "jruby-9.0.5.0"
6
- - "rbx-3.9"
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
- - gemfiles/active_support_5_0
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
@@ -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