pg_graph 0.5.1 → 0.5.2
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/exe/pg_graph +2 -0
- data/lib/pg_graph/reflector.rb +16 -4
- data/lib/pg_graph/type/read.rb +2 -2
- data/lib/pg_graph/version.rb +1 -1
- 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: 38b9eb4ca9867310cda60284befd00b8819dd91ab0f337c053a47e2045c41f35
|
4
|
+
data.tar.gz: f4fe9a924423df0b43b3e0609ba3075e864902ff7a6e92d1c7d2baf522065f31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f057d02742170bfb37e2fc93e6c1419c65ca8081e8543c33c497e29efa82598c9cb82ef10b3359143b7ad56482328de8c8b8e59b75749f89df940b355fe874f9
|
7
|
+
data.tar.gz: 37e9bc383ef07636a85740dd73350ba7dacd8b67036250b0959b41b31f4d91afef540f8ae4b841dbbbc513b50bd5b439e1b63230175a407d00cfd364302418a0
|
data/exe/pg_graph
CHANGED
@@ -11,6 +11,8 @@ include ShellOpts
|
|
11
11
|
SPEC = %(
|
12
12
|
@ Load, dump, and clean databases
|
13
13
|
|
14
|
+
-- DATABASE
|
15
|
+
|
14
16
|
pg_graph is a utility that uses the PgGraph module to load, dump, or clean a
|
15
17
|
database. It uses a variety of formats that can be executed by psql(1)
|
16
18
|
('psql') or by the Postgres library exec() call ('exec', 'sql'). It can also
|
data/lib/pg_graph/reflector.rb
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
require 'constrain'
|
3
3
|
require 'indented_io'
|
4
4
|
|
5
|
+
def putv(*variables)
|
6
|
+
for var in Array(variables)
|
7
|
+
puts "#{var}: #{self.send(var).inspect}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
5
11
|
module PgGraph
|
6
12
|
class Reflection
|
7
13
|
# Textual representation of match RE (String)
|
@@ -41,6 +47,11 @@ module PgGraph
|
|
41
47
|
# True if this is a default reflection
|
42
48
|
attr_reader :default_reflection
|
43
49
|
|
50
|
+
def dump
|
51
|
+
puts "Reflection"
|
52
|
+
indent { putv :match, :re, :this, :that, :multi?, :pluralize, :components }
|
53
|
+
end
|
54
|
+
|
44
55
|
# +this+ and +that+ are template strings, nil, or false
|
45
56
|
def initialize(match, this, that, multi = nil, pluralize = nil, default_reflection = false)
|
46
57
|
constrain match, Regexp, String
|
@@ -141,10 +152,11 @@ module PgGraph
|
|
141
152
|
|
142
153
|
# Find 'that' field name for the given UID by searching through reflections
|
143
154
|
# for a match. The name is pluralized if the matcher returns true or if the
|
144
|
-
# matcher returns nil and unique is false The :table option can be used to
|
155
|
+
# matcher returns nil and unique is false. The :table option can be used to
|
145
156
|
# override the table name in '$$' rules. This is used in N:M and M:M
|
146
|
-
# relations. Returns
|
147
|
-
#
|
157
|
+
# relations. Returns false if the :that property is set to false in the
|
158
|
+
# reflections file. Returns nil if no match was found or if a matching
|
159
|
+
# reflection has #continue equal to false
|
148
160
|
def that(uid, unique, multi = false, table: nil)
|
149
161
|
constrain uid, String
|
150
162
|
if (name, pluralize = do_match(uid, :that, multi, table: table))
|
@@ -240,7 +252,7 @@ module PgGraph
|
|
240
252
|
match_data = reflection.re.match(uid) or next
|
241
253
|
template = reflection.send(kind).dup
|
242
254
|
if template == false
|
243
|
-
return
|
255
|
+
return [false, false]
|
244
256
|
elsif template
|
245
257
|
table ||= uid.split(".")[-2]
|
246
258
|
template.gsub!(/\$\$/, table)
|
data/lib/pg_graph/type/read.rb
CHANGED
@@ -144,10 +144,10 @@ module PgGraph::Type
|
|
144
144
|
else
|
145
145
|
multi = reference_count[this_record_type][that_record_type] > 1
|
146
146
|
name = reflector.that(uid, this_column.unique?, multi, table: this_record_type.name)
|
147
|
-
name ||= PgGraph.inflector.pluralize(this_column.table.name) if this_column.kind?
|
147
|
+
name ||= PgGraph.inflector.pluralize(this_column.table.name) if name.nil? && this_column.kind?
|
148
148
|
end
|
149
149
|
|
150
|
-
next if name
|
150
|
+
next if !name
|
151
151
|
|
152
152
|
# Check for name collisions
|
153
153
|
if that_record_type.key?(name)
|
data/lib/pg_graph/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_graph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claus Rasmussen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: boolean
|