dbee 1.0.2 → 1.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e07996f0622fbf3eb19b8fa7bdd6ebfe963d3edc18745ccdf89f2a87f7a16dd
4
- data.tar.gz: 0e25d666b9cd0a099741220caf423a670e832149bac26f27283c7a43987c14c5
3
+ metadata.gz: aac48262d54b0524c4c8ecbe241ec9896478f7b02917376b835b64a75f6401bb
4
+ data.tar.gz: 94285e874df6c27cabd1c212b3456ce77351ee91c34c58bbfc430c1c8183667f
5
5
  SHA512:
6
- metadata.gz: 5290d4c90695c68b7d558c35cf4ca47cd24d60e50fc776ce2c4138a74d469e86bc9021d66a9645ddcb0e25924cad80d1dca239df610a1c01a41c02523159062e
7
- data.tar.gz: b9023ad0e9a82db914a0c0c40b918fd52a87572718aadc31e82eb1ba96adbd7a8a50932d9d1968b72d73de9689f26d4ca71374e4a7c2fcba416fd5f4e992c696
6
+ metadata.gz: 893af6c116b4687dd80bd4f25c96c991950bdfb799f3de590a33a9780c86ba287f4767c96ea8c6c1f10766c410a9be52fe29194c22ea29d30c9474c59acd4eff
7
+ data.tar.gz: 5863a68e275638f4b1d34c4326ed3b19b5ef433abed897e8f2bcbf5ec7eb536f5b54c8f666c1e339e49059bbc3ff2a6771b03db8cef6596bd76328b0ebe204e8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 1.0.3 (August 27th, 2019)
2
+
3
+ Additions:
4
+
5
+ * Added 'parent' keyword for static constraints. This makes it possible to have a static constraint apply to a parent and not just a child relationship.
6
+
1
7
  # 1.0.2 (August 26th, 2019)
2
8
 
3
9
  Fixes:
@@ -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
- raise ArgumentError, 'name is required' if name.to_s.empty?
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
- super(name: name)
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
- @parent = parent.to_s
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 static value.
16
- # It is usually used in conjunction with a ReferenceConstraint, further giving it more
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:, value: nil)
22
- super(name: name)
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
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module Dbee
11
- VERSION = '1.0.2'
11
+ VERSION = '1.0.3'
12
12
  end
@@ -16,20 +16,31 @@ describe Dbee::Model::Constraints::Base do
16
16
  end
17
17
 
18
18
  context '#initialize' do
19
- specify 'name is required' do
20
- expect { described_class.new(name: '') }.to raise_error(ArgumentError)
21
- expect { described_class.new(name: nil) }.to raise_error(ArgumentError)
22
- expect { described_class.new }.to raise_error(ArgumentError)
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) { { name: 'type' } }
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].to_s.hash)
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].hash}#{config[:parent]}".hash)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbee
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio