quo 0.6.0 → 1.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.standard.yml +4 -1
  3. data/Appraisals +11 -0
  4. data/CHANGELOG.md +78 -0
  5. data/Gemfile +6 -4
  6. data/LICENSE.txt +1 -1
  7. data/README.md +37 -36
  8. data/Steepfile +0 -2
  9. data/gemfiles/rails_7.0.gemfile +15 -0
  10. data/gemfiles/rails_7.1.gemfile +15 -0
  11. data/gemfiles/rails_7.2.gemfile +15 -0
  12. data/lib/quo/collection_backed_query.rb +87 -0
  13. data/lib/quo/collection_results.rb +44 -0
  14. data/lib/quo/composed_query.rb +168 -0
  15. data/lib/quo/engine.rb +11 -0
  16. data/lib/quo/minitest/helpers.rb +41 -0
  17. data/lib/quo/preloadable.rb +46 -0
  18. data/lib/quo/query.rb +97 -214
  19. data/lib/quo/relation_backed_query.rb +177 -0
  20. data/lib/quo/relation_results.rb +58 -0
  21. data/lib/quo/results.rb +48 -44
  22. data/lib/quo/rspec/helpers.rb +31 -9
  23. data/lib/quo/testing/collection_backed_fake.rb +29 -0
  24. data/lib/quo/testing/relation_backed_fake.rb +52 -0
  25. data/lib/quo/version.rb +3 -1
  26. data/lib/quo.rb +22 -30
  27. data/rbs_collection.yaml +0 -2
  28. data/sig/generated/quo/collection_backed_query.rbs +39 -0
  29. data/sig/generated/quo/collection_results.rbs +30 -0
  30. data/sig/generated/quo/composed_query.rbs +83 -0
  31. data/sig/generated/quo/engine.rbs +6 -0
  32. data/sig/generated/quo/preloadable.rbs +29 -0
  33. data/sig/generated/quo/query.rbs +98 -0
  34. data/sig/generated/quo/relation_backed_query.rbs +90 -0
  35. data/sig/generated/quo/relation_results.rbs +38 -0
  36. data/sig/generated/quo/results.rbs +39 -0
  37. data/sig/generated/quo/version.rbs +5 -0
  38. data/sig/generated/quo.rbs +9 -0
  39. metadata +67 -30
  40. data/lib/quo/eager_query.rb +0 -51
  41. data/lib/quo/loaded_query.rb +0 -18
  42. data/lib/quo/merged_query.rb +0 -36
  43. data/lib/quo/query_composer.rb +0 -78
  44. data/lib/quo/railtie.rb +0 -7
  45. data/lib/quo/utilities/callstack.rb +0 -21
  46. data/lib/quo/utilities/compose.rb +0 -18
  47. data/lib/quo/utilities/sanitize.rb +0 -19
  48. data/lib/quo/utilities/wrap.rb +0 -23
  49. data/lib/quo/wrapped_query.rb +0 -18
  50. data/sig/quo/eager_query.rbs +0 -15
  51. data/sig/quo/loaded_query.rbs +0 -7
  52. data/sig/quo/merged_query.rbs +0 -19
  53. data/sig/quo/query.rbs +0 -83
  54. data/sig/quo/query_composer.rbs +0 -32
  55. data/sig/quo/results.rbs +0 -22
  56. data/sig/quo/utilities/callstack.rbs +0 -7
  57. data/sig/quo/utilities/compose.rbs +0 -8
  58. data/sig/quo/utilities/sanitize.rbs +0 -9
  59. data/sig/quo/utilities/wrap.rbs +0 -11
  60. data/sig/quo/wrapped_query.rbs +0 -11
  61. data/sig/quo.rbs +0 -41
