taql 0.5.0 → 0.6.0

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: a347baf32a9b92dccb94907b40b42d35d00a5f8929f5938842e774d0dfe810a6
4
- data.tar.gz: 261b1878bc277f27c9d803a675f7ccc085c71eea9639bcdcdd8e6d44b28d5c82
3
+ metadata.gz: 06cf2ffe64ba72577b6e68ca71d276a1470bba0660521d0df02e9aaff5722112
4
+ data.tar.gz: 452c4e96ea43fa3df92ee786d1b81116162c8ca97f067306e29cdfe44e98a6ab
5
5
  SHA512:
6
- metadata.gz: f0aa1e50f2e9adfcc0013fe53d2a16d44f1b67cb3204c14f86cdff0c30a6e5b213eb5710c1573aa8be0cc1080f057b77e050882b762d23fb1f86b6f5f8e14cdb
7
- data.tar.gz: 817431a4c417af5c022fc893e0e40b5c8501f0e1470f64e5049b0a916cf20c448d574b48e62562c5e4f2b15bf150724c8ad5aa0f72cc404c6cfd928bcc64c87b
6
+ metadata.gz: a9e418d460768051aefecb0445a4ae6233184099aed19f5295e9c709e755b0d02233136d0bdfdb514b8a397d8d0219ec4395ed0c6c65b13c85f33e556821eb61
7
+ data.tar.gz: 825def129c7a925b42b1656b10825928d6006ceb6be82e912cc40b34d594bf13316a0a9d0d80257ebf192f452a77b0db3520842707256635fb7d41763409f946
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.6.0] - 2026-07-18
4
+
5
+ - Extract shared `Formatter` base class from `Table` and `List`
6
+ - Unify ActiveRecord connection handling in `Taql.active_record_connection`
7
+ - Fix CLI to avoid the Rails 7.2+ `connection` deprecation warning
8
+ - Remove unused `Table#rows`, `#columns`, and `markdown` writer
9
+
3
10
  ## [0.5.0] - 2026-03-11
4
11
 
5
12
  - Auto-switch to vertical list layout when table exceeds terminal width
data/lib/taql/cli.rb CHANGED
@@ -15,7 +15,7 @@ module Taql
15
15
  def run
16
16
  silence { require environment_path }
17
17
 
18
- Taql.execute(*query, options, connection: ActiveRecord::Base.connection)
18
+ Taql.execute(*query, options, connection: Taql.active_record_connection)
19
19
  end
20
20
 
21
21
  private
@@ -0,0 +1,23 @@
1
+ module Taql
2
+ class Formatter
3
+ DASH = "-".freeze
4
+
5
+ def initialize(entries)
6
+ @entries = entries.map { |entry| entry.transform_values(&:to_s) }
7
+ end
8
+
9
+ def headers
10
+ @headers ||= entries.flat_map(&:keys).uniq
11
+ end
12
+
13
+ def print
14
+ output if entries.any?
15
+ end
16
+
17
+ alias_method :to_s, :print
18
+
19
+ private
20
+
21
+ attr_reader :entries
22
+ end
23
+ end
data/lib/taql/list.rb CHANGED
@@ -1,31 +1,22 @@
1
+ require_relative "formatter"
2
+
1
3
  module Taql
2
- class List
3
- DASH = "-".freeze
4
+ class List < Formatter
4
5
  PIPE = " | ".freeze
5
6
 
6
7
  def initialize(entries, terminal_width: nil)
7
- @entries = entries.map { |entry| entry.transform_values(&:to_s) }
8
+ super(entries)
8
9
  @terminal_width = terminal_width
9
10
  end
10
11
 
11
- def print
12
- output if entries.any?
13
- end
14
-
15
12
  private
16
13
 
17
- attr_reader :entries
18
-
19
- def headers
20
- @headers ||= entries.flat_map(&:keys).uniq
21
- end
22
-
23
14
  def max_header_width
24
15
  @max_header_width ||= headers.map(&:length).max
25
16
  end
26
17
 
27
18
  def divider_width
28
- @terminal_width&.finite? ? @terminal_width : 32
19
+ @terminal_width || 32
29
20
  end
30
21
 
31
22
  def output
@@ -35,7 +26,7 @@ module Taql
35
26
  end
36
27
 
37
28
  def separator
38
- DASH * divider_width
29
+ @separator ||= DASH * divider_width
39
30
  end
40
31
 
41
32
  def rows(entry)
@@ -43,7 +34,5 @@ module Taql
43
34
  "#{header.upcase.rjust(max_header_width)}#{PIPE}#{entry[header]}"
44
35
  end
45
36
  end
46
-
47
- alias_method :to_s, :print
48
37
  end
49
38
  end
data/lib/taql/railtie.rb CHANGED
@@ -6,16 +6,8 @@ module Taql
6
6
 
