nazar 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +103 -11
- data/certs/krzyzak.pem +21 -21
- data/lib/nazar/formatter/generic.rb +1 -1
- data/lib/nazar/renderer.rb +10 -4
- data/lib/nazar/version.rb +1 -1
- data/lib/nazar/view.rb +61 -5
- data/lib/nazar.rb +8 -4
- data/nazar.gemspec +4 -1
- data.tar.gz.sig +0 -0
- metadata +40 -24
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f577a21e50d8bf8606ed8e8bf115a2c2fb0909b2ee7c1fae72fb4ef871064d0
|
4
|
+
data.tar.gz: '0609ff110d8ce48f3df2fd297ccd02e047d6730985b2698f9592c8f68e39df1b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbf98c584b508c82a19e69730403dda91e54b3f5d6c6a833ba535149591647445c14222b4bda7440090565c5b97a5e777c0b33d331c6a90194b3f32ac5962d03
|
7
|
+
data.tar.gz: da49a17743f2676d1178eb76df8e17c93752f6ad4d22dbe6195398a59f34ec4121315ffb4007c87ee704ed2d9fc4507fd9d9ac87ef72fbafb98eb933f8e1725d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -57,13 +57,13 @@ group :development, :test do
|
|
57
57
|
gem 'nazar', require: false
|
58
58
|
end
|
59
59
|
```
|
60
|
-
Then, you have to call `Nazar.enable!`. If you're using Rails, you might want to add this snippet to `config/application.rb`:
|
60
|
+
Then, you have to call `Nazar.enable!`. If you're using Rails, you might want to add this snippet to `config/application.rb`:
|
61
61
|
|
62
62
|
```ruby
|
63
63
|
console do
|
64
64
|
require 'nazar'
|
65
65
|
|
66
|
-
Nazar.enable! # See configuration section for more options and
|
66
|
+
Nazar.enable! # See configuration section for more options and
|
67
67
|
# Opt-in setup section if you don't want to enable it for every item
|
68
68
|
end
|
69
69
|
```
|
@@ -73,15 +73,15 @@ Otherwise, call it in `bin/console` or any other script that launches your REPL.
|
|
73
73
|
|
74
74
|
This is my recommended way to install this gem - that way it works automatically in all your projects, even in standalone `irb` or `pry` sessions.
|
75
75
|
|
76
|
-
- **Create global gems path**
|
77
|
-
|
76
|
+
- **Create global gems path**
|
77
|
+
|
78
78
|
`mkdir -p ~/.gem/ruby/global` - You're welcome to use any other path for your global gemset
|
79
79
|
- **Install nazar in your global gemset**
|
80
|
-
|
80
|
+
|
81
81
|
`gem install nazar -i ~/.gem/ruby/global`
|
82
82
|
- **Load Nazar in your REPL rc file**
|
83
83
|
Add following snippet to your `.irbrc` or `.pryrc`:
|
84
|
-
|
84
|
+
|
85
85
|
```ruby
|
86
86
|
global_gemset_path = File.expand_path('~/.gem/ruby/global/gems')
|
87
87
|
|
@@ -91,7 +91,7 @@ if Dir.exist?(global_gemset_path)
|
|
91
91
|
$LOAD_PATH.unshift(*global_gems_path)
|
92
92
|
end
|
93
93
|
|
94
|
-
%w[nazar].each do |gem|
|
94
|
+
%w[nazar].each do |gem| # add more gems you want to load globally
|
95
95
|
begin
|
96
96
|
require gem
|
97
97
|
rescue LoadError
|
@@ -101,16 +101,92 @@ end
|
|
101
101
|
Nazar.enable! if defined?(Nazar)
|
102
102
|
```
|
103
103
|
|
104
|
+
## Layouts
|
105
|
+
`Nazar.config.formatter.layout` can be set to either `:horizontal`, `:vertical` or `:auto`.
|
106
|
+
|
107
|
+
`:auto` uses horizontal layout if it fits in your console size, otherwise it falls back to `:vertical` layout.
|
108
|
+
|
109
|
+
Here's a preview of both layouts:
|
110
|
+
|
111
|
+
#### Horizontal
|
112
|
+
```ruby
|
113
|
+
┏━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
114
|
+
┃ id │ email │ name │ description │ created_at │ updated_at │ active │ last_login_at ┃
|
115
|
+
┣═══════╪══════════════════════════════════════╪══════════════════════╪═══════════════════════════════════════════════════════════════════════╪═════════════════════════╪═════════════════════════╪════════╪═════════════════════════┫
|
116
|
+
┃ 1 │ delma@goldner.co │ Mrs. Charis Brown │ Quasi atque ea. Beatae corporis quia. Eveniet velit ad. │ 2021-09-01 05:42:24 UTC │ 2021-09-20 09:36:29 UTC │ ✗ │ ∅ ┃
|
117
|
+
┃ 2 │ markpfeffer@wunschbraun.info │ Ms. Sherice Champlin │ Omnis ut illum. Non velit mollitia. Expedita facilis dignissimos. │ 2021-09-10 07:27:00 UTC │ 2021-09-20 09:36:29 UTC │ ✓ │ 2021-09-19 16:25:32 UTC ┃
|
118
|
+
┃ 3 │ nathansimonis@kunde.org │ Florentino Gleason │ Non recusandae eos. Et voluptates iusto. Commodi est in. │ 2021-09-07 18:24:45 UTC │ 2021-09-20 09:36:29 UTC │ ✗ │ ∅ ┃
|
119
|
+
┃ 4 │ edwardowilkinson@walkerschiller.info │ Judie Boehm │ Ut ea eum. Tempore voluptates praesentium. Animi sapiente distinctio. │ 2021-09-05 02:11:36 UTC │ 2021-09-20 09:36:29 UTC │ ✓ │ 2021-09-19 20:17:24 UTC ┃
|
120
|
+
┃ 5 │ isaiahebert@brauncarroll.net │ Mari Ullrich │ Aperiam quas voluptas. Autem alias quia. Aut perspiciatis eos. │ 2021-09-09 05:23:03 UTC │ 2021-09-20 09:36:29 UTC │ ∅ │ ∅ ┃
|
121
|
+
┠───────┼──────────────────────────────────────┴──────────────────────┴───────────────────────────────────────────────────────────────────────┴─────────────────────────┴─────────────────────────┴────────┴─────────────────────────┨
|
122
|
+
┃ Total │ 5 ┃
|
123
|
+
┗━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
124
|
+
```
|
125
|
+
|
126
|
+
### Vertical
|
127
|
+
```ruby
|
128
|
+
User.first(5)
|
129
|
+
|
130
|
+
┏━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
|
131
|
+
┃ id │ 1 ┃
|
132
|
+
┃ email │ delma@goldner.co ┃
|
133
|
+
┃ name │ Mrs. Charis Brown ┃
|
134
|
+
┃ description │ Quasi atque ea. Beatae corporis quia. Eveniet velit ad. ┃
|
135
|
+
┃ created_at │ 2021-09-01 05:42:24 UTC ┃
|
136
|
+
┃ updated_at │ 2021-09-20 09:36:29 UTC ┃
|
137
|
+
┃ active │ ✗ ┃
|
138
|
+
┃ last_login_at │ ∅ ┃
|
139
|
+
┠───────────────┼───────────────────────────────────────────────────────────────────────┨
|
140
|
+
┃ id │ 2 ┃
|
141
|
+
┃ email │ markpfeffer@wunschbraun.info ┃
|
142
|
+
┃ name │ Ms. Sherice Champlin ┃
|
143
|
+
┃ description │ Omnis ut illum. Non velit mollitia. Expedita facilis dignissimos. ┃
|
144
|
+
┃ created_at │ 2021-09-10 07:27:00 UTC ┃
|
145
|
+
┃ updated_at │ 2021-09-20 09:36:29 UTC ┃
|
146
|
+
┃ active │ ✓ ┃
|
147
|
+
┃ last_login_at │ 2021-09-19 16:25:32 UTC ┃
|
148
|
+
┠───────────────┼───────────────────────────────────────────────────────────────────────┨
|
149
|
+
┃ id │ 3 ┃
|
150
|
+
┃ email │ nathansimonis@kunde.org ┃
|
151
|
+
┃ name │ Florentino Gleason ┃
|
152
|
+
┃ description │ Non recusandae eos. Et voluptates iusto. Commodi est in. ┃
|
153
|
+
┃ created_at │ 2021-09-07 18:24:45 UTC ┃
|
154
|
+
┃ updated_at │ 2021-09-20 09:36:29 UTC ┃
|
155
|
+
┃ active │ ✗ ┃
|
156
|
+
┃ last_login_at │ ∅ ┃
|
157
|
+
┠───────────────┼───────────────────────────────────────────────────────────────────────┨
|
158
|
+
┃ id │ 4 ┃
|
159
|
+
┃ email │ edwardowilkinson@walkerschiller.info ┃
|
160
|
+
┃ name │ Judie Boehm ┃
|
161
|
+
┃ description │ Ut ea eum. Tempore voluptates praesentium. Animi sapiente distinctio. ┃
|
162
|
+
┃ created_at │ 2021-09-05 02:11:36 UTC ┃
|
163
|
+
┃ updated_at │ 2021-09-20 09:36:29 UTC ┃
|
164
|
+
┃ active │ ✓ ┃
|
165
|
+
┃ last_login_at │ 2021-09-19 20:17:24 UTC ┃
|
166
|
+
┠───────────────┼───────────────────────────────────────────────────────────────────────┨
|
167
|
+
┃ id │ 5 ┃
|
168
|
+
┃ email │ isaiahebert@brauncarroll.net ┃
|
169
|
+
┃ name │ Mari Ullrich ┃
|
170
|
+
┃ description │ Aperiam quas voluptas. Autem alias quia. Aut perspiciatis eos. ┃
|
171
|
+
┃ created_at │ 2021-09-09 05:23:03 UTC ┃
|
172
|
+
┃ updated_at │ 2021-09-20 09:36:29 UTC ┃
|
173
|
+
┃ active │ ∅ ┃
|
174
|
+
┃ last_login_at │ ∅ ┃
|
175
|
+
┠───────────────┼───────────────────────────────────────────────────────────────────────┨
|
176
|
+
┃ Total │ 5 ┃
|
177
|
+
┗━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
178
|
+
```
|
179
|
+
|
104
180
|
## Shorthand method
|
105
181
|
|
106
|
-
Nazar defines top level `__(data)` method, that can be useful for two things:
|
182
|
+
Nazar defines top level `__(data, **options)` method, that can be useful for two things:
|
107
183
|
|
108
184
|
### Inspecting (array of) Hashes/Structs
|
109
185
|
|
110
186
|
Nazar by design won't enhance output for any collection that does not consist of supported (eg. ActiveRecord/Sequel) items. If you have a data that is structurally compatible (ie: all items consists of the same keys), and want to enahance the output, you can simply use `#__` method:
|
111
187
|
|
112
188
|
```ruby
|
113
|
-
__
|
189
|
+
__([{foo: :bar, test: 123},{foo: :baz, test: 456}])
|
114
190
|
┏━━━━━━━┯━━━━━━┓
|
115
191
|
┃ foo │ test ┃
|
116
192
|
┣═══════╪══════┫
|
@@ -123,6 +199,21 @@ __ [{foo: :bar, test: 123},{foo: :baz, test: 456}]
|
|
123
199
|
|
124
200
|
It works with Structs and Hashes (or, more specifically - with any object that reponds to `#keys` and `#values`)
|
125
201
|
|
202
|
+
You can also enforce layout and/or pagination:
|
203
|
+
|
204
|
+
```ruby
|
205
|
+
__([{foo: :bar, test: 123},{foo: :baz, test: 456}], layout: :vertical)
|
206
|
+
┏━━━━━━━┯━━━━━━┓
|
207
|
+
┃ foo │ :bar ┃
|
208
|
+
┃ test │ 123 ┃
|
209
|
+
┠───────┼──────┨
|
210
|
+
┃ foo │ :baz ┃
|
211
|
+
┃ test │ 456 ┃
|
212
|
+
┠───────┼──────┨
|
213
|
+
┃ Total │ 2 ┃
|
214
|
+
┗━━━━━━━┷━━━━━━┛
|
215
|
+
```
|
216
|
+
|
126
217
|
### Opt-in setup
|
127
218
|
|
128
219
|
If you use `Nazar.load!` instead of `Nazar.enable!`, it would not enhance output for every element in the console. Instead, you have to call `#__` for each item that you want to enhance output
|
@@ -134,7 +225,6 @@ User.all # Returns default output
|
|
134
225
|
__ User.all # Returns output enhanced by Nazar
|
135
226
|
```
|
136
227
|
|
137
|
-
|
138
228
|
## Configuration
|
139
229
|
|
140
230
|
By default, Nazar improves output for ActiveRecord (both collections and a single item) and for CSV Tables. You can configure that by calling `#enable!` with optional argument:
|
@@ -146,7 +236,9 @@ You can also configure behaviour of Nazar:
|
|
146
236
|
| Config | Default | Description |
|
147
237
|
| ------ | ------- | ----------- |
|
148
238
|
| `Nazar.config.colors.enabled` | true | Determines whether the output should be colorised or not |
|
149
|
-
| `Nazar.config.formatter.nil` | `∅` | Sets character printed if the value was nil |
|
239
|
+
| `Nazar.config.formatter.nil` | `∅` | Sets character printed if the value was nil |
|
240
|
+
| `Nazar.config.formatter.layout` | `:auto` | Determines which layout should be used. See <a href="#layouts">Layouts</a> for more details |
|
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.
|
150
242
|
| `Nazar.config.formatter.boolean` | ['✓', '✗'] | First item in array is a character for `true`, second for `false` |
|
151
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 |
|
152
244
|
|
data/certs/krzyzak.pem
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
-----BEGIN CERTIFICATE-----
|
2
2
|
MIIEgjCCAuqgAwIBAgIBATANBgkqhkiG9w0BAQsFADA1MTMwMQYDVQQDDCptaWNo
|
3
|
-
|
4
|
-
|
3
|
+
YWwua3J6eXphbm93c2tpX2dpdGh1Yi9EQz1nbWFpbC9EQz1jb20wHhcNMjIwOTE5
|
4
|
+
MTQwNDQyWhcNMjMwOTE5MTQwNDQyWjA1MTMwMQYDVQQDDCptaWNoYWwua3J6eXph
|
5
5
|
bm93c2tpX2dpdGh1Yi9EQz1nbWFpbC9EQz1jb20wggGiMA0GCSqGSIb3DQEBAQUA
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
/
|
14
|
-
|
15
|
-
|
6
|
+
A4IBjwAwggGKAoIBgQC22POIs4KtFipZ5W1nYbBu2iUck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tRIrK3GecPBDtAVTRtYQQkCaSwbwE37sHJhntS/Dvnl8pw2THq7ef
|
21
|
+
XbhPDcqmP+yWRCszn9Hzda19+8VA6Sn+fIwevXMUgvb3VHqLYcIO2amHtnCeM8Q5
|
22
|
+
caYBi+Tx9EDFh04EE4rbUGX25RcLO43j3ShLLqfW6QHFUtJIKS7WhgBVoEGvNA35
|
23
|
+
2KAZEiV7+ByRFKndeJmFtom0GMNBYPQW4l96aCrQJZyVhWSWGQZornxbH+hylJEp
|
24
|
+
on5yD3vJbVQXzwm0Z4I1IH5xc4YbEepCQRK6u/cT6NuiQqbqeW82BxjXMPu4HVBy
|
25
|
+
WXVb638bzH4OYBIYuGcw50jqBK1SyDx4exzThr6KxSiGwhAKj2xFqy51MIQjfUN0
|
26
|
+
TL5B7Buq
|
27
27
|
-----END CERTIFICATE-----
|
data/lib/nazar/renderer.rb
CHANGED
@@ -2,13 +2,19 @@
|
|
2
2
|
|
3
3
|
module Nazar
|
4
4
|
class Renderer
|
5
|
-
def initialize(data, use_generic_formatter: false)
|
5
|
+
def initialize(data, layout:, paginate:, use_generic_formatter: false)
|
6
6
|
@data = data
|
7
7
|
@use_generic_formatter = use_generic_formatter
|
8
|
+
@layout = layout
|
9
|
+
@paginate = paginate
|
8
10
|
end
|
9
11
|
|
10
12
|
def render
|
11
|
-
|
13
|
+
if paginate || view.horizontal?
|
14
|
+
pager.page(view.render)
|
15
|
+
else
|
16
|
+
puts view.render
|
17
|
+
end
|
12
18
|
nil
|
13
19
|
end
|
14
20
|
|
@@ -22,10 +28,10 @@ module Nazar
|
|
22
28
|
|
23
29
|
private
|
24
30
|
|
25
|
-
attr_reader :data
|
31
|
+
attr_reader :data, :use_generic_formatter, :layout, :paginate
|
26
32
|
|
27
33
|
def view
|
28
|
-
@view ||= View.new(data, use_generic_formatter:
|
34
|
+
@view ||= View.new(data, use_generic_formatter: use_generic_formatter, layout: layout)
|
29
35
|
end
|
30
36
|
end
|
31
37
|
end
|
data/lib/nazar/version.rb
CHANGED
data/lib/nazar/view.rb
CHANGED
@@ -4,11 +4,12 @@ module Nazar
|
|
4
4
|
class View
|
5
5
|
extend Forwardable
|
6
6
|
|
7
|
-
def_delegators :formatter, :headers, :
|
7
|
+
def_delegators :formatter, :headers, :summary
|
8
8
|
|
9
|
-
def initialize(data, use_generic_formatter: false)
|
9
|
+
def initialize(data, layout:, use_generic_formatter: false)
|
10
10
|
@data = data
|
11
11
|
@use_generic_formatter = use_generic_formatter
|
12
|
+
@layout = layout
|
12
13
|
end
|
13
14
|
|
14
15
|
def render
|
@@ -23,10 +24,38 @@ module Nazar
|
|
23
24
|
!!formatter_klass && formatter.valid?
|
24
25
|
end
|
25
26
|
|
27
|
+
def layout
|
28
|
+
case @layout
|
29
|
+
when :auto
|
30
|
+
determine_layout
|
31
|
+
when :vertical
|
32
|
+
:vertical
|
33
|
+
when :horizontal
|
34
|
+
:horizontal
|
35
|
+
else
|
36
|
+
raise ArgumentError, "Unknown layout: #{Nazar.config.formatter.layout}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def horizontal?
|
41
|
+
layout == :horizontal
|
42
|
+
end
|
43
|
+
|
26
44
|
private
|
27
45
|
|
28
46
|
attr_reader :data, :use_generic_formatter
|
29
47
|
|
48
|
+
def determine_layout
|
49
|
+
table_width > TTY::Screen.width ? :vertical : :horizontal
|
50
|
+
end
|
51
|
+
|
52
|
+
def table_width
|
53
|
+
[
|
54
|
+
headers.map(&:size).sum,
|
55
|
+
horizontal_cells.map { |row| row.map(&:size).sum }.max
|
56
|
+
].max
|
57
|
+
end
|
58
|
+
|
30
59
|
def formatters
|
31
60
|
@formatters ||= Nazar.formatters.tap do |formatters|
|
32
61
|
formatters << Nazar::Formatter::Generic if use_generic_formatter
|
@@ -42,18 +71,45 @@ module Nazar
|
|
42
71
|
end
|
43
72
|
|
44
73
|
def add_summary
|
74
|
+
colspan = horizontal? ? headers.size - 1 : 1
|
75
|
+
|
45
76
|
table.add_separator
|
46
|
-
table.add_row [pastel.bold('Total'), { value: summary, colspan:
|
77
|
+
table.add_row [pastel.bold('Total'), { value: summary, colspan: colspan }]
|
47
78
|
end
|
48
79
|
|
49
80
|
def table
|
50
81
|
@table ||= Terminal::Table.new(
|
51
|
-
headings:
|
52
|
-
rows:
|
82
|
+
headings: display_headers,
|
83
|
+
rows: display_cells,
|
53
84
|
style: { border: :unicode_thick_edge }
|
54
85
|
)
|
55
86
|
end
|
56
87
|
|
88
|
+
def display_headers
|
89
|
+
horizontal? ? formatter.headers : []
|
90
|
+
end
|
91
|
+
|
92
|
+
def display_cells
|
93
|
+
horizontal? ? horizontal_cells : vertical_cells
|
94
|
+
end
|
95
|
+
|
96
|
+
def horizontal_cells
|
97
|
+
formatter.cells
|
98
|
+
end
|
99
|
+
|
100
|
+
def vertical_cells
|
101
|
+
data = horizontal_cells.inject([]) do |output, items|
|
102
|
+
items.each.with_index do |item, index|
|
103
|
+
output << [headers[index], item]
|
104
|
+
end
|
105
|
+
|
106
|
+
output << :separator
|
107
|
+
end
|
108
|
+
|
109
|
+
data.pop # remove last separator
|
110
|
+
data
|
111
|
+
end
|
112
|
+
|
57
113
|
def pastel
|
58
114
|
@pastel ||= Pastel.new(enabled: Nazar.config.colors.enabled)
|
59
115
|
end
|
data/lib/nazar.rb
CHANGED
@@ -19,6 +19,8 @@ module Nazar # rubocop:disable Metrics/ModuleLength
|
|
19
19
|
setting :formatter do
|
20
20
|
setting :nil, default: '∅'
|
21
21
|
setting :boolean, default: ['✓', '✗']
|
22
|
+
setting :layout, default: :auto
|
23
|
+
setting :paginate, default: true
|
22
24
|
end
|
23
25
|
|
24
26
|
setting :colors do
|
@@ -80,7 +82,8 @@ module Nazar # rubocop:disable Metrics/ModuleLength
|
|
80
82
|
return unless defined?(Pry)
|
81
83
|
|
82
84
|
proc do |output, value, instance|
|
83
|
-
renderer = Nazar::Renderer.new(value
|
85
|
+
renderer = Nazar::Renderer.new(value, layout: Nazar.config.formatter.layout,
|
86
|
+
paginate: Nazar.config.formatter.paginate)
|
84
87
|
renderer.valid? ? renderer.render : @__original_pry_print.call(output, value, instance)
|
85
88
|
end
|
86
89
|
end
|
@@ -113,7 +116,8 @@ module Nazar # rubocop:disable Metrics/ModuleLength
|
|
113
116
|
::IRB::Irb.class_eval do
|
114
117
|
alias_method :__original_output_value__, :output_value
|
115
118
|
def output_value(omit = false) # rubocop:disable Style/OptionalBooleanParameter
|
116
|
-
renderer = Nazar::Renderer.new(@context.last_value
|
119
|
+
renderer = Nazar::Renderer.new(@context.last_value, layout: Nazar.config.formatter.layout,
|
120
|
+
paginate: Nazar.config.formatter.paginate)
|
117
121
|
renderer.valid? ? renderer.render : __original_output_value__(omit)
|
118
122
|
end
|
119
123
|
end
|
@@ -137,8 +141,8 @@ module Nazar # rubocop:disable Metrics/ModuleLength
|
|
137
141
|
@defined_shorthand_method = true
|
138
142
|
|
139
143
|
Object.class_eval do
|
140
|
-
def __(item)
|
141
|
-
Nazar::Renderer.new(item, use_generic_formatter: true).render
|
144
|
+
def __(item, layout: Nazar.config.formatter.layout, paginate: Nazar.config.formatter.paginate)
|
145
|
+
Nazar::Renderer.new(item, use_generic_formatter: true, layout: layout, paginate: paginate).render
|
142
146
|
end
|
143
147
|
end
|
144
148
|
end
|
data/nazar.gemspec
CHANGED
@@ -2,17 +2,19 @@
|
|
2
2
|
|
3
3
|
require_relative 'lib/nazar/version'
|
4
4
|
|
5
|
-
Gem::Specification.new do |spec|
|
5
|
+
Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
6
6
|
spec.name = 'nazar'
|
7
7
|
spec.version = Nazar::VERSION
|
8
8
|
spec.authors = ['Michał Krzyżanowski']
|
9
9
|
spec.email = ['michal.krzyzanowski+github@gmail.com']
|
10
|
+
spec.licenses = ['MIT']
|
10
11
|
|
11
12
|
spec.summary = 'Nazar is a tool that enhances default IRB/Pry inspect output'
|
12
13
|
spec.homepage = 'https://github.com/krzyzak/nazar'
|
13
14
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
|
14
15
|
|
15
16
|
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
16
18
|
|
17
19
|
# Specify which files should be added to the gem when it is released.
|
18
20
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -36,4 +38,5 @@ Gem::Specification.new do |spec|
|
|
36
38
|
spec.add_runtime_dependency 'pastel', '~> 0.8'
|
37
39
|
spec.add_runtime_dependency 'terminal-table', '~> 3.0'
|
38
40
|
spec.add_runtime_dependency 'tty-pager', '~> 0.14'
|
41
|
+
spec.add_runtime_dependency 'tty-screen', '~> 0.8'
|
39
42
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nazar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michał Krzyżanowski
|
@@ -11,32 +11,32 @@ cert_chain:
|
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
13
|
MIIEgjCCAuqgAwIBAgIBATANBgkqhkiG9w0BAQsFADA1MTMwMQYDVQQDDCptaWNo
|
14
|
-
|
15
|
-
|
14
|
+
YWwua3J6eXphbm93c2tpX2dpdGh1Yi9EQz1nbWFpbC9EQz1jb20wHhcNMjIwOTE5
|
15
|
+
MTQwNDQyWhcNMjMwOTE5MTQwNDQyWjA1MTMwMQYDVQQDDCptaWNoYWwua3J6eXph
|
16
16
|
bm93c2tpX2dpdGh1Yi9EQz1nbWFpbC9EQz1jb20wggGiMA0GCSqGSIb3DQEBAQUA
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
/
|
25
|
-
|
26
|
-
|
17
|
+
A4IBjwAwggGKAoIBgQC22POIs4KtFip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|
+
rRnKtabxRNWtRIrK3GecPBDtAVTRtYQQkCaSwbwE37sHJhntS/Dvnl8pw2THq7ef
|
32
|
+
XbhPDcqmP+yWRCszn9Hzda19+8VA6Sn+fIwevXMUgvb3VHqLYcIO2amHtnCeM8Q5
|
33
|
+
caYBi+Tx9EDFh04EE4rbUGX25RcLO43j3ShLLqfW6QHFUtJIKS7WhgBVoEGvNA35
|
34
|
+
2KAZEiV7+ByRFKndeJmFtom0GMNBYPQW4l96aCrQJZyVhWSWGQZornxbH+hylJEp
|
35
|
+
on5yD3vJbVQXzwm0Z4I1IH5xc4YbEepCQRK6u/cT6NuiQqbqeW82BxjXMPu4HVBy
|
36
|
+
WXVb638bzH4OYBIYuGcw50jqBK1SyDx4exzThr6KxSiGwhAKj2xFqy51MIQjfUN0
|
37
|
+
TL5B7Buq
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date:
|
39
|
+
date: 2022-09-19 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activerecord
|
@@ -170,6 +170,20 @@ dependencies:
|
|
170
170
|
- - "~>"
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
version: '0.14'
|
173
|
+
- !ruby/object:Gem::Dependency
|
174
|
+
name: tty-screen
|
175
|
+
requirement: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - "~>"
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0.8'
|
180
|
+
type: :runtime
|
181
|
+
prerelease: false
|
182
|
+
version_requirements: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - "~>"
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0.8'
|
173
187
|
description:
|
174
188
|
email:
|
175
189
|
- michal.krzyzanowski+github@gmail.com
|
@@ -205,9 +219,11 @@ files:
|
|
205
219
|
- lib/nazar/view.rb
|
206
220
|
- nazar.gemspec
|
207
221
|
homepage: https://github.com/krzyzak/nazar
|
208
|
-
licenses:
|
222
|
+
licenses:
|
223
|
+
- MIT
|
209
224
|
metadata:
|
210
225
|
homepage_uri: https://github.com/krzyzak/nazar
|
226
|
+
rubygems_mfa_required: 'true'
|
211
227
|
post_install_message:
|
212
228
|
rdoc_options: []
|
213
229
|
require_paths:
|
metadata.gz.sig
CHANGED
Binary file
|