@@ -0,0 +1,83 @@
1
+ # Generated from lib/quo/composed_query.rb with RBS::Inline
2
+
3
+ module Quo
4
+ module ComposedQuery
5
+ # Combine two Query classes into a new composed query class
6
+ # Combine two query-like or composeable entities:
7
+ # These can be Quo::Query, Quo::ComposedQuery, Quo::CollectionBackedQuery and ActiveRecord::Relations.
8
+ # See the `README.md` docs for more details.
9
+ # @rbs chosen_superclass: singleton(Quo::RelationBackedQuery | Quo::CollectionBackedQuery)
10
+ # @rbs left_query_class: singleton(Quo::Query | ::ActiveRecord::Relation)
11
+ # @rbs right_query_class: singleton(Quo::Query | ::ActiveRecord::Relation)
12
+ # @rbs joins: untyped
13
+ # @rbs return: singleton(Quo::ComposedQuery)
14
+ def composer: (untyped chosen_superclass, untyped left_query_class, untyped right_query_class, ?joins: untyped) -> singleton(Quo::ComposedQuery)
15
+
16
+ include Quo::ComposedQuery
17
+
18
+ attr_reader _composing_joins: untyped
19
+
20
+ attr_reader _left_query: untyped
21
+
22
+ attr_reader _right_query: untyped
23
+
24
+ def self.inspect: () -> untyped
25
+
26
+ # @rbs operand: Quo::ComposedQuery | Quo::Query | ::ActiveRecord::Relation
27
+ # @rbs return: String
28
+ def self.quo_operand_desc: (Quo::ComposedQuery | Quo::Query | ::ActiveRecord::Relation operand) -> String
29
+
30
+ # We can also merge instance of prepared queries
31
+ # @rbs left_instance: Quo::Query | ::ActiveRecord::Relation
32
+ # @rbs right_instance: Quo::Query | ::ActiveRecord::Relation
33
+ # @rbs joins: untyped
34
+ # @rbs return: Quo::ComposedQuery
35
+ def merge_instances: (Quo::Query | ::ActiveRecord::Relation left_instance, Quo::Query | ::ActiveRecord::Relation right_instance, ?joins: untyped) -> Quo::ComposedQuery
36
+
37
+ # @rbs override
38
+ def query: ...
39
+
40
+ # @rbs override
41
+ def inspect: ...
42
+
43
+ private
44
+
45
+ # @rbs return: Hash[Symbol, untyped]
46
+ def child_options: (untyped query_class) -> Hash[Symbol, untyped]
47
+
48
+ # @rbs return: Array[Symbol]
49
+ def property_names: (untyped query_class) -> Array[Symbol]
50
+
51
+ # @rbs return: Quo::Query | ::ActiveRecord::Relation
52
+ def left: () -> (Quo::Query | ::ActiveRecord::Relation)
53
+
54
+ # @rbs return: Quo::Query | ::ActiveRecord::Relation
55
+ def right: () -> (Quo::Query | ::ActiveRecord::Relation)
56
+
57
+ # @rbs return: ActiveRecord::Relation | CollectionBackedQuery
58
+ def merge_left_and_right: () -> (ActiveRecord::Relation | CollectionBackedQuery)
59
+
60
+ # @rbs left_rel: ActiveRecord::Relation
61
+ # @rbs return: ActiveRecord::Relation
62
+ def apply_joins: (ActiveRecord::Relation left_rel) -> ActiveRecord::Relation
63
+
64
+ # @rbs rel: untyped
65
+ # @rbs return: bool
66
+ def is_relation?: (untyped rel) -> bool
67
+
68
+ # @rbs left: untyped
69
+ # @rbs right: untyped
70
+ # @rbs return: bool
71
+ def both_relations?: (untyped left, untyped right) -> bool
72
+
73
+ # @rbs left: untyped
74
+ # @rbs right: untyped
75
+ # @rbs return: bool
76
+ def left_relation_right_enumerable?: (untyped left, untyped right) -> bool
77
+
78
+ # @rbs left: untyped
79
+ # @rbs right: untyped
80
+ # @rbs return: bool
81
+ def left_enumerable_right_relation?: (untyped left, untyped right) -> bool
82
+ end
83
+ end
@@ -0,0 +1,6 @@
1
+ # Generated from lib/quo/engine.rb with RBS::Inline
2
+
3
+ module Quo
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,29 @@
1
+ # Generated from lib/quo/preloadable.rb with RBS::Inline
2
+
3
+ module Quo
4
+ module Preloadable
5
+ def self.included: (untyped base) -> untyped
6
+
7
+ # This implementation of `query` calls `collection` and preloads the includes.
8
+ # @rbs return: Object & Enumerable[untyped]
9
+ def query: () -> (Object & Enumerable[untyped])
10
+
11
+ # For use with collections of ActiveRecord models.
12
+ # Configures ActiveRecord::Associations::Preloader to load associations of models in the collection
13
+ # @rbs *options: untyped
14
+ # @rbs return: Quo::Query
15
+ def preload: (*untyped options) -> Quo::Query
16
+
17
+ # Alias for `preload`
18
+ # @rbs *options: untyped
19
+ # @rbs return: Quo::Query
20
+ def includes: (*untyped options) -> Quo::Query
21
+
22
+ private
23
+
24
+ @_rel_preload: untyped?
25
+
26
+ # @rbs (untyped records, ?untyped? preload) -> untyped
27
+ def preload_includes: (untyped records, ?untyped? preload) -> untyped
28
+ end
29
+ end
@@ -0,0 +1,98 @@
1
+ # Generated from lib/quo/query.rb with RBS::Inline
2
+
3
+ module Quo
4
+ class Query < Literal::Struct
5
+ include Literal::Types
6
+
7
+ def self.inspect: () -> untyped
8
+
9
+ def self.to_s: () -> untyped
10
+
11
+ def inspect: () -> untyped
12
+
13
+ def to_s: () -> untyped
14
+
15
+ # TODO: put this in a module with the composer and merge_instances methods
16
+ # Compose is aliased as `+`. Can optionally take `joins` parameters to add joins on merged relation.
17
+ # @rbs right: Quo::Query | ActiveRecord::Relation | Object & Enumerable[untyped]
18
+ # @rbs joins: Symbol | Hash[Symbol, untyped] | Array[Symbol | Hash[Symbol, untyped]]
19
+ # @rbs return: Quo::Query & Quo::ComposedQuery
20
+ def self.compose: (Quo::Query | ActiveRecord::Relation | Object & Enumerable[untyped] right, ?joins: Symbol | Hash[Symbol, untyped] | Array[Symbol | Hash[Symbol, untyped]]) -> (Quo::Query & Quo::ComposedQuery)
21
+
22
+ COERCE_TO_INT: untyped
23
+
24
+ attr_accessor page(): Integer?
25
+
26
+ attr_accessor page_size(): Integer?
27
+
28
+ @current_page: Integer?
29
+
30
+ def next_page_query: () -> Quo::Query
31
+
32
+ def previous_page_query: () -> Quo::Query
33
+
34
+ def offset: () -> Integer
35
+
36
+ # Returns a active record query, or a Quo::Query instance
37
+ def query: () -> (Quo::Query | ::ActiveRecord::Relation)
38
+
39
+ # @rbs **overrides: untyped
40
+ # @rbs return: Quo::Query
41
+ def copy: (**untyped overrides) -> Quo::Query
42
+
43
+ # Compose is aliased as `+`. Can optionally take `joins` parameters to add joins on merged relation.
44
+ # @rbs right: Quo::Query | ::ActiveRecord::Relation
45
+ # @rbs joins: untyped
46
+ # @rbs return: Quo::ComposedQuery
47
+ def merge: (Quo::Query | ::ActiveRecord::Relation right, ?joins: untyped) -> Quo::ComposedQuery
48
+
49
+ @__transformer: nil | ^(untyped, ?Integer) -> untyped
50
+
51
+ # Set a block used to transform data after query fetching
52
+ # @rbs block: ^(untyped, ?Integer) -> untyped
53
+ # @rbs return: self
54
+ def transform: () ?{ (?) -> untyped } -> self
55
+
56
+ # Is this query object a ActiveRecord relation under the hood?
57
+ def relation?: () -> bool
58
+
59
+ # Is this query object loaded data/collection under the hood? (ie not a AR relation)
60
+ def collection?: () -> bool
61
+
62
+ # Is this query object paged? (ie is paging enabled)
63
+ def paged?: () -> bool
64
+
65
+ # Is this query object transforming results?
66
+ def transform?: () -> bool
67
+
68
+ # Unwrap the paginated query
69
+ def unwrap: () -> ActiveRecord::Relation
70
+
71
+ # Unwrap the un-paginated query
72
+ def unwrap_unpaginated: () -> ActiveRecord::Relation
73
+
74
+ private
75
+
76
+ def transformer: () -> untyped
77
+
78
+ def validated_query: () -> untyped
79
+
80
+ # The underlying query is essentially the configured query with optional extras setup
81
+ def underlying_query: () -> void
82
+
83
+ # The configured query is the underlying query with paging
84
+ def configured_query: () -> void
85
+
86
+ def sanitised_page_size: () -> Integer
87
+
88
+ # @rbs rel: untyped
89
+ # @rbs return: bool
90
+ def is_collection?: (untyped rel) -> bool
91
+
92
+ # @rbs rel: untyped
93
+ # @rbs return: bool
94
+ def test_relation: (untyped rel) -> bool
95
+
96
+ def quo_unwrap_unpaginated_query: (untyped q) -> untyped
97
+ end
98
+ end
@@ -0,0 +1,90 @@
1
+ # Generated from lib/quo/relation_backed_query.rb with RBS::Inline
2
+
3
+ module Quo
4
+ class RelationBackedQuery < Query
5
+ # @rbs query: ActiveRecord::Relation | Quo::Query
6
+ # @rbs props: Hash[Symbol, untyped]
7
+ # @rbs &block: () -> ActiveRecord::Relation | Quo::Query | Object & Enumerable[untyped]
8
+ # @rbs return: Quo::RelationBackedQuery
9
+ def self.wrap: (?ActiveRecord::Relation | Quo::Query query, ?props: Hash[Symbol, untyped]) ?{ (?) -> untyped } -> Quo::RelationBackedQuery
10
+
11
+ # @rbs conditions: untyped?
12
+ # @rbs return: String
13
+ def self.sanitize_sql_for_conditions: (untyped? conditions) -> String
14
+
15
+ # @rbs string: String
16
+ # @rbs return: String
17
+ def self.sanitize_sql_string: (String string) -> String
18
+
19
+ # @rbs value: untyped
20
+ # @rbs return: String
21
+ def self.sanitize_sql_parameter: (untyped value) -> String
22
+
23
+ @_rel_group: untyped?
24
+
25
+ @_rel_distinct: bool?
26
+
27
+ @_rel_order: untyped?
28
+
29
+ @_rel_limit: untyped?
30
+
31
+ @_rel_preload: untyped?
32
+
33
+ @_rel_includes: untyped?
34
+
35
+ @_rel_select: untyped?
36
+
37
+ # SQL 'SELECT' configuration, calls to underlying AR relation
38
+ # @rbs *options: untyped
39
+ # @rbs return: Quo::Query
40
+ def select: (*untyped options) -> Quo::Query
41
+
42
+ # SQL 'LIMIT' configuration, calls to underlying AR relation
43
+ # @rbs limit: untyped
44
+ # @rbs return: Quo::Query
45
+ def limit: (untyped limit) -> Quo::Query
46
+
47
+ # SQL 'ORDER BY' configuration, calls to underlying AR relation
48
+ # @rbs options: untyped
49
+ # @rbs return: Quo::Query
50
+ def order: (untyped options) -> Quo::Query
51
+
52
+ # SQL 'GROUP BY' configuration, calls to underlying AR relation
53
+ # @rbs *options: untyped
54
+ # @rbs return: Quo::Query
55
+ def group: (*untyped options) -> Quo::Query
56
+
57
+ # Configures underlying AR relation to include associations
58
+ # @rbs *options: untyped
59
+ # @rbs return: Quo::Query
60
+ def includes: (*untyped options) -> Quo::Query
61
+
62
+ # Configures underlying AR relation to preload associations
63
+ # @rbs *options: untyped
64
+ # @rbs return: Quo::Query
65
+ def preload: (*untyped options) -> Quo::Query
66
+
67
+ # Calls to underlying AR distinct method
68
+ # @rbs enabled: bool
69
+ # @rbs return: Quo::Query
70
+ def distinct: (?bool enabled) -> Quo::Query
71
+
72
+ # @rbs return: Quo::CollectionBackedQuery
73
+ def to_collection: (?total_count: untyped) -> Quo::CollectionBackedQuery
74
+
75
+ def results: () -> Quo::Results
76
+
77
+ # Return the SQL string for this query if its a relation type query object
78
+ def to_sql: () -> String
79
+
80
+ private
81
+
82
+ def validated_query: () -> untyped
83
+
84
+ # The underlying query is essentially the configured query with optional extras setup
85
+ def underlying_query: () -> ActiveRecord::Relation
86
+
87
+ # The configured query is the underlying query with paging
88
+ def configured_query: () -> ActiveRecord::Relation
89
+ end
90
+ end
@@ -0,0 +1,38 @@
1
+ # Generated from lib/quo/relation_results.rb with RBS::Inline
2
+
3
+ module Quo
4
+ class RelationResults < Results
5
+ # @rbs query: Quo::Query
6
+ # @rbs transformer: (^(untyped, ?Integer) -> untyped)?
7
+ # @rbs return: void
8
+ def initialize: (Quo::Query query, ?transformer: (^(untyped, ?Integer) -> untyped)?) -> void
9
+
10
+ # Are there any results for this query?
11
+ def exists?: () -> bool
12
+
13
+ # Gets the count of all results ignoring the current page and page size (if set).
14
+ def total_count: () -> Integer
15
+
16
+ # Gets the actual count of elements in the page of results (assuming paging is being used, otherwise the count of
17
+ # all results)
18
+ def page_count: () -> Integer
19
+
20
+ private
21
+
22
+ @query: Quo::RelationBackedQuery
23
+
24
+ @configured_query: ActiveRecord::Relation
25
+
26
+ # Note we reselect the query as this prevents query errors if the SELECT clause is not compatible with COUNT
27
+ # (SQLException: wrong number of arguments to function COUNT()). We do this in two ways, either with the primary key
28
+ # or with Arel.star. The primary key is the most compatible way to count, but if the query does not have a primary
29
+ # we fallback. The fallback "*" wont work in certain situations though, specifically if we have a limit() on the query
30
+ # which Arel constructs as a subquery. In this case we will get a SQL error as the generated SQL contains
31
+ # `SELECT COUNT(count_column) FROM (SELECT * AS count_column FROM ...) subquery_for_count` where the error is:
32
+ # `ActiveRecord::StatementInvalid: SQLite3::SQLException: near "AS": syntax error`
33
+ # Either way DB engines know how to count efficiently.
34
+ # @rbs query: ActiveRecord::Relation
35
+ # @rbs return: Integer
36
+ def count_query: (ActiveRecord::Relation query) -> Integer
37
+ end
38
+ end
@@ -0,0 +1,39 @@
1
+ # Generated from lib/quo/results.rb with RBS::Inline
2
+
3
+ module Quo
4
+ class Results
5
+ def empty?: () -> bool
6
+
7
+ # Alias for total_count
8
+ def count: () -> Integer
9
+
10
+ # Alias for total_count
11
+ def size: () -> Integer
12
+
13
+ # Alias for page_count
14
+ def page_size: () -> Integer
15
+
16
+ # @rbs &block: (untyped, *untyped) -> untyped
17
+ # @rbs return: Hash[untyped, Array[untyped]]
18
+ def group_by: () { (untyped, *untyped) -> untyped } -> Hash[untyped, Array[untyped]]
19
+
20
+ # Delegate other enumerable methods to underlying collection but also transform
21
+ # @rbs override
22
+ def method_missing: ...
23
+
24
+ # @rbs name: Symbol
25
+ # @rbs include_private: bool
26
+ # @rbs return: bool
27
+ def respond_to_missing?: (Symbol name, ?bool include_private) -> bool
28
+
29
+ def transform?: () -> bool
30
+
31
+ private
32
+
33
+ @transformer: (^(untyped, ?Integer) -> untyped)?
34
+
35
+ # @rbs results: untyped
36
+ # @rbs return: untyped
37
+ def transform_results: (untyped results) -> untyped
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ # Generated from lib/quo/version.rb with RBS::Inline
2
+
3
+ module Quo
4
+ VERSION: ::String
5
+ end
@@ -0,0 +1,9 @@
1
+ # Generated from lib/quo.rb with RBS::Inline
2
+
3
+ module Quo
4
+ extend ActiveSupport::Autoload
5
+
6
+ def self.relation_backed_query_base_class: () -> Quo::RelationBackedQuery
7
+
8
+ def self.collection_backed_query_base_class: () -> Quo::CollectionBackedQuery
9
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 1.0.0.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Ierodiaconou
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-19 00:00:00.000000000 Z
11
+ date: 2024-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '6'
19
+ version: '7'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '8'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '6'
29
+ version: '7'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '8'
@@ -36,7 +36,7 @@ dependencies:
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '6'
39
+ version: '7'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '8'
@@ -46,10 +46,44 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: '6'
49
+ version: '7'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '8'
53
+ - !ruby/object:Gem::Dependency
54
+ name: literal
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.2.0
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '2'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 0.2.0
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '2'
73
+ - !ruby/object:Gem::Dependency
74
+ name: appraisal
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ type: :development
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
53
87
  description: Quo query objects are composable.
