nazar 1.1.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2689adb3080ba628ef27ab5ce71804352ccb02b2a90dbf363a50373210f7b2bd
4
- data.tar.gz: e8a4f1954eb5d67a62e1f54d4a9983f7d2cb034903bd24d5a7d2dfed626d0808
3
+ metadata.gz: 0d6d959973fd00cf0d233b01f69c7cd4bbd08889bc2251427ab855d24e13ce42
4
+ data.tar.gz: 233302d7d8b97a7299763c8f3ef70bb7182f34094f22033cc22a0781fa08379b
5
5
  SHA512:
6
- metadata.gz: ee1752541ac4356428bce4298bb5a6ff011b83943784ed0727adeec0c82b9763465944324dd8672d5cfb27e0a28e05e44f2dc796a9a28d5459086804b5c1a7c4
7
- data.tar.gz: 7eb125d122b3c424251eb6ef76554d5737d24509659d12c1414cab0ad48fb59f790b63a0c8cf264273b10f3786efb7b1397db2549a3ef4dc8af6963ef4e7e62c
6
+ metadata.gz: ab38635347ebc90e8439b8a59af77b52c38f90a73a58dfd347506e6b2c1c923b4e0a8f890bad5de1d1554eb9612871b14577bc26ca264dd36db3b391b645841b
7
+ data.tar.gz: 0b0f71f05886d5b65728ab935c0ae3bbcce5ee3411e4eeadb7639e30ec0133a3c6e023127ca6b981ee075db1a60819c2a9f2cf9ea78c2174c6dd86fd021abbc8
data/.rubocop.yml CHANGED
@@ -6,6 +6,8 @@ Style/SymbolArray:
6
6
  EnforcedStyle: brackets
7
7
  Style/WordArray:
8
8
  EnforcedStyle: brackets
9
+ Style/OpenStructUse:
10
+ Enabled: false
9
11
  Metrics/BlockLength:
10
12
  Exclude:
11
13
  - 'spec/**/*_spec.rb'
@@ -15,3 +17,5 @@ Layout/EndAlignment:
15
17
  EnforcedStyleAlignWith: variable
16
18
  Layout/FirstArrayElementIndentation:
17
19
  EnforcedStyle: consistent
20
+ Gemspec/DevelopmentDependencies:
21
+ Enabled: false
data/README.md CHANGED
@@ -240,9 +240,10 @@ You can also configure behaviour of Nazar:
240
240
  | `Nazar.config.formatter.layout` | `:auto` | Determines which layout should be used. See <a href="#layouts">Layouts</a> for more details |
241
241
  | `Nazar.config.formatter.paginate` | `true` | Determines if results too long/wide should be printed directly, or paginated with `less`. Horizontal layout is always paginated.
242
242
  | `Nazar.config.formatter.boolean` | ['✓', '✗'] | First item in array is a character for `true`, second for `false` |
243
- | `Nazar.config.formatter.resize` | `true` | Determines if the table should always be resized to take full width |
244
243
  | `Nazar.config.enable_shorthand_method` | true | Determines if shorthand method should be defined. See <a href="#opt-in-setup">Opt-in setup</a> for more details |
245
-
244
+ | `Nazar.config.table.resize` | `true` | Determines if the table should always be resized to take full width |
245
+ | `Nazar.config.table.min_width` | `nil` | Sets minimum width. By default uses the longest header length |
246
+ | `Nazar.config.table.max_width` | `nil` | Determines maximum table width. If `resize` is set to true, uses terminal width by default, otherwise uses content length |
246
247
  ## Contributing
247
248
 
248
249
  Bug reports and pull requests are welcome on GitHub at https://github.com/krzyzak/nazar.
@@ -25,7 +25,7 @@ module Nazar
25
25
  end
26
26
 
27
27
  def resize
28
- Nazar.config.formatter.resize
28
+ Nazar.config.table.resize
29
29
  end
30
30
 
31
31
  def summary_row(value)
@@ -16,6 +16,8 @@ module Nazar
16
16
  end
17
17
 
18
18
  def self.valid?(data)
19
+ return false if data.is_a?(Struct) || (defined?(OpenStruct) && data.is_a?(OpenStruct))
20
+
19
21
  data.is_a?(ActiveRecord::Associations::CollectionProxy) ||
20
22
  data.is_a?(ActiveRecord::Relation) ||
21
23
  (data.is_a?(Enumerable) && data.first.is_a?(ActiveRecord::Base))
@@ -27,10 +27,10 @@ module Nazar
27
27
  end
28
28
 
29
29
  def self.valid?(data)
30
- item = data&.first
31
- compatible = item.respond_to?(:keys) && item.respond_to?(:values)
30
+ return false unless data.is_a?(Enumerable)
32
31
 
