dbee-active_record 2.0.3 → 2.1.2

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 (28) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +13 -12
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +3 -10
  5. data/CHANGELOG.md +24 -1
  6. data/README.md +1 -1
  7. data/dbee-active_record.gemspec +17 -8
  8. data/exe/.gitkeep +0 -0
  9. data/lib/dbee/providers/active_record_provider/expression_builder.rb +55 -24
  10. data/lib/dbee/providers/active_record_provider/maker.rb +37 -0
  11. data/lib/dbee/providers/active_record_provider/{expression_builder/constraint_maker.rb → makers/constraint.rb} +12 -12
  12. data/lib/dbee/providers/active_record_provider/{expression_builder/order_maker.rb → makers/order.rb} +9 -9
  13. data/lib/dbee/providers/active_record_provider/makers/select.rb +81 -0
  14. data/lib/dbee/providers/active_record_provider/makers/where.rb +111 -0
  15. data/lib/dbee/providers/active_record_provider/version.rb +1 -1
  16. data/spec/db_helper.rb +134 -14
  17. data/spec/dbee/providers/active_record_provider/expression_builder_spec.rb +117 -0
  18. data/spec/dbee/providers/active_record_provider/makers/where_spec.rb +260 -0
  19. data/spec/dbee/providers/active_record_provider_spec.rb +101 -3
  20. data/spec/fixtures/active_record_snapshots/one_table_empty_query.yaml +10 -0
  21. data/spec/fixtures/active_record_snapshots/one_table_query_with_filters.yaml +24 -16
  22. data/spec/fixtures/active_record_snapshots/two_table_query_with_aggregation.yaml +71 -0
  23. data/spec/fixtures/active_record_snapshots/two_table_query_with_pivoting.yaml +88 -0
  24. data/spec/fixtures/models.yaml +20 -0
  25. data/spec/spec_helper.rb +5 -1
  26. metadata +51 -19
  27. data/lib/dbee/providers/active_record_provider/expression_builder/select_maker.rb +0 -33
  28. data/lib/dbee/providers/active_record_provider/expression_builder/where_maker.rb +0 -56
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- #
4
- # Copyright (c) 2019-present, Blue Marble Payroll, LLC
5
- #
6
- # This source code is licensed under the MIT license found in the
7
- # LICENSE file in the root directory of this source tree.
8
- #
9
-
10
- module Dbee
11
- module Providers
12
- class ActiveRecordProvider
13
- class ExpressionBuilder
14
- # Derives Arel#project predicates.
15
- class SelectMaker
16
- include Singleton
17
-
18
- def make(column, arel_column, alias_maker)
19
- column_alias = quote(alias_maker.make(column.display))
20
-
21
- arel_column.as(column_alias)
22
- end
23
-
24
- private
25
-
26
- def quote(value)
27
- ActiveRecord::Base.connection.quote(value)
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- #
4
- # Copyright (c) 2019-present, Blue Marble Payroll, LLC
5
- #
6
- # This source code is licensed under the MIT license found in the
7
- # LICENSE file in the root directory of this source tree.
8
- #
9
-
10
- module Dbee
11
- module Providers
12
- class ActiveRecordProvider
13
- class ExpressionBuilder
14
- # Derives Arel#where predicates.
15
- class WhereMaker
16
- include Singleton
17
-
18
- FILTER_EVALUATORS = {
19
- Query::Filters::Contains => ->(column, val) { column.matches("%#{val}%") },
20
- Query::Filters::Equals => ->(column, val) { column.eq(val) },
21
- Query::Filters::GreaterThan => ->(column, val) { column.gt(val) },
22
- Query::Filters::GreaterThanOrEqualTo => ->(column, val) { column.gteq(val) },
23
- Query::Filters::LessThan => ->(column, val) { column.lt(val) },
24
- Query::Filters::LessThanOrEqualTo => ->(column, val) { column.lteq(val) },
25
- Query::Filters::NotContain => ->(column, val) { column.does_not_match("%#{val}%") },
26
- Query::Filters::NotEquals => ->(column, val) { column.not_eq(val) },
27
- Query::Filters::NotStartWith => ->(column, val) { column.does_not_match("#{val}%") },
28
- Query::Filters::StartsWith => ->(column, val) { column.matches("#{val}%") }
29
- }.freeze
30
-
31
- private_constant :FILTER_EVALUATORS
32
-
33
- def make(filter, arel_column)
34
- predicates = normalize(filter.value).map do |coerced_value|
35
- method = FILTER_EVALUATORS[filter.class]
36
-
37
- raise ArgumentError, "cannot compile filter: #{filter}" unless method
38
-
39
- method.call(arel_column, coerced_value)
40
- end
41
-
42
- predicates.inject(predicates.shift) do |memo, predicate|
43
- memo.or(predicate)
44
- end
45
- end
46
-
47
- private
48
-
49
- def normalize(value)
50
- value ? Array(value).flatten : [nil]
51
- end
52
- end
53
- end
54
- end
55
- end
56
- end