54
88
  email:
55
89
  - stevegeek@gmail.com
@@ -58,41 +92,44 @@ extensions: []
58
92
  extra_rdoc_files: []
59
93
  files:
60
94
  - ".standard.yml"
95
+ - Appraisals
61
96
  - CHANGELOG.md
62
97
  - Gemfile
63
98
  - LICENSE.txt
64
99
  - README.md
65
100
  - Rakefile
66
101
  - Steepfile
102
+ - gemfiles/rails_7.0.gemfile
103
+ - gemfiles/rails_7.1.gemfile
104
+ - gemfiles/rails_7.2.gemfile
67
105
  - lib/quo.rb
68
- - lib/quo/eager_query.rb
69
- - lib/quo/loaded_query.rb
70
- - lib/quo/merged_query.rb
106
+ - lib/quo/collection_backed_query.rb
107
+ - lib/quo/collection_results.rb
108
+ - lib/quo/composed_query.rb
109
+ - lib/quo/engine.rb
110
+ - lib/quo/minitest/helpers.rb
111
+ - lib/quo/preloadable.rb
71
112
  - lib/quo/query.rb
72
- - lib/quo/query_composer.rb
73
- - lib/quo/railtie.rb
113
+ - lib/quo/relation_backed_query.rb
114
+ - lib/quo/relation_results.rb
74
115
  - lib/quo/results.rb