33
- data.is_a?(Enumerable) && (item.is_a?(Struct) || compatible)
32
+ item = data&.first
33
+ item.respond_to?(:keys) && item.respond_to?(:values)
34
34
  end
35
35
 
36
36
  def valid?
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nazar
4
+ module Formatter
5
+ class Struct
6
+ def initialize(item)
7
+ @collection = Array(item)
8
+ @attributes = item.to_h.keys
9
+ @item = item
10
+ end
11
+
12
+ def self.valid?(data)
13
+ data.is_a?(::Struct) || data.is_a?(::OpenStruct)
14
+ end
15
+
16
+ def valid?
17
+ true
18
+ end
19
+
20
+ def headers
21
+ HeadersFormatter.new(attributes).format
22
+ end
23
+
24
+ def cells
25
+ @cells ||= @collection.map do |item|
26
+ item.each_pair do |_, value|
27
+ CellFormatter.new(value, type: nil).format
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -3,7 +3,7 @@
3
3
  module Nazar
4
4
  class HorizontalTable < BaseTable
5
5
  def render
6
- table.render(:unicode, border: { separator: :each_row }, multiline: true, resize: resize)
6
+ table.render(:unicode, options)
7
7
  end
8
8
 
9
9
  private
@@ -11,5 +11,11 @@ module Nazar
11
11
  def summary_row(value)
12
12
  super.fill(nil, 3, table.columns_size - 3)
13
13
  end
14
+
15
+ def options
16
+ { border: { separator: :each_row }, multiline: true, resize: resize }.tap do |hash|
17
+ hash[:width] = Nazar.config.table.max_width if Nazar.config.table.max_width
18
+ end
19
+ end
14
20
  end
15
21
  end
data/lib/nazar/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nazar
4
- VERSION = '1.1.0'
4
+ VERSION = '1.3.0'
5
5
  end
@@ -23,7 +23,7 @@ module Nazar
23
23
  end
24
24
 
25
25
  def render
26
- table.render_with(VerticalBorder, multiline: true, resize: resize) do |renderer|
26
+ table.render_with(VerticalBorder, options) do |renderer|
27
27
  renderer.border.style = :green if Nazar.config.colors.enabled
28
28
  renderer.border.separator = separators_around_each_item
29
29
  end
@@ -37,6 +37,15 @@ module Nazar
37
37
  @table ||= TTY::Table.new(rows: cells)
38
38
  end
39
39
 
40
+ def options
41
+ {
42
+ multiline: true,
43
+ resize: resize,
44
+ column_widths: column_widths,
45
+ width: max_width
46
+ }
47
+ end
48
+
40
49
  def cells
41
50
  @cells.flat_map do |cell|
42
51
  cell.map.with_index do |item, index|
@@ -50,5 +59,43 @@ module Nazar
50
59
  (i % headers.size).zero? || ((i + 1) % headers.size).zero?
51
60
  end
52
61
  end
62
+
63
+ def column_widths
64
+ [headers_width, values_width]
65
+ end
66
+
67
+ def max_width
68
+ Nazar.config.table.max_width || default_width
69
+ end
70
+
71
+ def default_width
72
+ Nazar.config.table.resize ? TTY::Screen.width : natural_width + padding
73
+ end
74
+
75
+ def natural_width
76
+ content_size = headers_width + content_width
77
+
78
+ [content_size, TTY::Screen.width].min
79
+ end
80
+
81
+ def content_width
82
+ cells.flatten.map(&:size).max
83
+ end
84
+
85
+ def headers_width
86
+ [headers.map(&:size).max + 1, Nazar.config.table.min_width].compact.min
87
+ end
88
+
89
+ def values_width
90
+ if Nazar.config.table.resize
91
+ TTY::Screen.width - headers_width
92
+ else
93
+ [content_width, TTY::Screen.width - headers_width].min
94
+ end
95
+ end
96
+
97
+ def padding
98
+ 3
99
+ end
53
100
  end
54
101
  end
data/lib/nazar.rb CHANGED
@@ -24,7 +24,12 @@ module Nazar # rubocop:disable Metrics/ModuleLength
24
24
  setting :boolean, default: ['✓', '✗']
25
25
  setting :layout, default: :auto
26
26
  setting :paginate, default: true
27
+ end
28
+
29
+ setting :table do
27
30
  setting :resize, default: true
31
+ setting :min_width, default: nil
32
+ setting :max_width, default: nil
28
33
  end
29
34
 
30
35
  setting :colors do
@@ -33,12 +38,12 @@ module Nazar # rubocop:disable Metrics/ModuleLength
33
38
 
34
39
  setting :enable_shorthand_method, default: true
35
40
 
36
- class << self
41
+ class << self # rubocop:disable Metrics/ClassLength
37
42
  def formatters
38
43
  @formatters ||= Set.new
39
44
  end
40
45
 
