superstore 2.4.3 → 3.0.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.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +40 -0
- data/.gitignore +1 -0
- data/.simplecov +3 -0
- data/Gemfile +2 -3
- data/LICENSE +1 -1
- data/MIT-LICENSE +1 -1
- data/README.md +4 -34
- data/lib/superstore/adapters/abstract_adapter.rb +1 -27
- data/lib/superstore/adapters/jsonb_adapter.rb +4 -132
- data/lib/superstore/associations/association.rb +6 -0
- data/lib/superstore/associations/association_scope.rb +20 -0
- data/lib/superstore/associations/belongs_to.rb +3 -1
- data/lib/superstore/associations/builder/association.rb +1 -1
- data/lib/superstore/associations/has_many.rb +15 -2
- data/lib/superstore/associations/reflection.rb +8 -2
- data/lib/superstore/associations.rb +9 -4
- data/lib/superstore/attribute_assignment.rb +7 -0
- data/lib/superstore/attribute_methods/primary_key.rb +20 -11
- data/lib/superstore/attribute_methods.rb +1 -109
- data/lib/superstore/attributes.rb +13 -0
- data/lib/superstore/base.rb +6 -34
- data/lib/superstore/core.rb +7 -65
- data/lib/superstore/model_schema.rb +35 -0
- data/lib/superstore/persistence.rb +26 -115
- data/lib/superstore/railtie.rb +3 -11
- data/lib/superstore/relation/scrolling.rb +48 -0
- data/lib/superstore/types/array_type.rb +3 -7
- data/lib/superstore/types/base.rb +9 -0
- data/lib/superstore/types/boolean_type.rb +7 -12
- data/lib/superstore/types/date_range_type.rb +7 -0
- data/lib/superstore/types/date_type.rb +7 -10
- data/lib/superstore/types/float_type.rb +3 -11
- data/lib/superstore/types/geo_point_type.rb +30 -0
- data/lib/superstore/types/integer_range_type.rb +15 -0
- data/lib/superstore/types/integer_type.rb +8 -14
- data/lib/superstore/types/json_type.rb +1 -1
- data/lib/superstore/types/range_type.rb +58 -0
- data/lib/superstore/types/string_type.rb +4 -4
- data/lib/superstore/types/time_type.rb +10 -8
- data/lib/superstore/types.rb +11 -9
- data/lib/superstore.rb +17 -19
- data/superstore.gemspec +8 -10
- data/test/support/jsonb.rb +3 -1
- data/test/support/models.rb +10 -4
- data/test/test_helper.rb +7 -3
- data/test/unit/adapters/adapter_test.rb +1 -3
- data/test/unit/associations/belongs_to_test.rb +1 -1
- data/test/unit/associations/has_many_test.rb +10 -2
- data/test/unit/attribute_methods/dirty_test.rb +8 -19
- data/test/unit/attribute_methods/primary_key_test.rb +1 -1
- data/test/unit/attribute_methods_test.rb +10 -22
- data/test/unit/{attribute_methods/typecasting_test.rb → attributes_test.rb} +13 -39
- data/test/unit/base_test.rb +4 -0
- data/test/unit/caching_test.rb +1 -1
- data/test/unit/callbacks_test.rb +4 -4
- data/test/unit/core_test.rb +15 -20
- data/test/unit/persistence_test.rb +36 -44
- data/test/unit/{scope/batches_test.rb → relation/scrolling_test.rb} +9 -5
- data/test/unit/serialization_test.rb +10 -2
- data/test/unit/{timestamps_test.rb → timestamp_test.rb} +5 -5
- data/test/unit/types/array_type_test.rb +3 -18
- data/test/unit/types/boolean_type_test.rb +7 -21
- data/test/unit/types/date_range_type_test.rb +29 -0
- data/test/unit/types/date_type_test.rb +15 -6
- data/test/unit/types/float_type_test.rb +4 -19
- data/test/unit/types/geo_point_type_test.rb +28 -0
- data/test/unit/types/integer_range_type_test.rb +28 -0
- data/test/unit/types/integer_type_test.rb +7 -16
- data/test/unit/types/string_type_test.rb +9 -13
- data/test/unit/types/time_type_test.rb +17 -11
- data/test/unit/validations_test.rb +2 -2
- metadata +39 -53
- data/.travis.yml +0 -13
- data/Gemfile-rails4.2 +0 -11
- data/lib/superstore/attribute_methods/definition.rb +0 -17
- data/lib/superstore/attribute_methods/dirty.rb +0 -52
- data/lib/superstore/attribute_methods/typecasting.rb +0 -53
- data/lib/superstore/caching.rb +0 -13
- data/lib/superstore/callbacks.rb +0 -29
- data/lib/superstore/connection.rb +0 -24
- data/lib/superstore/errors.rb +0 -10
- data/lib/superstore/inspect.rb +0 -25
- data/lib/superstore/model.rb +0 -38
- data/lib/superstore/schema.rb +0 -20
- data/lib/superstore/scope/batches.rb +0 -27
- data/lib/superstore/scope/finder_methods.rb +0 -51
- data/lib/superstore/scope/query_methods.rb +0 -52
- data/lib/superstore/scope.rb +0 -73
- data/lib/superstore/scoping.rb +0 -30
- data/lib/superstore/timestamps.rb +0 -19
- data/lib/superstore/type.rb +0 -16
- data/lib/superstore/types/base_type.rb +0 -23
- data/lib/superstore/validations.rb +0 -44
- data/test/unit/attribute_methods/definition_test.rb +0 -16
- data/test/unit/inspect_test.rb +0 -26
- data/test/unit/schema_test.rb +0 -15
- data/test/unit/scope/finder_methods_test.rb +0 -62
- data/test/unit/scope/query_methods_test.rb +0 -36
- data/test/unit/scoping_test.rb +0 -7
- data/test/unit/types/base_type_test.rb +0 -11
@@ -7,7 +7,7 @@ class Superstore::ValidationsTest < Superstore::TestCase
|
|
7
7
|
|
8
8
|
Issue.create!(description: 'lol')
|
9
9
|
|
10
|
-
assert_raise(
|
10
|
+
assert_raise(ActiveRecord::RecordInvalid) { Issue.create!(description: '') }
|
11
11
|
ensure
|
12
12
|
Issue.reset_callbacks(:validate)
|
13
13
|
end
|
@@ -19,7 +19,7 @@ class Superstore::ValidationsTest < Superstore::TestCase
|
|
19
19
|
|
20
20
|
Issue.new(description: 'lol').save!
|
21
21
|
|
22
|
-
assert_raise(
|
22
|
+
assert_raise(ActiveRecord::RecordInvalid) { Issue.new(description: '').save! }
|
23
23
|
ensure
|
24
24
|
Issue.reset_callbacks(:validate)
|
25
25
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: superstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Koziarski
|
8
|
-
-
|
9
|
-
autorequire:
|
8
|
+
- Data Axle
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-02-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -17,36 +17,36 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '6.1'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
27
|
+
version: '6.1'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
29
|
+
name: activerecord
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '6.1'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
41
|
+
version: '6.1'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
43
|
+
name: bundler
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
|
-
type: :
|
49
|
+
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
@@ -54,19 +54,19 @@ dependencies:
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
57
|
+
name: rails
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- - "
|
60
|
+
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '6.1'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- - "
|
67
|
+
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '6.1'
|
70
70
|
description: ActiveModel-based JSONB document store
|
71
71
|
email: developer@matthewhiggins.com
|
72
72
|
executables: []
|
@@ -74,11 +74,11 @@ extensions: []
|
|
74
74
|
extra_rdoc_files:
|
75
75
|
- README.md
|
76
76
|
files:
|
77
|
+
- ".github/workflows/ruby.yml"
|
77
78
|
- ".gitignore"
|
78
|
-
- ".
|
79
|
+
- ".simplecov"
|
79
80
|
- CHANGELOG.md
|
80
81
|
- Gemfile
|
81
|
-
- Gemfile-rails4.2
|
82
82
|
- LICENSE
|
83
83
|
- MIT-LICENSE
|
84
84
|
- README.md
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- lib/superstore/adapters/jsonb_adapter.rb
|
89
89
|
- lib/superstore/associations.rb
|
90
90
|
- lib/superstore/associations/association.rb
|
91
|
+
- lib/superstore/associations/association_scope.rb
|
91
92
|
- lib/superstore/associations/belongs_to.rb
|
92
93
|
- lib/superstore/associations/builder/association.rb
|
93
94
|
- lib/superstore/associations/builder/belongs_to.rb
|
@@ -96,41 +97,31 @@ files:
|
|
96
97
|
- lib/superstore/associations/has_many.rb
|
97
98
|
- lib/superstore/associations/has_one.rb
|
98
99
|
- lib/superstore/associations/reflection.rb
|
100
|
+
- lib/superstore/attribute_assignment.rb
|
99
101
|
- lib/superstore/attribute_methods.rb
|
100
|
-
- lib/superstore/attribute_methods/definition.rb
|
101
|
-
- lib/superstore/attribute_methods/dirty.rb
|
102
102
|
- lib/superstore/attribute_methods/primary_key.rb
|
103
|
-
- lib/superstore/
|
103
|
+
- lib/superstore/attributes.rb
|
104
104
|
- lib/superstore/base.rb
|
105
|
-
- lib/superstore/caching.rb
|
106
|
-
- lib/superstore/callbacks.rb
|
107
|
-
- lib/superstore/connection.rb
|
108
105
|
- lib/superstore/core.rb
|
109
|
-
- lib/superstore/errors.rb
|
110
106
|
- lib/superstore/identity.rb
|
111
|
-
- lib/superstore/
|
112
|
-
- lib/superstore/model.rb
|
107
|
+
- lib/superstore/model_schema.rb
|
113
108
|
- lib/superstore/persistence.rb
|
114
109
|
- lib/superstore/railtie.rb
|
115
|
-
- lib/superstore/
|
116
|
-
- lib/superstore/scope.rb
|
117
|
-
- lib/superstore/scope/batches.rb
|
118
|
-
- lib/superstore/scope/finder_methods.rb
|
119
|
-
- lib/superstore/scope/query_methods.rb
|
120
|
-
- lib/superstore/scoping.rb
|
121
|
-
- lib/superstore/timestamps.rb
|
122
|
-
- lib/superstore/type.rb
|
110
|
+
- lib/superstore/relation/scrolling.rb
|
123
111
|
- lib/superstore/types.rb
|
124
112
|
- lib/superstore/types/array_type.rb
|
125
|
-
- lib/superstore/types/
|
113
|
+
- lib/superstore/types/base.rb
|
126
114
|
- lib/superstore/types/boolean_type.rb
|
115
|
+
- lib/superstore/types/date_range_type.rb
|
127
116
|
- lib/superstore/types/date_type.rb
|
128
117
|
- lib/superstore/types/float_type.rb
|
118
|
+
- lib/superstore/types/geo_point_type.rb
|
119
|
+
- lib/superstore/types/integer_range_type.rb
|
129
120
|
- lib/superstore/types/integer_type.rb
|
130
121
|
- lib/superstore/types/json_type.rb
|
122
|
+
- lib/superstore/types/range_type.rb
|
131
123
|
- lib/superstore/types/string_type.rb
|
132
124
|
- lib/superstore/types/time_type.rb
|
133
|
-
- lib/superstore/validations.rb
|
134
125
|
- superstore.gemspec
|
135
126
|
- test/support/jsonb.rb
|
136
127
|
- test/support/models.rb
|
@@ -142,31 +133,27 @@ files:
|
|
142
133
|
- test/unit/associations/has_many_test.rb
|
143
134
|
- test/unit/associations/has_one_test.rb
|
144
135
|
- test/unit/associations/reflection_test.rb
|
145
|
-
- test/unit/attribute_methods/definition_test.rb
|
146
136
|
- test/unit/attribute_methods/dirty_test.rb
|
147
137
|
- test/unit/attribute_methods/primary_key_test.rb
|
148
|
-
- test/unit/attribute_methods/typecasting_test.rb
|
149
138
|
- test/unit/attribute_methods_test.rb
|
139
|
+
- test/unit/attributes_test.rb
|
150
140
|
- test/unit/base_test.rb
|
151
141
|
- test/unit/caching_test.rb
|
152
142
|
- test/unit/callbacks_test.rb
|
153
143
|
- test/unit/connection_test.rb
|
154
144
|
- test/unit/core_test.rb
|
155
145
|
- test/unit/identity_test.rb
|
156
|
-
- test/unit/inspect_test.rb
|
157
146
|
- test/unit/persistence_test.rb
|
158
|
-
- test/unit/
|
159
|
-
- test/unit/scope/batches_test.rb
|
160
|
-
- test/unit/scope/finder_methods_test.rb
|
161
|
-
- test/unit/scope/query_methods_test.rb
|
162
|
-
- test/unit/scoping_test.rb
|
147
|
+
- test/unit/relation/scrolling_test.rb
|
163
148
|
- test/unit/serialization_test.rb
|
164
|
-
- test/unit/
|
149
|
+
- test/unit/timestamp_test.rb
|
165
150
|
- test/unit/types/array_type_test.rb
|
166
|
-
- test/unit/types/base_type_test.rb
|
167
151
|
- test/unit/types/boolean_type_test.rb
|
152
|
+
- test/unit/types/date_range_type_test.rb
|
168
153
|
- test/unit/types/date_type_test.rb
|
169
154
|
- test/unit/types/float_type_test.rb
|
155
|
+
- test/unit/types/geo_point_type_test.rb
|
156
|
+
- test/unit/types/integer_range_type_test.rb
|
170
157
|
- test/unit/types/integer_type_test.rb
|
171
158
|
- test/unit/types/json_type_test.rb
|
172
159
|
- test/unit/types/string_type_test.rb
|
@@ -177,7 +164,7 @@ licenses:
|
|
177
164
|
- ISC
|
178
165
|
- MIT
|
179
166
|
metadata: {}
|
180
|
-
post_install_message:
|
167
|
+
post_install_message:
|
181
168
|
rdoc_options: []
|
182
169
|
require_paths:
|
183
170
|
- lib
|
@@ -185,16 +172,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
185
172
|
requirements:
|
186
173
|
- - ">="
|
187
174
|
- !ruby/object:Gem::Version
|
188
|
-
version:
|
175
|
+
version: 3.0.0
|
189
176
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
177
|
requirements:
|
191
178
|
- - ">="
|
192
179
|
- !ruby/object:Gem::Version
|
193
|
-
version:
|
180
|
+
version: 3.2.0
|
194
181
|
requirements: []
|
195
|
-
|
196
|
-
|
197
|
-
signing_key:
|
182
|
+
rubygems_version: 3.1.6
|
183
|
+
signing_key:
|
198
184
|
specification_version: 4
|
199
185
|
summary: ActiveModel for JSONB documents
|
200
186
|
test_files: []
|
data/.travis.yml
DELETED
data/Gemfile-rails4.2
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module Superstore
|
2
|
-
module AttributeMethods
|
3
|
-
class Definition
|
4
|
-
attr_reader :name, :type
|
5
|
-
def initialize(model, name, type_class, options)
|
6
|
-
@name = name.to_s
|
7
|
-
@type = type_class.new(model, options)
|
8
|
-
end
|
9
|
-
|
10
|
-
def instantiate(value)
|
11
|
-
return if value.nil?
|
12
|
-
|
13
|
-
value.kind_of?(String) ? type.decode(value) : type.typecast(value)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module Superstore
|
2
|
-
module AttributeMethods
|
3
|
-
module Dirty
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
include ActiveModel::Dirty
|
6
|
-
|
7
|
-
# Attempts to +save+ the record and clears changed attributes if successful.
|
8
|
-
def save(*) #:nodoc:
|
9
|
-
if status = super
|
10
|
-
@previously_changed = changes
|
11
|
-
@changed_attributes = {}
|
12
|
-
end
|
13
|
-
status
|
14
|
-
end
|
15
|
-
|
16
|
-
# <tt>reload</tt> the record and clears changed attributes.
|
17
|
-
def reload
|
18
|
-
super.tap do
|
19
|
-
@previously_changed.try :clear
|
20
|
-
@changed_attributes.try :clear
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def unapplied_changes
|
25
|
-
result = {}
|
26
|
-
changed_attributes.each_key { |attr| result[attr] = read_attribute(attr) }
|
27
|
-
result
|
28
|
-
end
|
29
|
-
|
30
|
-
def old_attribute_value(attr)
|
31
|
-
if attribute_changed?(attr)
|
32
|
-
changed_attributes[attr]
|
33
|
-
else
|
34
|
-
read_attribute attr
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def write_attribute(name, value)
|
39
|
-
name = name.to_s
|
40
|
-
old = old_attribute_value(name)
|
41
|
-
|
42
|
-
super
|
43
|
-
|
44
|
-
if old == read_attribute(name)
|
45
|
-
changed_attributes.delete(name)
|
46
|
-
else
|
47
|
-
changed_attributes[name] = old
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module Superstore
|
2
|
-
module AttributeMethods
|
3
|
-
module Typecasting
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
included do
|
7
|
-
class_attribute :attribute_definitions
|
8
|
-
self.attribute_definitions = {}
|
9
|
-
|
10
|
-
%w(array boolean date float integer json string time).each do |type|
|
11
|
-
instance_eval <<-EOV, __FILE__, __LINE__ + 1
|
12
|
-
def #{type}(*args)
|
13
|
-
options = args.extract_options!
|
14
|
-
args.each do |name|
|
15
|
-
attribute(name, options.merge(:type => :#{type}))
|
16
|
-
end
|
17
|
-
end
|
18
|
-
EOV
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
module ClassMethods
|
23
|
-
def inherited(child)
|
24
|
-
super
|
25
|
-
child.attribute_definitions = attribute_definitions.dup
|
26
|
-
end
|
27
|
-
|
28
|
-
#
|
29
|
-
# attribute :name, type: :string
|
30
|
-
# attribute :ammo, type: :integer
|
31
|
-
#
|
32
|
-
def attribute(name, options)
|
33
|
-
type_name = options[:type]
|
34
|
-
type_class = Superstore::Type.get_type_class(type_name) || (raise "Unknown type #{type_name}")
|
35
|
-
|
36
|
-
attribute_definitions[name.to_s] = AttributeMethods::Definition.new(self, name, type_class, options)
|
37
|
-
end
|
38
|
-
|
39
|
-
def typecast_attribute(name, value)
|
40
|
-
if attribute_definition = attribute_definitions[name.to_s]
|
41
|
-
attribute_definition.instantiate(value)
|
42
|
-
else
|
43
|
-
raise NoMethodError, "Unknown attribute #{name.inspect}"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def type_for(attribute)
|
48
|
-
attribute_definitions[attribute.to_s].type
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
data/lib/superstore/caching.rb
DELETED
data/lib/superstore/callbacks.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module Superstore
|
2
|
-
module Callbacks
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
extend ActiveModel::Callbacks
|
7
|
-
include ActiveModel::Validations::Callbacks
|
8
|
-
|
9
|
-
define_model_callbacks :save, :create, :update, :destroy
|
10
|
-
end
|
11
|
-
|
12
|
-
def destroy #:nodoc:
|
13
|
-
run_callbacks(:destroy) { super }
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
def write(*args) #:nodoc:
|
18
|
-
run_callbacks(:save) { super }
|
19
|
-
end
|
20
|
-
|
21
|
-
def create_self #:nodoc:
|
22
|
-
run_callbacks(:create) { super }
|
23
|
-
end
|
24
|
-
|
25
|
-
def update_self(*) #:nodoc:
|
26
|
-
run_callbacks(:update) { super }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Superstore
|
2
|
-
module Connection
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
module ClassMethods
|
6
|
-
def adapter
|
7
|
-
@adapter ||= adapter_class.new(config)
|
8
|
-
end
|
9
|
-
|
10
|
-
def adapter_class
|
11
|
-
case config[:adapter]
|
12
|
-
when nil, 'jsonb'
|
13
|
-
Superstore::Adapters::JsonbAdapter
|
14
|
-
else
|
15
|
-
raise "Unknown adapter #{config[:adapter]}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def connection
|
20
|
-
adapter.connection
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/superstore/errors.rb
DELETED
data/lib/superstore/inspect.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
module Superstore
|
2
|
-
module Inspect
|
3
|
-
def inspect
|
4
|
-
inspection = ["#{self.class.primary_key}: #{id.inspect}"]
|
5
|
-
|
6
|
-
@attributes.each do |attribute, value|
|
7
|
-
if value.present?
|
8
|
-
inspection << "#{attribute}: #{attribute_for_inspect(value)}"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
"#<#{self.class} #{inspection * ', '}>"
|
13
|
-
end
|
14
|
-
|
15
|
-
def attribute_for_inspect(value)
|
16
|
-
if value.is_a?(String) && value.length > 50
|
17
|
-
"#{value[0..50]}...".inspect
|
18
|
-
elsif value.is_a?(Date) || value.is_a?(Time)
|
19
|
-
%("#{value.to_s(:db)}")
|
20
|
-
else
|
21
|
-
value.inspect
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/lib/superstore/model.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
module Superstore
|
2
|
-
module Model
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
included do
|
6
|
-
class_attribute :symbolized_config
|
7
|
-
self.symbolized_config = {}
|
8
|
-
end
|
9
|
-
|
10
|
-
module ClassMethods
|
11
|
-
def base_class
|
12
|
-
class_of_active_record_descendant(self)
|
13
|
-
end
|
14
|
-
|
15
|
-
def config=(config)
|
16
|
-
self.symbolized_config = config.deep_symbolize_keys
|
17
|
-
end
|
18
|
-
|
19
|
-
def config
|
20
|
-
symbolized_config
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
# Returns the class descending directly from ActiveRecord::Base or an
|
26
|
-
# abstract class, if any, in the inheritance hierarchy.
|
27
|
-
def class_of_active_record_descendant(klass)
|
28
|
-
if klass == Base || klass.superclass == Base
|
29
|
-
klass
|
30
|
-
elsif klass.superclass.nil?
|
31
|
-
raise "#{name} doesn't belong in a hierarchy descending from Superstore"
|
32
|
-
else
|
33
|
-
class_of_active_record_descendant(klass.superclass)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/lib/superstore/schema.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module Superstore
|
2
|
-
class Schema
|
3
|
-
class << self
|
4
|
-
def create_table(table_name, options = {})
|
5
|
-
adapter.create_table table_name, options
|
6
|
-
end
|
7
|
-
|
8
|
-
def drop_table(table_name)
|
9
|
-
adapter.drop_table table_name
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def adapter
|
15
|
-
Superstore::Base.adapter
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Superstore
|
2
|
-
module Batches
|
3
|
-
def find_each(options = {})
|
4
|
-
batch_size = options[:batch_size] || 1000
|
5
|
-
|
6
|
-
klass.adapter.scroll(self, batch_size) do |key, attributes|
|
7
|
-
yield klass.instantiate(key, attributes)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def find_in_batches(options = {})
|
12
|
-
batch_size = options[:batch_size] || 1000
|
13
|
-
batch = []
|
14
|
-
|
15
|
-
find_each(options) do |record|
|
16
|
-
batch << record
|
17
|
-
|
18
|
-
if batch.size == batch_size
|
19
|
-
yield batch
|
20
|
-
batch = []
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
yield(batch) if batch.any?
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
module Superstore
|
2
|
-
module FinderMethods
|
3
|
-
def find(ids)
|
4
|
-
if ids.is_a?(Array)
|
5
|
-
find_some(ids)
|
6
|
-
else
|
7
|
-
find_one(ids)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def find_by_id(ids)
|
12
|
-
find(ids)
|
13
|
-
rescue Superstore::RecordNotFound
|
14
|
-
nil
|
15
|
-
end
|
16
|
-
|
17
|
-
def all
|
18
|
-
clone
|
19
|
-
end
|
20
|
-
|
21
|
-
def first
|
22
|
-
limit(1).to_a.first
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_ids
|
26
|
-
klass.adapter.to_ids self
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def find_one(id)
|
32
|
-
if id.blank?
|
33
|
-
raise Superstore::RecordNotFound, "Couldn't find #{self.name} with key #{id.inspect}"
|
34
|
-
elsif record = where_ids(id).first
|
35
|
-
record
|
36
|
-
else
|
37
|
-
raise Superstore::RecordNotFound
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def find_some(ids)
|
42
|
-
ids = ids.flatten
|
43
|
-
ids.compact!
|
44
|
-
return [] if ids.empty?
|
45
|
-
|
46
|
-
ids = ids.map(&:to_s).uniq
|
47
|
-
|
48
|
-
where_ids(ids).to_a
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module Superstore
|
2
|
-
module QueryMethods
|
3
|
-
def select!(*values)
|
4
|
-
self.select_values += values.flatten
|
5
|
-
self
|
6
|
-
end
|
7
|
-
|
8
|
-
def select(*values, &block)
|
9
|
-
if block_given?
|
10
|
-
to_a.select(&block)
|
11
|
-
else
|
12
|
-
clone.select!(*values)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def where!(*values)
|
17
|
-
self.where_values += values.flatten
|
18
|
-
self
|
19
|
-
end
|
20
|
-
|
21
|
-
def where(*values)
|
22
|
-
clone.where! values
|
23
|
-
end
|
24
|
-
|
25
|
-
def where_ids!(*ids)
|
26
|
-
self.id_values += ids.flatten
|
27
|
-
self
|
28
|
-
end
|
29
|
-
|
30
|
-
def where_ids(*ids)
|
31
|
-
clone.where_ids! ids
|
32
|
-
end
|
33
|
-
|
34
|
-
def limit!(value)
|
35
|
-
self.limit_value = value
|
36
|
-
self
|
37
|
-
end
|
38
|
-
|
39
|
-
def limit(value)
|
40
|
-
clone.limit! value
|
41
|
-
end
|
42
|
-
|
43
|
-
def order!(*values)
|
44
|
-
self.order_values = values.flatten
|
45
|
-
self
|
46
|
-
end
|
47
|
-
|
48
|
-
def order(*values)
|
49
|
-
clone.order! values
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|