dbee-active_record 1.0.0.pre.alpha.1 → 1.0.0.pre.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b90006ed4131966543f8f275e4deb54980ffab496a498815773aa5aa67b4b8cf
4
- data.tar.gz: f62a8f583274f83119f269b2c7a5f718ed72801067d359254ae9de30df5a5775
3
+ metadata.gz: cab1f2d6c2a6d667b383c44478b3252720abd3b15ce6a2592e74de9c9ac4154a
4
+ data.tar.gz: 241dd04790275b714766f1132b6266a05027f972a073de71f0cc9839451b29ad
5
5
  SHA512:
6
- metadata.gz: f1fd3ac8fbda1255d6eabecb1d932274e799727223220c08fa93db0ea1970ea0438416ae83e6d7da34477fc43ff43cc3a78afe1763bb5cd19292822e74f3ae99
7
- data.tar.gz: c26ff6e76f480578fbee1a6f51ad37a07826189307b9e65dc4b5fa4d8acb1ccf43b36ab2322dc498f91e7e60d5b3c1b1a1fc8ac30fdd5fc0eb090a5046fae632
6
+ metadata.gz: 393dbacbcb27172556d5957777e72b0d3a5428a7f833a9c24c80e7a733f56b794fba8beb372f6661152806042df0c1b13bcd7e9d12eef936bd1ab7236a94d49b
7
+ data.tar.gz: c65fdeb21d29c3af66d8dfb353fecae9fb01991314914c5113d85c2912c4e1f775b89237077c935f217f0f8c69f24fd3d7cc7455904528da4ecd1da2fd7f9af9
data/.rubocop.yml CHANGED
@@ -16,7 +16,7 @@ Metrics/MethodLength:
16
16
  - spec/db_helper.rb
17
17
 
18
18
  AllCops:
19
- TargetRubyVersion: 2.5
19
+ TargetRubyVersion: 2.4
20
20
 
21
21
  Metrics/AbcSize:
22
22
  Max: 16
data/.travis.yml CHANGED
@@ -6,8 +6,8 @@ services:
6
6
  - mysql
7
7
  rvm:
8
8
  # Build on the latest stable of all supported Rubies (https://www.ruby-lang.org/en/downloads/):
9
- - 2.5.3
10
- - 2.6.0
9
+ - 2.4.6
10
+ - 2.5.5
11
11
  - 2.6.3
12
12
  cache: bundler
13
13
  before_script:
@@ -19,18 +19,18 @@ Gem::Specification.new do |s|
19
19
  s.homepage = 'https://github.com/bluemarblepayroll/dbee-active_record'
20
20
  s.license = 'MIT'
21
21
 
22
- s.required_ruby_version = '>= 2.5.3'
22
+ s.required_ruby_version = '>= 2.4.6'
23
23
 
24
24
  s.add_dependency('activerecord', '~>5', '>=5.2.1')
25
- s.add_dependency('dbee', '>=1.0.0.pre.alpha.2')
25
+ s.add_dependency('dbee', '~>1')
26
26
 
27
27
  s.add_development_dependency('guard-rspec', '~>4.7')
28
28
  s.add_development_dependency('mysql2', '~>0.5')
29
29
  s.add_development_dependency('pry', '~>0')
30
30
  s.add_development_dependency('rake', '~> 12')
31
31
  s.add_development_dependency('rspec', '~> 3.8')
32
- s.add_development_dependency('rubocop', '~>0.63.1')
33
- s.add_development_dependency('simplecov', '~>0.16.1')
34
- s.add_development_dependency('simplecov-console', '~>0.4.2')
32
+ s.add_development_dependency('rubocop', '~>0.74.0')
33
+ s.add_development_dependency('simplecov', '~>0.17.0')
34
+ s.add_development_dependency('simplecov-console', '~>0.5.0')
35
35
  s.add_development_dependency('sqlite3', '~>1')
