dbee 1.0.0 → 1.0.1

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: dab2bf5eb7197181b4683180b3a3c490621d8e9fb58ee6d0edc99f39be1709ec
4
- data.tar.gz: e20fc2c2d02819aa2659847c795878ee7c23a1798d5a27b4e220320987016692
3
+ metadata.gz: bc7bf9701c14a96bfe5c83893637a1e10545e70f268c674851279d150b57bcc4
4
+ data.tar.gz: 1fbdb14e73fe98629a2cf41db0906b543eb33d16e044d5c8552916c76d4e9e8d
5
5
  SHA512:
6
- metadata.gz: c55baaace5f9e37d4d71a2465780ef60b20d06956ab27b45d9d91bc841757f4d393b05cfc757aead9f6acd4225b3b06a55b5521b78f6686e42cc4391fc9f72db
7
- data.tar.gz: 96bcb8c21d3974b4d46608e3e80658bd6608dc588d781da4676ea335bc8dc75ffc7f6dd202e691bbc905589f3f81e8a2b00e9f770a1d21a58de1729382f0b3e2
6
+ metadata.gz: 6ecaedc494e15776f1716de8891dd528fcbbbb76e44d6fe4d3056ab70674ede17f029f5316c171680c9265074624de8d78cf8856957fa5242371c26e41297089
7
+ data.tar.gz: e091625f6c6281673c48df689a1ec3ec692898799f9ef76d28991c90c519526bcd3c09d19d0cd1ce72a1df35bc98b5f81b46b01ec25934b4aa7ea86635549d1e
@@ -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.
@@ -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.each_with_object([]) do |config, memo|
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
 
@@ -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
@@ -21,6 +21,7 @@ module Dbee
21
21
 
22
22
  register 'reference', Reference
23
23
  register 'static', Static
24
+ register '', Reference # When type is not present this will be the default
24
25
  end
25
26
  end
26
27
  end
@@ -22,6 +22,10 @@ module Dbee
22
22
  @name = name.to_s
23
23
  end
24
24
 
25
+ def <=>(other)
26
+ other.name <=> name
27
+ end
28
+
25
29
  def hash
26
30
  name.hash
27
31
  end
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module Dbee
11
- VERSION = '1.0.0'
11
+ VERSION = '1.0.1'
12
12
  end
@@ -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: { type: :reference, name: :member_id, parent: :id }
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
@@ -5,11 +5,9 @@ Theaters, Members, and Movies:
5
5
  - name: members
6
6
  table: members
7
7
  constraints:
8
- - type: reference
9
- parent: id
8
+ - parent: id
10
9
  name: tid
11
- - type: reference
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.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-22 00:00:00.000000000 Z
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