dbee 1.0.0 → 1.0.1
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 +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/dbee/base.rb +10 -8
- data/lib/dbee/model.rb +6 -2
- data/lib/dbee/model/constraints.rb +1 -0
- data/lib/dbee/model/constraints/base.rb +4 -0
- data/lib/dbee/version.rb +1 -1
- data/spec/fixtures/models.rb +7 -5
- data/spec/fixtures/models.yaml +65 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc7bf9701c14a96bfe5c83893637a1e10545e70f268c674851279d150b57bcc4
|
4
|
+
data.tar.gz: 1fbdb14e73fe98629a2cf41db0906b543eb33d16e044d5c8552916c76d4e9e8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ecaedc494e15776f1716de8891dd528fcbbbb76e44d6fe4d3056ab70674ede17f029f5316c171680c9265074624de8d78cf8856957fa5242371c26e41297089
|
7
|
+
data.tar.gz: e091625f6c6281673c48df689a1ec3ec692898799f9ef76d28991c90c519526bcd3c09d19d0cd1ce72a1df35bc98b5f81b46b01ec25934b4aa7ea86635549d1e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
# 1.0.1 (August 26th, 2019)
|
2
|
+
|
3
|
+
Fixes:
|
4
|
+
|
5
|
+
* Dbee::Base sub-classes can now declare self-referential associations. Note that it will stop the hierarchy once the cycle is detected.
|
6
|
+
|
7
|
+
Additions:
|
8
|
+
|
9
|
+
* Static constraint is now the default type when type is omitted.
|
10
|
+
|
1
11
|
# 1.0.0 (August 22nd, 2019)
|
2
12
|
|
3
13
|
Initial release.
|
data/lib/dbee/base.rb
CHANGED
@@ -24,11 +24,11 @@ module Dbee
|
|
24
24
|
self
|
25
25
|
end
|
26
26
|
|
27
|
-
def to_model(name = nil, constraints = [])
|
27
|
+
def to_model(name = nil, constraints = [], from = nil)
|
28
28
|
name = derive_name(name)
|
29
|
-
key = [name, constraints]
|
29
|
+
key = [name, constraints, from]
|
30
30
|
|
31
|
-
to_models[key] ||= Model.make(model_config(name, constraints))
|
31
|
+
to_models[key] ||= Model.make(model_config(name, constraints, from))
|
32
32
|
end
|
33
33
|
|
34
34
|
def table_name
|
@@ -63,10 +63,10 @@ module Dbee
|
|
63
63
|
subclasses.reverse
|
64
64
|
end
|
65
65
|
|
66
|
-
def model_config(name, constraints)
|
66
|
+
def model_config(name, constraints, from)
|
67
67
|
{
|
68
68
|
constraints: constraints,
|
69
|
-
models: associations,
|
69
|
+
models: associations(from),
|
70
70
|
name: name,
|
71
71
|
table: derive_table
|
72
72
|
}
|
@@ -82,13 +82,15 @@ module Dbee
|
|
82
82
|
inherited_table.empty? ? inflected_name : inherited_table
|
83
83
|
end
|
84
84
|
|
85
|
-
def associations
|
86
|
-
inherited_associations_by_name.values
|
85
|
+
def associations(from)
|
86
|
+
inherited_associations_by_name.values
|
87
|
+
.reject { |c| c[:name].to_s == from.to_s }
|
88
|
+
.each_with_object([]) do |config, memo|
|
87
89
|
model_klass = config[:model]
|
88
90
|
associated_constraints = config[:constraints]
|
89
91
|
name = config[:name]
|
90
92
|
|
91
|
-
memo << model_klass.to_model(name, associated_constraints)
|
93
|
+
memo << model_klass.to_model(name, associated_constraints, name)
|
92
94
|
end
|
93
95
|
end
|
94
96
|
|
data/lib/dbee/model.rb
CHANGED
@@ -69,11 +69,15 @@ module Dbee
|
|
69
69
|
def ==(other)
|
70
70
|
other.name == name &&
|
71
71
|
other.table == table &&
|
72
|
-
other.models == models &&
|
73
|
-
other.constraints == constraints
|
72
|
+
other.models.sort == models.sort &&
|
73
|
+
other.constraints.sort == constraints.sort
|
74
74
|
end
|
75
75
|
alias eql? ==
|
76
76
|
|
77
|
+
def <=>(other)
|
78
|
+
other.name <=> name
|
79
|
+
end
|
80
|
+
|
77
81
|
private
|
78
82
|
|
79
83
|
attr_reader :models_by_name
|
data/lib/dbee/version.rb
CHANGED
data/spec/fixtures/models.rb
CHANGED
@@ -17,7 +17,6 @@ module Models
|
|
17
17
|
class Demographics < Dbee::Base
|
18
18
|
association :phone_numbers, model: PhoneNumbers,
|
19
19
|
constraints: {
|
20
|
-
type: :reference,
|
21
20
|
name: :demographic_id,
|
22
21
|
parent: :id
|
23
22
|
}
|
@@ -28,7 +27,7 @@ module Models
|
|
28
27
|
constraints: { type: :reference, name: :member_id, parent: :id }
|
29
28
|
|
30
29
|
association :movies, model: Movies,
|
31
|
-
constraints: {
|
30
|
+
constraints: { name: :member_id, parent: :id }
|
32
31
|
end
|
33
32
|
|
34
33
|
class Members < MembersBase
|
@@ -49,15 +48,18 @@ module Models
|
|
49
48
|
end
|
50
49
|
|
51
50
|
class TheatersBase < Dbee::Base
|
52
|
-
end
|
53
|
-
|
54
|
-
class Theaters < TheatersBase
|
55
51
|
association :members, model: Members, constraints: [
|
56
52
|
{ type: :reference, name: :tid, parent: :id },
|
57
53
|
{ type: :reference, name: :partition, parent: :partition }
|
58
54
|
]
|
59
55
|
end
|
60
56
|
|
57
|
+
class Theaters < TheatersBase
|
58
|
+
association :parent_theater, model: self, constraints: [
|
59
|
+
{ type: :reference, name: :parent_theater_id, parent: :id }
|
60
|
+
]
|
61
|
+
end
|
62
|
+
|
61
63
|
class A < Dbee::Base
|
62
64
|
table 'table_set_to_a'
|
63
65
|
end
|
data/spec/fixtures/models.yaml
CHANGED
@@ -5,11 +5,9 @@ Theaters, Members, and Movies:
|
|
5
5
|
- name: members
|
6
6
|
table: members
|
7
7
|
constraints:
|
8
|
-
-
|
9
|
-
parent: id
|
8
|
+
- parent: id
|
10
9
|
name: tid
|
11
|
-
-
|
12
|
-
parent: partition
|
10
|
+
- parent: partition
|
13
11
|
name: partition
|
14
12
|
models:
|
15
13
|
- name: demos
|
@@ -58,6 +56,69 @@ Theaters, Members, and Movies:
|
|
58
56
|
- type: static
|
59
57
|
name: genre
|
60
58
|
value: comedy
|
59
|
+
- name: parent_theater
|
60
|
+
table: theaters
|
61
|
+
constraints:
|
62
|
+
- type: reference
|
63
|
+
name: parent_theater_id
|
64
|
+
parent: id
|
65
|
+
models:
|
66
|
+
- name: members
|
67
|
+
table: members
|
68
|
+
constraints:
|
69
|
+
- type: reference
|
70
|
+
parent: id
|
71
|
+
name: tid
|
72
|
+
- type: reference
|
73
|
+
parent: partition
|
74
|
+
name: partition
|
75
|
+
models:
|
76
|
+
- name: demos
|
77
|
+
table: demographics
|
78
|
+
constraints:
|
79
|
+
- type: reference
|
80
|
+
parent: id
|
81
|
+
name: member_id
|
82
|
+
models:
|
83
|
+
- name: phone_numbers
|
84
|
+
table: phone_numbers
|
85
|
+
constraints:
|
86
|
+
- type: reference
|
87
|
+
parent: id
|
88
|
+
name: demographic_id
|
89
|
+
- name: movies
|
90
|
+
table: movies
|
91
|
+
constraints:
|
92
|
+
- type: reference
|
93
|
+
parent: id
|
94
|
+
name: member_id
|
95
|
+
- name: favorite_comic_movies
|
96
|
+
table: movies
|
97
|
+
constraints:
|
98
|
+
- type: reference
|
99
|
+
parent: id
|
100
|
+
name: member_id
|
101
|
+
- type: static
|
102
|
+
name: genre
|
103
|
+
value: comic
|
104
|
+
- name: favorite_mystery_movies
|
105
|
+
table: movies
|
106
|
+
constraints:
|
107
|
+
- type: reference
|
108
|
+
parent: id
|
109
|
+
name: member_id
|
110
|
+
- type: static
|
111
|
+
name: genre
|
112
|
+
value: mystery
|
113
|
+
- name: favorite_comedy_movies
|
114
|
+
table: movies
|
115
|
+
constraints:
|
116
|
+
- type: reference
|
117
|
+
parent: id
|
118
|
+
name: member_id
|
119
|
+
- type: static
|
120
|
+
name: genre
|
121
|
+
value: comedy
|
61
122
|
Readme:
|
62
123
|
name: practices
|
63
124
|
models:
|
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: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Ruggio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: acts_as_hashable
|