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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad60c697f9ee0213951d02981190dee26a8db0a2e48ab36d3118c1aaf95d4d40
4
- data.tar.gz: 43a5f89b6509a636d579416c92bbbc52c63e15b8029701b46c525bd651a049a1
3
+ metadata.gz: 3f4f23141ac1d1c1d74db46f6e08a7897f013145cecedf862bf0daf1d5cf0e7c
4
+ data.tar.gz: 1b6c975c452b3673e346aed16aef4574bd7ccabd6cd1b1a4a01140e6b18e3a69
5
5
  SHA512:
6
- metadata.gz: 7753fdc81bfc3568053c99f3f4f98107d0ca3b2ad1b64b127e19902e00f35a8b889b86b2219a431ea2dd673bab86000d0705b59d7a88ef1c68192be2cf012d3e
7
- data.tar.gz: d05dd1bb4dd969a77555c3685ab129a9f31a479c5d2f69ef80c9ed7971677c044bc918ec2fd7e1212bc90eb49e678acd306f8afe66d7c9b743ea3b9dc3b9e650
6
+ metadata.gz: 9f3e75090cc665121ecb20fd2ae0c626f10fd3572f7f25a35559130769e6a8093226f94e6c9b43eec88b51dd148c00401fd74687f36b7d8bc62e39532ac672ce
7
+ data.tar.gz: 6faa3c85c724fb087868ab7768699bdf6f5f07aa943362367110680899b7eb69842e7ebab396cfc3f6e17b3d70cc0bff1e7c3d83335601b0475452d1a3ca4e71
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.2)
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
@@ -57,10 +60,15 @@ module Annotato
57
60
  lines << closing
58
61
  lines
59
62
  else
60
- # single-line comment
61
- line = left
62
- line += " #{opts.join(', ')}" unless opts.empty?
63
- [line.rstrip]
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.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.2"
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serhii Bodnaruk