annotato 0.2.1 → 0.2.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/Gemfile.lock +1 -1
- data/lib/annotato/column_formatter.rb +12 -4
- data/lib/annotato/trigger_formatter.rb +22 -5
- data/lib/annotato/version.rb +1 -1
- data/lib/annotato/wrap_helper.rb +1 -1
- 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: 3f4f23141ac1d1c1d74db46f6e08a7897f013145cecedf862bf0daf1d5cf0e7c
|
|
4
|
+
data.tar.gz: 1b6c975c452b3673e346aed16aef4574bd7ccabd6cd1b1a4a01140e6b18e3a69
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9f3e75090cc665121ecb20fd2ae0c626f10fd3572f7f25a35559130769e6a8093226f94e6c9b43eec88b51dd148c00401fd74687f36b7d8bc62e39532ac672ce
|
|
7
|
+
data.tar.gz: 6faa3c85c724fb087868ab7768699bdf6f5f07aa943362367110680899b7eb69842e7ebab396cfc3f6e17b3d70cc0bff1e7c3d83335601b0475452d1a3ca4e71
|
data/Gemfile.lock
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "json"
|
|
4
|
+
require_relative "wrap_helper"
|
|
4
5
|
|
|
5
6
|
module Annotato
|
|
6
7
|
class ColumnFormatter
|
|
8
|
+
extend WrapHelper
|
|
9
|
+
|
|
7
10
|
# Main entry: returns an array of comment lines per column, flattened.
|
|
8
11
|
def self.format(model, connection)
|
|
9
12
|
table_name = model.table_name
|
|
@@ -57,10 +60,15 @@ module Annotato
|
|
|
57
60
|
lines << closing
|
|
58
61
|
lines
|
|
59
62
|
else
|
|
60
|
-
# single-line comment
|
|
61
|
-
|
|
62
|
-
line
|
|
63
|
-
|
|
63
|
+
# single-line comment; wrap options onto continuation line if too long
|
|
64
|
+
opts_str = opts.join(", ")
|
|
65
|
+
line = opts_str.empty? ? left : "#{left} #{opts_str}"
|
|
66
|
+
if line.length > WrapHelper::MAX_LINE && !opts_str.empty?
|
|
67
|
+
cont_indent = " " * (left.length + 1)
|
|
68
|
+
[left, "# #{cont_indent}#{opts_str}"]
|
|
69
|
+
else
|
|
70
|
+
[line.rstrip]
|
|
71
|
+
end
|
|
64
72
|
end
|
|
65
73
|
end
|
|
66
74
|
end
|
|
@@ -3,11 +3,28 @@
|
|
|
3
3
|
module Annotato
|
|
4
4
|
class TriggerFormatter
|
|
5
5
|
def self.format(conn, table_name)
|
|
6
|
-
conn.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
rows = case conn.adapter_name.downcase
|
|
7
|
+
when "postgresql"
|
|
8
|
+
conn.exec_query(
|
|
9
|
+
"SELECT tgname AS name FROM pg_trigger WHERE tgrelid = $1::regclass AND NOT tgisinternal",
|
|
10
|
+
"SQL", [table_name]
|
|
11
|
+
)
|
|
12
|
+
when "mysql2", "mysql", "trilogy"
|
|
13
|
+
conn.exec_query(
|
|
14
|
+
"SELECT TRIGGER_NAME AS name FROM information_schema.TRIGGERS " \
|
|
15
|
+
"WHERE EVENT_OBJECT_SCHEMA = DATABASE() AND EVENT_OBJECT_TABLE = ?",
|
|
16
|
+
"SQL", [table_name]
|
|
17
|
+
)
|
|
18
|
+
when "sqlite3"
|
|
19
|
+
conn.exec_query(
|
|
20
|
+
"SELECT name FROM sqlite_master WHERE type = 'trigger' AND tbl_name = ?",
|
|
21
|
+
"SQL", [table_name]
|
|
22
|
+
)
|
|
23
|
+
else
|
|
24
|
+
return []
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
rows.map { |r| "# #{r['name']}" }
|
|
11
28
|
end
|
|
12
29
|
end
|
|
13
30
|
end
|
data/lib/annotato/version.rb
CHANGED
data/lib/annotato/wrap_helper.rb
CHANGED