41
- def enable!(extensions: [:active_record, :csv])
46
+ def enable!(extensions: [:active_record, :csv, :struct])
42
47
  return if @enabled
43
48
 
44
49
  load_extensions!(extensions)
@@ -62,6 +67,12 @@ module Nazar # rubocop:disable Metrics/ModuleLength
62
67
  register_formatter!('CSVTable', 'nazar/formatter/csv_table')
63
68
  end
64
69
 
70
+ def load_struct!
71
+ require 'ostruct'
72
+
73
+ register_formatter!('Struct', 'nazar/formatter/struct')
74
+ end
75
+
65
76
  def load_active_record!
66
77
  require 'active_record'
67
78
 
@@ -108,6 +119,7 @@ module Nazar # rubocop:disable Metrics/ModuleLength
108
119
  def load_extensions!(extensions)
109
120
  load_active_record! if extensions.include?(:active_record)
110
121
  load_csv! if extensions.include?(:csv)
122
+ load_struct! if extensions.include?(:struct)
111
123
  load_sequel! if extensions.include?(:sequel)
112
124
  end
113
125
 
data/nazar.gemspec CHANGED
@@ -25,9 +25,6 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ['lib']
27
27
 
28
- spec.cert_chain = ['certs/krzyzak.pem']
29
- spec.signing_key = File.expand_path('~/.ssh/gem-private_key.pem') if $PROGRAM_NAME =~ /gem\z/
30
-
31
28
  spec.add_development_dependency 'activerecord', '>= 3.0', '< 6.2'
32
29
  spec.add_development_dependency 'rubocop', '~> 1.21'
33
30
  spec.add_development_dependency 'sequel', '~> 5.0'
metadata CHANGED
@@ -1,42 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nazar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michał Krzyżanowski
8
8
  autorequire:
9
9
  bindir: exe
10
- cert_chain:
11
- - |
12
- -----BEGIN CERTIFICATE-----
13
- MIIEgjCCAuqgAwIBAgIBATANBgkqhkiG9w0BAQsFADA1MTMwMQYDVQQDDCptaWNo
14
- YWwua3J6eXphbm93c2tpX2dpdGh1Yi9EQz1nbWFpbC9EQz1jb20wH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iErEXtKAExnxRefzWSHNm0WjXT/dIyFUbYQ
31
- rRnKtabxRNWtRIrK3GecPBDtAVTRtYQQkCaSwbwE37sHJhntS/Dvnl8pw2THq7ef
32
- XbhPDcqmP+yWRCszn9Hzda19+8VA6Sn+fIwevXMUgvb3VHqLYcIO2amHtnCeM8Q5
33
- caYBi+Tx9EDFh04EE4rbUGX25RcLO43j3ShLLqfW6QHFUtJIKS7WhgBVoEGvNA35
34
- 2KAZEiV7+ByRFKndeJmFtom0GMNBYPQW4l96aCrQJZyVhWSWGQZornxbH+hylJEp
35
- on5yD3vJbVQXzwm0Z4I1IH5xc4YbEepCQRK6u/cT6NuiQqbqeW82BxjXMPu4HVBy
36
- WXVb638bzH4OYBIYuGcw50jqBK1SyDx4exzThr6KxSiGwhAKj2xFqy51MIQjfUN0
37
- TL5B7Buq
38
- -----END CERTIFICATE-----
39
- date: 2022-10-12 00:00:00.000000000 Z
10
+ cert_chain: []
11
+ date: 2024-07-01 00:00:00.000000000 Z
40
12
  dependencies:
41
13
  - !ruby/object:Gem::Dependency
42
14
  name: activerecord
@@ -201,7 +173,6 @@ files:
201
173
  - Rakefile
202
174
  - bin/console
203
175
  - bin/setup
204
- - certs/krzyzak.pem
205
176
  - lib/nazar.rb
206
177
  - lib/nazar/base_table.rb
207
178
  - lib/nazar/cell_formatter.rb
@@ -214,6 +185,7 @@ files:
214
185
  - lib/nazar/formatter/sequel_collection.rb
215
186
  - lib/nazar/formatter/sequel_interface.rb
216
187
  - lib/nazar/formatter/sequel_item.rb
188
+ - lib/nazar/formatter/struct.rb
217
189
  - lib/nazar/headers_formatter.rb
218
190
  - lib/nazar/horizontal_table.rb
219
191
  - lib/nazar/renderer.rb
@@ -242,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
214
  - !ruby/object:Gem::Version
243
215
  version: '0'
244
216
  requirements: []
245
- rubygems_version: 3.1.6
217
+ rubygems_version: 3.4.6
246
218
  signing_key:
247
219
  specification_version: 4
248
220
  summary: Nazar is a tool that enhances default IRB/Pry inspect output