7
7
  initializer "taql.initialize" do
8
8
  ActiveSupport.on_load(:active_record) do
9
- Taql.default_connection = method(:connection)
9
+ Taql.default_connection = Taql.method(:active_record_connection)
10
10
  end
11
11
  end
12
-
13
- def self.connection
14
- pool.respond_to?(:lease_connection) ? pool.lease_connection : pool.connection
15
- end
16
-
17
- def self.pool
18
- ActiveRecord::Base.connection_pool
19
- end
20
12
  end
21
13
  end
data/lib/taql/table.rb CHANGED
@@ -1,53 +1,36 @@
1
+ require_relative "formatter"
2
+
1
3
  module Taql
2
- class Table
3
- DASH = "-".freeze
4
+ class Table < Formatter
4
5
  PLUS = "+".freeze
5
6
  SPACE = " ".freeze
6
7
  VERTICAL_BAR = "|".freeze
7
8
 
8
- attr_accessor :markdown
9
+ attr_reader :markdown
9
10
 
10
11
  def initialize(entries, markdown: false)
11
- @entries = entries.map { |entry| entry.transform_values(&:to_s) }
12
+ super(entries)
12
13
  @markdown = markdown
13
14
  end
14
15
 
15
16
  def table_width
16
- column_widths.sum + (3 * columns.count) + 1
17
+ column_widths.sum + (3 * headers.count) + 1
17
18
  end
18
19
 
19
20
  def body
20
21
  entries.map(&:values)
21
22
  end
22
23
 
23
- def columns
24
- @columns ||= headers.map do |header|
25
- [header, *entries.map { |entry| entry[header] }]
26
- end
27
- end
28
-
29
- def headers
30
- @headers ||= entries.flat_map(&:keys).uniq
31
- end
32
-
33
- def print
34
- output if entries.any?
35
- end
36
-
37
- def rows
38
- [headers, *body]
39
- end
40
-
41
24
  private
42
25
 
43
- attr_reader :entries
44
-
45
26
  def border
46
27
  separator unless markdown
47
28
  end
48
29
 
49
30
  def column_widths
50
- @column_widths ||= columns.map { |column| column.map(&:length).max }
31
+ @column_widths ||= headers.map do |header|
32
+ [header, *entries.map { |entry| entry[header] }].map(&:length).max
33
+ end
51
34
  end
52
35
 
53
36
  def edge
@@ -73,13 +56,11 @@ module Taql
73
56
  end
74
57
 
75
58
  def separator
76
- columns.map.with_index do |column, index|
77
- Array.new(column_widths[index] + 2, DASH).join
78
- end.then do |columns|
79
- [edge, columns.join(edge), edge].join
59
+ column_widths.map do |width|
60
+ DASH * (width + 2)
61
+ end.then do |segments|
62
+ [edge, segments.join(edge), edge].join
80
63
  end
81
64
  end
82
-
83
- alias_method :to_s, :print
84
65
  end
85
66
  end
data/lib/taql/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Taql
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/taql.rb CHANGED
@@ -17,19 +17,26 @@ module Taql
17
17
  end
18
18
  end
19
19
 
20
+ def active_record_connection
21
+ pool = ActiveRecord::Base.connection_pool
22
+ pool.respond_to?(:lease_connection) ? pool.lease_connection : pool.connection
23
+ end
24
+
20
25
  private
21
26
 
22
- def formatter(results, markdown: false)
27
+ def formatter(results, markdown:)
23
28
  table = Table.new(results, markdown: markdown)
24
- if !markdown && table.table_width > terminal_width
25
- List.new(results, terminal_width: terminal_width)
29
+ width = terminal_width
30
+
31
+ if !markdown && width && table.table_width > width
32
+ List.new(results, terminal_width: width)
26
33
  else
27
34
  table
28
35
  end
29
36
  end
30
37
 
31
38
  def terminal_width
32
- IO.console&.winsize&.last || Float::INFINITY
39
+ IO.console&.winsize&.last
33
40
  end
34
41
 
35
42
  def default_connection
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ariel Rzezak
@@ -29,6 +29,7 @@ files:
29
29
  - exe/taql
30
30
  - lib/taql.rb
31
31
  - lib/taql/cli.rb
32
+ - lib/taql/formatter.rb
32
33
  - lib/taql/list.rb
33
34
  - lib/taql/railtie.rb
34
35
  - lib/taql/table.rb
@@ -55,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
56
  - !ruby/object:Gem::Version
56
57
  version: '0'
57
58
  requirements: []
58
- rubygems_version: 4.0.3
59
+ rubygems_version: 4.0.14
59
60
  specification_version: 4
60
61
  summary: Tableize Rails SQL queries
61
62
  test_files: []