dbee 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/dbee/model/constraints/base.rb +7 -8
- data/lib/dbee/model/constraints/reference.rb +2 -12
- data/lib/dbee/model/constraints/static.rb +9 -5
- data/lib/dbee/version.rb +1 -1
- data/spec/dbee/model/constraints/base_spec.rb +17 -6
- data/spec/dbee/model/constraints/reference_spec.rb +1 -1
- data/spec/dbee/model/constraints/static_spec.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aac48262d54b0524c4c8ecbe241ec9896478f7b02917376b835b64a75f6401bb
|
4
|
+
data.tar.gz: 94285e874df6c27cabd1c212b3456ce77351ee91c34c58bbfc430c1c8183667f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 893af6c116b4687dd80bd4f25c96c991950bdfb799f3de590a33a9780c86ba287f4767c96ea8c6c1f10766c410a9be52fe29194c22ea29d30c9474c59acd4eff
|
7
|
+
data.tar.gz: 5863a68e275638f4b1d34c4326ed3b19b5ef433abed897e8f2bcbf5ec7eb536f5b54c8f666c1e339e49059bbc3ff2a6771b03db8cef6596bd76328b0ebe204e8
|
data/CHANGELOG.md
CHANGED
@@ -14,24 +14,23 @@ module Dbee
|
|
14
14
|
class Base
|
15
15
|
acts_as_hashable
|
16
16
|
|
17
|
-
attr_reader :name
|
17
|
+
attr_reader :name, :parent
|
18
18
|
|
19
|
-
def initialize(name:)
|
20
|
-
|
21
|
-
|
22
|
-
@name = name.to_s
|
19
|
+
def initialize(name: '', parent: '')
|
20
|
+
@name = name.to_s
|
21
|
+
@parent = parent.to_s
|
23
22
|
end
|
24
23
|
|
25
24
|
def <=>(other)
|
26
|
-
name <=> other.name
|
25
|
+
"#{name}#{parent}" <=> "#{other.name}#{other.parent}"
|
27
26
|
end
|
28
27
|
|
29
28
|
def hash
|
30
|
-
name.hash
|
29
|
+
"#{name}#{parent}".hash
|
31
30
|
end
|
32
31
|
|
33
32
|
def ==(other)
|
34
|
-
other.name == name
|
33
|
+
other.name == name && other.parent == parent
|
35
34
|
end
|
36
35
|
alias eql? ==
|
37
36
|
end
|
@@ -19,23 +19,13 @@ module Dbee
|
|
19
19
|
attr_reader :parent
|
20
20
|
|
21
21
|
def initialize(name:, parent:)
|
22
|
-
|
23
|
-
|
22
|
+
raise ArgumentError, 'name is required' if name.to_s.empty?
|
24
23
|
raise ArgumentError, 'parent is required' if parent.to_s.empty?
|
25
24
|
|
26
|
-
|
25
|
+
super(name: name, parent: parent)
|
27
26
|
|
28
27
|
freeze
|
29
28
|
end
|
30
|
-
|
31
|
-
def hash
|
32
|
-
"#{super}#{parent}".hash
|
33
|
-
end
|
34
|
-
|
35
|
-
def ==(other)
|
36
|
-
super && other.parent == parent
|
37
|
-
end
|
38
|
-
alias eql? ==
|
39
29
|
end
|
40
30
|
end
|
41
31
|
end
|
@@ -12,14 +12,18 @@ require_relative 'base'
|
|
12
12
|
module Dbee
|
13
13
|
class Model
|
14
14
|
class Constraints
|
15
|
-
# A static constraint is a equality constraint on a child column to a
|
16
|
-
# It is usually used in conjunction with a ReferenceConstraint,
|
17
|
-
# scoping.
|
15
|
+
# A static constraint is a equality constraint on a child and/or parent column to a
|
16
|
+
# static value. It is usually used in conjunction with a ReferenceConstraint,
|
17
|
+
# further giving it more scoping.
|
18
18
|
class Static < Base
|
19
19
|
attr_reader :value
|
20
20
|
|
21
|
-
def initialize(name
|
22
|
-
|
21
|
+
def initialize(name: '', parent: '', value: nil)
|
22
|
+
if name.to_s.empty? && parent.to_s.empty?
|
23
|
+
raise ArgumentError, "name (#{name}) and/or parent (#{parent}) required"
|
24
|
+
end
|
25
|
+
|
26
|
+
super(name: name, parent: parent)
|
23
27
|
|
24
28
|
@value = value
|
25
29
|
|
data/lib/dbee/version.rb
CHANGED
@@ -16,20 +16,31 @@ describe Dbee::Model::Constraints::Base do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
context '#initialize' do
|
19
|
-
|
20
|
-
expect
|
21
|
-
expect
|
22
|
-
expect
|
19
|
+
it 'sets name correctly' do
|
20
|
+
expect(described_class.new.name).to eq('')
|
21
|
+
expect(described_class.new(name: 123).name).to eq('123')
|
22
|
+
expect(described_class.new(name: 'abc').name).to eq('abc')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'sets parent correctly' do
|
26
|
+
expect(described_class.new.parent).to eq('')
|
27
|
+
expect(described_class.new(parent: 123).parent).to eq('123')
|
28
|
+
expect(described_class.new(parent: 'abc').parent).to eq('abc')
|
23
29
|
end
|
24
30
|
end
|
25
31
|
|
26
32
|
context 'equality' do
|
27
|
-
let(:config)
|
33
|
+
let(:config) do
|
34
|
+
{
|
35
|
+
name: 'NAME!',
|
36
|
+
parent: 'PARENT!'
|
37
|
+
}
|
38
|
+
end
|
28
39
|
|
29
40
|
subject { described_class.new(config) }
|
30
41
|
|
31
42
|
specify '#hash produces same output as string hash of name' do
|
32
|
-
expect(subject.hash).to eq(config[:name].
|
43
|
+
expect(subject.hash).to eq("#{config[:name]}#{config[:parent]}".hash)
|
33
44
|
end
|
34
45
|
|
35
46
|
specify '#== and #eql? compares attributes' do
|
@@ -24,7 +24,7 @@ describe Dbee::Model::Constraints::Reference do
|
|
24
24
|
subject { described_class.new(config) }
|
25
25
|
|
26
26
|
specify '#hash produces same output as concatenated string hash of name and parent' do
|
27
|
-
expect(subject.hash).to eq("#{config[:name]
|
27
|
+
expect(subject.hash).to eq("#{config[:name]}#{config[:parent]}".hash)
|
28
28
|
end
|
29
29
|
|
30
30
|
specify '#== and #eql? compare attributes' do
|
@@ -15,6 +15,14 @@ describe Dbee::Model::Constraints::Static do
|
|
15
15
|
|
16
16
|
subject { described_class.new(config) }
|
17
17
|
|
18
|
+
describe '#initialize' do
|
19
|
+
it 'requires either a name or parent' do
|
20
|
+
expect { described_class.new }.to raise_error(ArgumentError)
|
21
|
+
expect { described_class.new(name: '', parent: '') }.to raise_error(ArgumentError)
|
22
|
+
expect { described_class.new(name: nil, parent: nil) }.to raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
18
26
|
specify '#hash produces same output as concatenated string hash of name and parent' do
|
19
27
|
expect(subject.hash).to eq("#{config[:name].hash}#{config[:value]}".hash)
|
20
28
|
end
|