checksums.yaml.gz.sig DELETED
Binary file
data/certs/krzyzak.pem DELETED
@@ -1,27 +0,0 @@
1
- -----BEGIN CERTIFICATE-----
2
- MIIEgjCCAuqgAwIBAgIBATANBgkqhkiG9w0BAQsFADA1MTMwMQYDVQQDDCptaWNo
3
- YWwua3J6eXphbm93c2tpX2dpdGh1Yi9EQz1nbWFpbC9EQz1jb20wHhcNMjIwOTE5
4
- MTQwNDQyWhcNMjMwOTE5MTQwNDQyWjA1MTMwMQYDVQQDDCptaWNoYWwua3J6eXph
5
- bm93c2tpX2dpdGh1Yi9EQz1nbWFpbC9EQz1jb20wggGiMA0GCSqGSIb3DQEBAQUA
6
- A4IBjwAwggGKAoIBgQC22POIs4KtFipZ5W1nYbBu2iUck//fJrhyssXVxnljkZr/
7
- 8P6/BH9SiWmyatDQ+LiYug72olUoMQ2wRoZzEn58ZllZlHfPJSQ5QnIjKjITWHJt
8
- iBi/ou31T0/OU7KVnPzryMKBL9smbxhwRbBrQlT8nV5rfHXCrpvGdOElM3EvNWwR
9
- HM7Klal/3zlr3q/X3BZQvOp8R8hmR6OYtgNrYclS6IkvqKpcD9Y3q8K4Snz6RZ3o
10
- DGp0QW28cF5m6CJ+N7KpQkASPuFFMAjnqyhE6r5VsklxR7I083UI1JLVOq/+s6Yt
11
- kbCBqscI55BwcYakszStNqJXiqrEOqUEdcg5tkzc0PFC+ZEzWbMU1RTox17N1pwG
12
- VGtdE/3OxK2A/hm6GM/sFPR2ig7wRSBs6AI9bwbv259RzHvm4wr1yQDAQzuNWeyZ
13
- Wd3/SkNDN3nEF9mTEF1pyRC4UO2+tvQc5YOoW66a6W/gNyhGQk4QFT39Pt1Mq/VX
14
- Ec8+0b1uEAKvD+z9xPcCAwEAAaOBnDCBmTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIE
15
- sDAdBgNVHQ4EFgQUSu4g81ThKkq44UAqzDkZQAEi4eUwLwYDVR0RBCgwJoEkbWlj
16
- aGFsLmtyenl6YW5vd3NraStnaXRodWJAZ21haWwuY29tMC8GA1UdEgQoMCaBJG1p
17
- Y2hhbC5rcnp5emFub3dza2krZ2l0aHViQGdtYWlsLmNvbTANBgkqhkiG9w0BAQsF
18
- AAOCAYEAfmM8QzJAfeZkmHonfleoiIIFNSeG84wK/MWBGKr0VMIalhNHpR6DQbao
19
- 5kAQh7PMWjPr0n3ZHUT4QU7lqp1/eiErEXtKAExnxRefzWSHNm0WjXT/dIyFUbYQ
20
- rRnKtabxRNWtRIrK3GecPBDtAVTRtYQQkCaSwbwE37sHJhntS/Dvnl8pw2THq7ef
21
- XbhPDcqmP+yWRCszn9Hzda19+8VA6Sn+fIwevXMUgvb3VHqLYcIO2amHtnCeM8Q5
22
- caYBi+Tx9EDFh04EE4rbUGX25RcLO43j3ShLLqfW6QHFUtJIKS7WhgBVoEGvNA35
23
- 2KAZEiV7+ByRFKndeJmFtom0GMNBYPQW4l96aCrQJZyVhWSWGQZornxbH+hylJEp
24
- on5yD3vJbVQXzwm0Z4I1IH5xc4YbEepCQRK6u/cT6NuiQqbqeW82BxjXMPu4HVBy
25
- WXVb638bzH4OYBIYuGcw50jqBK1SyDx4exzThr6KxSiGwhAKj2xFqy51MIQjfUN0
26
- TL5B7Buq
27
- -----END CERTIFICATE-----
data.tar.gz.sig DELETED
@@ -1 +0,0 @@
1
- �s �/>��p���띡׺"�:y��s1�)F���3#$w7a�S�t�ϩH̑P �!�0O�)�΀��Jl��JX��Q�H���S��������bh]Т���*Tk���e�����8�#[���ð�N���y�%+c:@Nҟ��,mgÕ� �'�.;V�4ɍ5�s��sm-հ�Rb�Rwh�1�/GE��d�|TA����>|��1���ܒ�2V����x ��@�<�������ermF�xS�fCئ��SY��\R��W�琲O���AG�v�,��(��g���j��C�t�yW�P��xo᥏ȫ��"��K�<n����;�O�H���d�)����
metadata.gz.sig DELETED
Binary file