75
116
  - lib/quo/rspec/helpers.rb
76
- - lib/quo/utilities/callstack.rb
77
- - lib/quo/utilities/compose.rb
78
- - lib/quo/utilities/sanitize.rb
79
- - lib/quo/utilities/wrap.rb
117
+ - lib/quo/testing/collection_backed_fake.rb
118
+ - lib/quo/testing/relation_backed_fake.rb
80
119
  - lib/quo/version.rb
81
- - lib/quo/wrapped_query.rb
82
120
  - lib/tasks/quo.rake
83
121
  - rbs_collection.yaml
84
- - sig/quo.rbs
85
- - sig/quo/eager_query.rbs
86
- - sig/quo/loaded_query.rbs
87
- - sig/quo/merged_query.rbs
88
- - sig/quo/query.rbs
89
- - sig/quo/query_composer.rbs
90
- - sig/quo/results.rbs
91
- - sig/quo/utilities/callstack.rbs
92
- - sig/quo/utilities/compose.rbs
93
- - sig/quo/utilities/sanitize.rbs
94
- - sig/quo/utilities/wrap.rbs
95
- - sig/quo/wrapped_query.rbs
122
+ - sig/generated/quo.rbs
123
+ - sig/generated/quo/collection_backed_query.rbs
124
+ - sig/generated/quo/collection_results.rbs
125
+ - sig/generated/quo/composed_query.rbs
126
+ - sig/generated/quo/engine.rbs
127
+ - sig/generated/quo/preloadable.rbs
128
+ - sig/generated/quo/query.rbs
129
+ - sig/generated/quo/relation_backed_query.rbs
130
+ - sig/generated/quo/relation_results.rbs
131
+ - sig/generated/quo/results.rbs
132
+ - sig/generated/quo/version.rbs
96
133
  homepage: https://github.com/stevegeek/quo