36
36
  end
@@ -28,10 +28,8 @@ module Dbee
28
28
 
29
29
  private_constant :METHODS
30
30
 
31
- def make(filter, arel_column, model_column)
32
- coerced_values = Array(filter.value).map { |v| model_column.coerce(v) }
33
-
34
- predicates = coerced_values.map do |coerced_value|
31
+ def make(filter, arel_column)
32
+ predicates = normalize(filter.value).map do |coerced_value|
35
33
  method = METHODS[filter.class]
36
34
 
37
35
  raise ArgumentError, "cannot compile filter: #{filter}" unless method
@@ -39,13 +37,15 @@ module Dbee
39
37
  method.call(arel_column, coerced_value)
40
38
  end
41
39
 
42
- clause = predicates.shift
43
-
44
- predicates.each do |predicate|
45
- clause = clause.or(predicate)
40
+ predicates.inject(predicates.shift) do |memo, predicate|
41
+ memo.or(predicate)
46
42
  end
43
+ end
44
+
45
+ private
47
46
 
48
- clause
47
+ def normalize(value)
48
+ value ? Array(value).flatten : [nil]
49
49
  end
50
50
  end
51
51
  end
@@ -58,10 +58,6 @@ module Dbee
58
58
  @key_paths_to_arel_columns ||= {}
59
59
  end
60
60
 
61
- def key_paths_to_model_columns
62
- @key_paths_to_model_columns ||= {}
63
- end
64
-
65
61
  def where_maker
66
62
  @where_maker ||= WhereMaker.new
67
63
  end
@@ -81,11 +77,10 @@ module Dbee
81
77
  def add_filter(filter)
82
78
  add_key_path(filter.key_path)
83
79
 
84
- key_path = filter.key_path
85
- arel_column = key_paths_to_arel_columns[key_path]
86
- model_column = key_paths_to_model_columns[key_path]
80
+ key_path = filter.key_path
81
+ arel_column = key_paths_to_arel_columns[key_path]
87
82
 
88
- predicate = where_maker.make(filter, arel_column, model_column)
83
+ predicate = where_maker.make(filter, arel_column)
89
84
 
90
85
  @statement = statement.where(predicate)
91
86
 
@@ -126,11 +121,6 @@ module Dbee
126
121
  self
127
122
  end
128
123
 
129
- def model_column(ancestors, key_path)
130
- model_column = (ancestors.values.last || model).column(key_path.column_name)
131
- key_paths_to_model_columns[key_path] = model_column
132
- end
133
-
134
124
  def table(name, model, previous_table)
135
125
  table = Arel::Table.new(model.table)
136
126
  table.table_alias = table_alias_maker.make(name)
@@ -154,8 +144,6 @@ module Dbee
154
144
 
155
145
  ancestors = model.ancestors(key_path.ancestor_names)
156
146
 
157
- model_column(ancestors, key_path)
158
-
159
147
  table = traverse_ancestors(ancestors)
160
148
 
161
149
  arel_column = table[key_path.column_name]
@@ -10,7 +10,7 @@
10
10
  module Dbee
11
11
  module Providers
12
12
  class ActiveRecordProvider
13
- VERSION = '1.0.0-alpha.1'
13
+ VERSION = '1.0.0-alpha.2'
14
14
  end
15
15
  end
16
16
  end
@@ -21,6 +21,8 @@ module Dbee
21
21
  DEFAULT_TABLE_PREFIX = 't'
22
22
  DEFAULT_COLUMN_PREFIX = 'c'
23
23
 
24
+ private_constant :DEFAULT_TABLE_PREFIX, :DEFAULT_COLUMN_PREFIX
25
+
24
26
  attr_reader :readable, :table_alias_maker, :column_alias_maker
25
27
 
