dbee 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -1
- data/CHANGELOG.md +17 -0
- data/dbee.gemspec +2 -2
- data/lib/dbee.rb +1 -0
- data/lib/dbee/constant_resolver.rb +34 -0
- data/lib/dbee/dsl/association.rb +8 -19
- data/lib/dbee/version.rb +1 -1
- data/spec/dbee/constant_resolver_spec.rb +53 -0
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a84b1a2e86f04be67850fa1bfe79aa9a52d1548db6ba8c76df551b5257a00bd8
|
4
|
+
data.tar.gz: 2c7d2d5b847e805f46c94019c72b6d7c79990ebd2d4b7d8a3d940278b267a904
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83f756643490546309610118e1ff5efb501c3db51c0322e5a2bb7a0fe2bc96b5164362d9531e6ff11371fee8a6096ba38c04f5c269bf590670fa76c03d62bb45
|
7
|
+
data.tar.gz: 449063144c4ba5babd0358e7d8851686d4cf7520d2aef2a9444175e616cc9a9a01fe8c3596c941e24ce4dafa5c7e4aaa0fe8d8ac378953f61d97e2acbc4a36b8
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.6.
|
1
|
+
2.6.5
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
# 2.0.3 (January 7th, 2020)
|
2
|
+
|
3
|
+
### Fixes:
|
4
|
+
|
5
|
+
* Constant resolution will now explicitly set inherit to false when calling `Object#const_defined?` and `Object#const_get`. This should equate to less false positives. For example:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
class A; end
|
9
|
+
|
10
|
+
module B
|
11
|
+
class A; end
|
12
|
+
class C; end
|
13
|
+
end
|
14
|
+
```
|
15
|
+
|
16
|
+
If `B::A` is the desired class, it would not be suitable to just declare an association on `A` as that would resolve explicitly to `::A`. It also means C cannot be auto-resolved without prefixing/sharing the namespace with parent association `A`.
|
17
|
+
|
1
18
|
# 2.0.2 (November 7th, 2019)
|
2
19
|
|
3
20
|
### Additions:
|
data/dbee.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.add_development_dependency('pry', '~>0')
|
29
29
|
s.add_development_dependency('rake', '~> 13')
|
30
30
|
s.add_development_dependency('rspec')
|
31
|
-
s.add_development_dependency('rubocop', '~>0.
|
31
|
+
s.add_development_dependency('rubocop', '~>0.79.0')
|
32
32
|
s.add_development_dependency('simplecov', '~>0.17.0')
|
33
|
-
s.add_development_dependency('simplecov-console', '~>0.
|
33
|
+
s.add_development_dependency('simplecov-console', '~>0.6.0')
|
34
34
|
end
|
data/lib/dbee.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
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
|
+
# This class is responsible for turning strings and symbols into constants.
|
12
|
+
# It does not deal with inflection, simply just constant resolution.
|
13
|
+
class ConstantResolver
|
14
|
+
# Only use Module constant resolution if a string or symbol was passed in.
|
15
|
+
# Any other type is defined as an acceptable constant and is simply returned.
|
16
|
+
def constantize(value)
|
17
|
+
value.is_a?(String) || value.is_a?(Symbol) ? object_constant(value) : value
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# If the constant has been loaded, we can safely use it through const_get.
|
23
|
+
# If the constant has not been loaded, we need to defer to const_missing to resolve it.
|
24
|
+
# If we blindly call const_get, it may return false positives for namespaced constants
|
25
|
+
# or anything nested.
|
26
|
+
def object_constant(value)
|
27
|
+
if Object.const_defined?(value, false)
|
28
|
+
Object.const_get(value, false)
|
29
|
+
else
|
30
|
+
Object.const_missing(value)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/dbee/dsl/association.rb
CHANGED
@@ -19,16 +19,17 @@ module Dbee
|
|
19
19
|
raise ArgumentError, 'inflector is required' unless inflector
|
20
20
|
raise ArgumentError, 'name is required' if name.to_s.empty?
|
21
21
|
|
22
|
-
@on_class_name
|
23
|
-
@inflector
|
24
|
-
@name
|
25
|
-
@opts
|
22
|
+
@on_class_name = on_class_name
|
23
|
+
@inflector = inflector
|
24
|
+
@name = name.to_s
|
25
|
+
@opts = opts || {}
|
26
|
+
@constant_resolver = ConstantResolver.new
|
26
27
|
|
27
28
|
freeze
|
28
29
|
end
|
29
30
|
|
30
31
|
def model_constant
|
31
|
-
constantize(class_name)
|
32
|
+
constant_resolver.constantize(class_name)
|
32
33
|
end
|
33
34
|
|
34
35
|
def constraints
|
@@ -37,6 +38,8 @@ module Dbee
|
|
37
38
|
|
38
39
|
private
|
39
40
|
|
41
|
+
attr_reader :constant_resolver
|
42
|
+
|
40
43
|
def class_name
|
41
44
|
opts[:model] || relative_class_name
|
42
45
|
end
|
@@ -47,20 +50,6 @@ module Dbee
|
|
47
50
|
def relative_class_name
|
48
51
|
(on_class_name.split('::')[0...-1] + [inflector.classify(name)]).join('::')
|
49
52
|
end
|
50
|
-
|
51
|
-
# Only use Module constant resolution if a string or symbol was passed in.
|
52
|
-
# Any other type is defined as an acceptable constant and is simply returned.
|
53
|
-
def constantize(value)
|
54
|
-
value.is_a?(String) || value.is_a?(Symbol) ? object_constant(value) : value
|
55
|
-
end
|
56
|
-
|
57
|
-
# If the constant has been loaded, we can safely use it through const_get.
|
58
|
-
# If the constant has not been loaded, we need to defer to const_missing to resolve it.
|
59
|
-
# If we blindly call const_get, it may return false positives for namespaced constants
|
60
|
-
# or anything nested.
|
61
|
-
def object_constant(value)
|
62
|
-
Object.const_defined?(value) ? Object.const_get(value) : Object.const_missing(value)
|
63
|
-
end
|
64
53
|
end
|
65
54
|
end
|
66
55
|
end
|
data/lib/dbee/version.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
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
|
+
require 'spec_helper'
|
11
|
+
|
12
|
+
describe Dbee::ConstantResolver do
|
13
|
+
module A
|
14
|
+
class B; end
|
15
|
+
class E; end
|
16
|
+
end
|
17
|
+
|
18
|
+
class B; end
|
19
|
+
|
20
|
+
module C
|
21
|
+
class D; end
|
22
|
+
class E; end
|
23
|
+
|
24
|
+
module F
|
25
|
+
class G; end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'resolves nested constant with the same as an ancestor constants sibling' do
|
30
|
+
expect(subject.constantize('A::B')).to eq(::A::B)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'resolves root constant' do
|
34
|
+
expect(subject.constantize('B')).to eq(::B)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'does not resolve constant in a different parent module' do
|
38
|
+
expect { subject.constantize('C::B') }.to raise_error(NameError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'does not resolve constant in a different parent module' do
|
42
|
+
expect { subject.constantize('D') }.to raise_error(NameError)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'resolves same leaf constants specific to their parents' do
|
46
|
+
expect(subject.constantize('A::E')).to eq(::A::E)
|
47
|
+
expect(subject.constantize('C::E')).to eq(::C::E)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'does not resolve constant without its parent' do
|
51
|
+
expect { subject.constantize('F') }.to raise_error(NameError)
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Ruggio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: acts_as_hashable
|
@@ -106,14 +106,14 @@ dependencies:
|
|
106
106
|
requirements:
|
107
107
|
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0.
|
109
|
+
version: 0.79.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: 0.
|
116
|
+
version: 0.79.0
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
118
|
name: simplecov
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,14 +134,14 @@ dependencies:
|
|
134
134
|
requirements:
|
135
135
|
- - "~>"
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version: 0.
|
137
|
+
version: 0.6.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.
|
144
|
+
version: 0.6.0
|
145
145
|
description: " Dbee provides a simple-to-use data modeling and query API. The
|
146
146
|
query API can produce SQL using other ORMs, such as Arel/ActiveRecord. The targeted
|
147
147
|
use-case for Dbee is ad-hoc reporting, so the total SQL feature-set that Dbee supports
|
@@ -169,6 +169,7 @@ files:
|
|
169
169
|
- dbee.gemspec
|
170
170
|
- lib/dbee.rb
|
171
171
|
- lib/dbee/base.rb
|
172
|
+
- lib/dbee/constant_resolver.rb
|
172
173
|
- lib/dbee/dsl/association.rb
|
173
174
|
- lib/dbee/dsl/association_builder.rb
|
174
175
|
- lib/dbee/dsl/methods.rb
|
@@ -203,6 +204,7 @@ files:
|
|
203
204
|
- lib/dbee/query/sorters/descending.rb
|
204
205
|
- lib/dbee/version.rb
|
205
206
|
- spec/dbee/base_spec.rb
|
207
|
+
- spec/dbee/constant_resolver_spec.rb
|
206
208
|
- spec/dbee/key_chain_spec.rb
|
207
209
|
- spec/dbee/key_path_spec.rb
|
208
210
|
- spec/dbee/model/constraints/base_spec.rb
|
@@ -247,6 +249,7 @@ specification_version: 4
|
|
247
249
|
summary: Adhoc Reporting SQL Generator
|
248
250
|
test_files:
|
249
251
|
- spec/dbee/base_spec.rb
|
252
|
+
- spec/dbee/constant_resolver_spec.rb
|
250
253
|
- spec/dbee/key_chain_spec.rb
|
251
254
|
- spec/dbee/key_path_spec.rb
|
252
255
|
- spec/dbee/model/constraints/base_spec.rb
|