97
134
  licenses:
98
135
  - MIT
@@ -107,14 +144,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
144
  requirements:
108
145
  - - ">="
109
146
  - !ruby/object:Gem::Version
110
- version: 2.7.0
147
+ version: 3.1.0
111
148
  required_rubygems_version: !ruby/object:Gem::Requirement
112
149
  requirements:
113
150
  - - ">="
114
151
  - !ruby/object:Gem::Version
115
152
  version: '0'
116
153
  requirements: []
117
- rubygems_version: 3.5.3
154
+ rubygems_version: 3.5.11
118
155
  signing_key:
119
156
  specification_version: 4
120
157
  summary: Quo is a query object gem for Rails
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Quo
4
- class EagerQuery < Quo::Query
5
- # Optionally return the `total_count` option if it has been set.
6
- # This is useful when the total count is known and not equal to size
7
- # of wrapped collection.
8
- def count
9
- options[:total_count] || super
10
- end
11
-
12
- # Is this query object paged? (when no total count)
13
- def paged?
14
- options[:total_count].nil? && current_page.present?
15
- end
16
-
17
- def collection
18
- raise NotImplementedError, "EagerQuery objects must define a 'collection' method"
19
- end
20
-
21
- def query
22
- preload_includes(collection) if options[:includes]
23
- collection
24
- end
25
-
26
- def relation?
27
- false
28
- end
29
-
30
- def eager?
31
- true
32
- end
33
-
34
- private
35
-
36
- def underlying_query
37
- unwrap_relation(query)
38
- end
39
-
40
- def unwrap_relation(query)
41
- query.is_a?(Quo::Query) ? query.unwrap : query
42
- end
43
-
44
- def preload_includes(records, preload = nil)
45
- ::ActiveRecord::Associations::Preloader.new(
46
- records: records,
47
- associations: preload || options[:includes]
48
- ).call
49
- end
50
- end
51
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Quo
4
- class LoadedQuery < Quo::EagerQuery
5
- def initialize(collection, **options)
6
- @collection = collection
7
- super(**options)
8
- end
9
-
10
- def copy(**options)
11
- self.class.new(@collection, **@options.merge(options))
12
- end
13
-
14
- private
15
-
16
- attr_reader :collection
17
- end
18
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Quo
4
- class MergedQuery < Quo::Query
5
- def initialize(merged_query, left, right, **options)
6
- @merged_query = merged_query
7
- @left = left
8
- @right = right
9
- super(**options)
10
- end
11
-
12
- def query
13
- @merged_query
14
- end
15
-
16
- def copy(**options)
17
- self.class.new(query, left, right, **@options.merge(options))
18
- end
19
-
20
- def inspect
21
- "Quo::MergedQuery[#{operand_desc(left)}, #{operand_desc(right)}]"
22
- end
23
-
24
- private
25
-
26
- attr_reader :left, :right
27
-
28
- def operand_desc(operand)
29
- if operand.is_a? Quo::MergedQuery
30
- operand.inspect
31
- else
32
- operand.class.name || "(anonymous)"
33
- end
34
- end
35
- end
36
- end