26
28
  def initialize(
@@ -30,8 +30,8 @@ describe Dbee::Providers::ActiveRecordProvider do
30
30
  model_name = snapshot['model_name']
31
31
  query = Dbee::Query.make(snapshot['query'])
32
32
  model = Dbee::Model.make(models[model_name])
33
- expected_sql = snapshot[key].to_s.chomp.tr("\n", ' ')
34
- actual_sql = described_class.new(readable: readable).sql(model, query)
33
+ expected_sql = snapshot[key].to_s.chomp.tr("\n", ' ')
34
+ actual_sql = described_class.new(readable: readable).sql(model, query)
35
35
 
36
36
  error_msg = <<~ERROR_MSG
37
37
  Expected: #{expected_sql}
@@ -21,22 +21,13 @@ query:
21
21
  value: 'false' # notice how the value is a string, but the data model should be setup to be a boolean
22
22
  - type: equals
23
23
  key_path: active
24
- value:
25
- - false
26
- - true
27
- - null
28
- - 'y'
29
- - 'n'
30
- - ''
24
+ value: [ true, false, [ null ] ] # test out nested value arrays
31
25
  - type: equals
32
26
  key_path: inspected
33
27
  value:
34
28
  - false
35
29
  - true
36
30
  - null
37
- - 'y'
38
- - 'n'
39
- - ''
40
31
  - type: less_than_or_equal_to
41
32
  value: '2019-03-04'
42
33
  key_path: created_at
@@ -65,24 +56,15 @@ query:
65
56
  - 'hu'
66
57
  key_path: name
67
58
  sqlite_readable: |+
68
- SELECT
69
- "theaters"."id" AS 'ID #',
59
+ SELECT "theaters"."id" AS 'ID #',
70
60
  "theaters"."name" AS 'name'
71
61
  FROM "theaters" "theaters"
72
- WHERE
73
- ("theaters"."name" = 'AMC' OR "theaters"."name" = 'Regal') AND
62
+ WHERE ("theaters"."name" = 'AMC' OR "theaters"."name" = 'Regal') AND
74
63
  "theaters"."name" LIKE 'A%' AND
75
64
  "theaters"."name" LIKE '%m%' AND
76
- "theaters"."active" = 'f' AND
77
- ((((("theaters"."active" = 'f' OR "theaters"."active" = 't') OR
78
- "theaters"."active" = 'f') OR "theaters"."active" = 't') OR
79
- "theaters"."active" = 'f') OR
80
- "theaters"."active" = 'f') AND
81
- ((((("theaters"."inspected" = 'f' OR "theaters"."inspected" = 't') OR
82
- "theaters"."inspected" IS NULL) OR
83
- "theaters"."inspected" = 't') OR
84
- "theaters"."inspected" = 'f') OR
85
- "theaters"."inspected" IS NULL) AND
65
+ "theaters"."active" = 'false' AND
66
+ (("theaters"."active" = 't' OR "theaters"."active" = 'f') OR "theaters"."active" IS NULL) AND
67
+ (("theaters"."inspected" = 'f' OR "theaters"."inspected" = 't') OR "theaters"."inspected" IS NULL) AND
86
68
  "theaters"."created_at" <= '2019-03-04' AND
87
69
  "theaters"."created_at" < '2018-03-04' AND
88
70
  "theaters"."created_at" >= '2001-03-04' AND
@@ -91,24 +73,15 @@ sqlite_readable: |+
91
73
  ("theaters"."name" NOT LIKE '%tfli%' OR "theaters"."name" NOT LIKE '%ul%') AND
92
74
  ("theaters"."name" NOT LIKE 'netf%' OR "theaters"."name" NOT LIKE 'hu%')
93
75
  sqlite_not_readable: |+
94
- SELECT
95
- "t0"."id" AS 'c0',
76
+ SELECT "t0"."id" AS 'c0',
96
77
  "t0"."name" AS 'c1'
97
78
  FROM "theaters" "t0"
98
- WHERE
99
- ("t0"."name" = 'AMC' OR "t0"."name" = 'Regal') AND
79
+ WHERE ("t0"."name" = 'AMC' OR "t0"."name" = 'Regal') AND
100
80
  "t0"."name" LIKE 'A%' AND
101
81
  "t0"."name" LIKE '%m%' AND
102
- "t0"."active" = 'f' AND
103
- ((((("t0"."active" = 'f' OR "t0"."active" = 't') OR
104
- "t0"."active" = 'f') OR "t0"."active" = 't') OR
105
- "t0"."active" = 'f') OR
106
- "t0"."active" = 'f') AND
107
- ((((("t0"."inspected" = 'f' OR "t0"."inspected" = 't') OR
108
- "t0"."inspected" IS NULL) OR
109
- "t0"."inspected" = 't') OR
110
- "t0"."inspected" = 'f') OR
111
- "t0"."inspected" IS NULL) AND
82
+ "t0"."active" = 'false' AND
83
+ (("t0"."active" = 't' OR "t0"."active" = 'f') OR "t0"."active" IS NULL) AND
84
+ (("t0"."inspected" = 'f' OR "t0"."inspected" = 't') OR "t0"."inspected" IS NULL) AND
112
85
  "t0"."created_at" <= '2019-03-04' AND
113
86
  "t0"."created_at" < '2018-03-04' AND
114
87
  "t0"."created_at" >= '2001-03-04' AND
@@ -117,24 +90,15 @@ sqlite_not_readable: |+
117
90
  ("t0"."name" NOT LIKE '%tfli%' OR "t0"."name" NOT LIKE '%ul%') AND
118
91
  ("t0"."name" NOT LIKE 'netf%' OR "t0"."name" NOT LIKE 'hu%')
119
92
  mysql_readable: |+
120
- SELECT
121
- `theaters`.`id` AS 'ID #',
93
+ SELECT `theaters`.`id` AS 'ID #',
122
94
  `theaters`.`name` AS 'name'
123
95
  FROM `theaters` `theaters`
124
- WHERE
125
- (`theaters`.`name` = 'AMC' OR `theaters`.`name` = 'Regal') AND
96
+ WHERE (`theaters`.`name` = 'AMC' OR `theaters`.`name` = 'Regal') AND
126
97
  `theaters`.`name` LIKE 'A%' AND
127
98
  `theaters`.`name` LIKE '%m%' AND
128
- `theaters`.`active` = FALSE AND
129
- (((((`theaters`.`active` = FALSE OR `theaters`.`active` = TRUE) OR
130
- `theaters`.`active` = FALSE) OR `theaters`.`active` = TRUE) OR
131
- `theaters`.`active` = FALSE) OR
132
- `theaters`.`active` = FALSE) AND
133
- (((((`theaters`.`inspected` = FALSE OR `theaters`.`inspected` = TRUE) OR
134
- `theaters`.`inspected` IS NULL) OR
135
- `theaters`.`inspected` = TRUE) OR
136
- `theaters`.`inspected` = FALSE) OR
137
- `theaters`.`inspected` IS NULL) AND
99
+ `theaters`.`active` = 'false' AND
100
+ ((`theaters`.`active` = TRUE OR `theaters`.`active` = FALSE) OR `theaters`.`active` IS NULL) AND
101
+ ((`theaters`.`inspected` = FALSE OR `theaters`.`inspected` = TRUE) OR `theaters`.`inspected` IS NULL) AND
138
102
  `theaters`.`created_at` <= '2019-03-04' AND
139
103
  `theaters`.`created_at` < '2018-03-04' AND
140
104
  `theaters`.`created_at` >= '2001-03-04' AND
@@ -143,24 +107,15 @@ mysql_readable: |+
143
107
  (`theaters`.`name` NOT LIKE '%tfli%' OR `theaters`.`name` NOT LIKE '%ul%') AND
144
108
  (`theaters`.`name` NOT LIKE 'netf%' OR `theaters`.`name` NOT LIKE 'hu%')
145
109
  mysql_not_readable: |+
146
- SELECT
147
- `t0`.`id` AS 'c0',
110
+ SELECT `t0`.`id` AS 'c0',
148
111
  `t0`.`name` AS 'c1'
149
112
  FROM `theaters` `t0`
150
- WHERE
151
- (`t0`.`name` = 'AMC' OR `t0`.`name` = 'Regal') AND
113
+ WHERE (`t0`.`name` = 'AMC' OR `t0`.`name` = 'Regal') AND
152
114
  `t0`.`name` LIKE 'A%' AND
153
115
  `t0`.`name` LIKE '%m%' AND
154
- `t0`.`active` = FALSE AND
155
- (((((`t0`.`active` = FALSE OR `t0`.`active` = TRUE) OR
156
- `t0`.`active` = FALSE) OR `t0`.`active` = TRUE) OR
157
- `t0`.`active` = FALSE) OR
158
- `t0`.`active` = FALSE) AND
159
- (((((`t0`.`inspected` = FALSE OR `t0`.`inspected` = TRUE) OR
160
- `t0`.`inspected` IS NULL) OR
161
- `t0`.`inspected` = TRUE) OR
162
- `t0`.`inspected` = FALSE) OR
163
- `t0`.`inspected` IS NULL) AND
116
+ `t0`.`active` = 'false' AND
117
+ ((`t0`.`active` = TRUE OR `t0`.`active` = FALSE) OR `t0`.`active` IS NULL) AND
118
+ ((`t0`.`inspected` = FALSE OR `t0`.`inspected` = TRUE) OR `t0`.`inspected` IS NULL) AND
164
119
  `t0`.`created_at` <= '2019-03-04' AND
165
120
  `t0`.`created_at` < '2018-03-04' AND
166
121
  `t0`.`created_at` >= '2001-03-04' AND
@@ -1,12 +1,6 @@
1
1
  Theaters, Members, and Movies:
2
2
  name: theaters
3
3
  table: theaters
4
- columns:
5
- - name: active
6
- type: boolean
7
- nullable: false
8
- - name: inspected
9
- type: boolean # this one is nullable
10
4
  models:
11
5
  - name: members
12
6
  table: members
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbee-active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.alpha.1
4
+ version: 1.0.0.pre.alpha.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
@@ -34,16 +34,16 @@ dependencies:
34
34
  name: dbee
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">="
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 1.0.0.pre.alpha.2
39
+ version: '1'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ">="
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 1.0.0.pre.alpha.2
46
+ version: '1'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard-rspec
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -120,42 +120,42 @@ dependencies:
120
120
  requirements:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: 0.63.1
123
+ version: 0.74.0
124
124
  type: :development
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
- version: 0.63.1
130
+ version: 0.74.0
131
131
  - !ruby/object:Gem::Dependency
132
132
  name: simplecov
133
133
  requirement: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: 0.16.1
137
+ version: 0.17.0
138
138
  type: :development
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
- version: 0.16.1
144
+ version: 0.17.0
145
145
  - !ruby/object:Gem::Dependency
146
146
  name: simplecov-console
147
147
  requirement: !ruby/object:Gem::Requirement
148
148
  requirements:
149
149
  - - "~>"
150
150
  - !ruby/object:Gem::Version
151
- version: 0.4.2
151
+ version: 0.5.0
152
152
  type: :development
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: 0.4.2
158
+ version: 0.5.0
159
159
  - !ruby/object:Gem::Dependency
160
160
  name: sqlite3
161
161
  requirement: !ruby/object:Gem::Requirement
@@ -228,7 +228,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
228
228
  requirements:
229
229
  - - ">="
230
230
  - !ruby/object:Gem::Version
231
- version: 2.5.3
231
+ version: 2.4.6
232
232
  required_rubygems_version: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - ">"