annotato 0.2.1 → 0.2.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: ad60c697f9ee0213951d02981190dee26a8db0a2e48ab36d3118c1aaf95d4d40
4
- data.tar.gz: 43a5f89b6509a636d579416c92bbbc52c63e15b8029701b46c525bd651a049a1
3
+ metadata.gz: d46bed9c8d25cf14624fc0381d1742eead5efd0777705e8a55044ac797e0625a
4
+ data.tar.gz: af4276aea78359e7feb0dff649b5a185fb6074e81cb287ee5dd724b329c2dbe1
5
5
  SHA512:
6
- metadata.gz: 7753fdc81bfc3568053c99f3f4f98107d0ca3b2ad1b64b127e19902e00f35a8b889b86b2219a431ea2dd673bab86000d0705b59d7a88ef1c68192be2cf012d3e
7
- data.tar.gz: d05dd1bb4dd969a77555c3685ab129a9f31a479c5d2f69ef80c9ed7971677c044bc918ec2fd7e1212bc90eb49e678acd306f8afe66d7c9b743ea3b9dc3b9e650
6
+ metadata.gz: f430a13536edb3f88e2bfcb414c08c7fa38e369cd78b17957940ff7f0366a5b2da4846814e21a65c11b208cff1874850a53180634a142a885e2834b3f6a56fdc
7
+ data.tar.gz: 7a8cca116a125eff5e994905bb2f2947a567a4146fe9f9a48b6116217d009eb3441ac5e3c109e008fb78c6db9fa439c63756cb5893bf642a4fa5c50ce837d0ac
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- annotato (0.2.1)
4
+ annotato (0.2.3)
5
5
  rails (>= 6.0)
6
6
 
7
7
  GEM
@@ -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
@@ -23,11 +26,12 @@ module Annotato
23
26
  type = col.sql_type
24
27
 
25
28
  # Build the left-hand side and calculate indent.
26
- left = "# %-#{name_width}s :%-#{type_width}s" % [name, type]
27
- # " default(" is 9 chars; +2 gives the extra gap.
29
+ # Strip trailing padding spaces immediately — output must never have trailing whitespace.
30
+ left = ("# %-#{name_width}s :%-#{type_width}s" % [name, type]).rstrip
31
+ # indent_size aligns multiline default content under the opening "default(" token.
28
32
  indent_size = left.length + 1
29
33
  indent_str = " " * indent_size
30
- closing_indent_str = " " * (indent_size - 2)
34
+ closing_indent_str = " " * (indent_size - 2)
31
35
 
32
36
  # Gather all options, pulling out default_lines if multiline.
33
37
  opts = []
@@ -57,10 +61,14 @@ module Annotato
57
61
  lines << closing
58
62
  lines
59
63
  else
60
- # single-line comment
61
- line = left
62
- line += " #{opts.join(', ')}" unless opts.empty?
63
- [line.rstrip]
64
+ # single-line comment; wrap options onto continuation line if too long
65
+ opts_str = opts.join(", ")
66
+ line = opts_str.empty? ? left : "#{left} #{opts_str}"
67
+ if line.length > WrapHelper::MAX_LINE && !opts_str.empty?
68
+ [left, "# #{opts_str}"]
69
+ else
70
+ [line]
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.exec_query(
7
- "SELECT tgname FROM pg_trigger WHERE tgrelid = $1::regclass AND NOT tgisinternal",
8
- "SQL",
9
- [table_name]
10
- ).map { |r| "# #{r['tgname']}" }
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Annotato
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.3"
5
5
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Annotato
4
4
  module WrapHelper
5
- MAX_LINE = 100
5
+ MAX_LINE = 120
6
6
 
7
7
  # Produces one or more lines, each already prefixed with "# "
8
8
  # First line: "# where (..."
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annotato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serhii Bodnaruk