Turn this:
>> User.all
User Load (0.4ms) SELECT "users".* FROM "users" /* loading for inspect */ LIMIT ? [["LIMIT", 11]]
=> #<ActiveRecord::Relation [#<User id: 1, email: "[email protected]", name: "Mrs. Charis Brown", description: "Quasi atque ea. Beatae corporis quia. Eveniet veli...", created_at: "2021-09-01 05:42:24.341344000 +0000", updated_at: "2021-09-20 09:36:29.289078000 +0000", active: false, last_login_at: nil>, #<User id: 2, email: "[email protected]", name: "Ms. Sherice Champlin", description: "Omnis ut illum. Non velit mollitia. Expedita facil...", created_at: "2021-09-10 07:27:00.182298000 +0000", updated_at: "2021-09-20 09:36:29.292065000 +0000", active: true, last_login_at: "2021-09-19 16:25:32.094418000 +0000">, #<User id: 3, email: "[email protected]", name: "Florentino Gleason", description: "Non recusandae eos. Et voluptates iusto. Commodi e...", created_at: "2021-09-07 18:24:45.608164000 +0000", updated_at: "2021-09-20 09:36:29.293572000 +0000", active: false, last_login_at: nil>, #<User id: 4, email: "[email protected]", name: "Judie Boehm", description: "Ut ea eum. Tempore voluptates praesentium. Animi s...", created_at: "2021-09-05 02:11:36.564693000 +0000", updated_at: "2021-09-20 09:36:29.295763000 +0000", active: true, last_login_at: "2021-09-19 20:17:24.074515000 +0000">, #<User id: 5, email: "[email protected]", name: "Mari Ullrich", description: "Aperiam quas voluptas. Autem alias quia. Aut persp...", created_at: "2021-09-09 05:23:03.229860000 +0000", updated_at: "2021-09-20 09:36:29.296928000 +0000", active: nil, last_login_at: nil>, #<User id: 6, email: "[email protected]", name: "Sam Larson DDS", description: "Sed velit consectetur. Quas cupiditate enim. Neque...", created_at: "2021-09-03 02:52:14.055696000 +0000", updated_at: "2021-09-20 09:36:29.299157000 +0000", active: true, last_login_at: "2021-09-20 05:01:39.019563000 +0000">, #<User id: 7, email: "[email protected]", name: "Ying Kub I", description: "Cupiditate ut consequatur. Eos ab laboriosam. Ipsa...", created_at: "2021-09-10 05:52:32.005877000 +0000", updated_at: "2021-09-20 09:36:29.301469000 +0000", active: true, last_login_at: "2021-09-19 21:30:48.854010000 +0000">, #<User id: 8, email: "[email protected]", name: "Johnie Corwin II", description: "Suscipit itaque adipisci. Assumenda ad error. Quas...", created_at: "2021-09-12 13:05:49.845361000 +0000", updated_at: "2021-09-20 09:36:29.302657000 +0000", active: nil, last_login_at: nil>, #<User id: 9, email: "[email protected]", name: "Sharie Weber", description: "Sapiente voluptatum mollitia. Dolores voluptatum a...", created_at: "2021-09-19 03:03:39.360526000 +0000", updated_at: "2021-09-20 09:36:29.304929000 +0000", active: true, last_login_at: "2021-09-20 06:46:05.846685000 +0000">, #<User id: 10, email: "[email protected]", name: "Yoshiko Mohr", description: "Similique laborum totam. Non cum atque. Placeat qu...", created_at: "2021-09-08 05:41:36.588541000 +0000", updated_at: "2021-09-20 09:36:29.306120000 +0000", active: nil, last_login_at: nil>, ...]>
Into this:
>> User.all
(0.6ms) SELECT sqlite_version(*)
User Load (0.8ms) SELECT "users".* FROM "users"
βββββββββ―βββββββββββββββββββββββββββββββββββββββ―ββββββββββββββββββββββββ―ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ―ββββββββββββββββββββββββββ―ββββββββββββββββββββββββββ―βββββββββ―ββββββββββββββββββββββββββ
β id β email β name β description β created_at β updated_at β active β last_login_at β
β£ββββββββͺβββββββββββββββββββββββββββββββββββββββͺββββββββββββββββββββββββͺββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββͺββββββββββββββββββββββββββͺββββββββββββββββββββββββββͺβββββββββͺββββββββββββββββββββββββββ«
β 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 β β β β
β
β 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 β
β 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 β β β β
β
β 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 β
β 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 β β
β β
β
β 6 β alexander@anderson.io β Sam Larson DDS β Sed velit consectetur. Quas cupiditate enim. Neque facere harum. β 2021-09-03 02:52:14 UTC β 2021-09-20 09:36:29 UTC β β β 2021-09-20 05:01:39 UTC β
β 7 β chirunolfon@keler.io β Ying Kub I β Cupiditate ut consequatur. Eos ab laboriosam. Ipsam ut veritatis. β 2021-09-10 05:52:32 UTC β 2021-09-20 09:36:29 UTC β β β 2021-09-19 21:30:48 UTC β
β 8 β johnny@anderson.net β Johnie Corwin II β Suscipit itaque adipisci. Assumenda ad error. Quas enim beatae. β 2021-09-12 13:05:49 UTC β 2021-09-20 09:36:29 UTC β β
β β
β
β 9 β yahairakuhn@schneider.com β Sharie Weber β Sapiente voluptatum mollitia. Dolores voluptatum accusamus. Veniam voluptatem deserunt. β 2021-09-19 03:03:39 UTC β 2021-09-20 09:36:29 UTC β β β 2021-09-20 06:46:05 UTC β
β 10 β tommye@schuppe.biz β Yoshiko Mohr β Similique laborum totam. Non cum atque. Placeat quia velit. β 2021-09-08 05:41:36 UTC β 2021-09-20 09:36:29 UTC β β
β β
β
β 11 β derekbeier@hermankuhlman.co β Lavern Feil β Itaque molestias et. Iure tempora minus. Dolore autem omnis. β 2021-09-05 04:04:51 UTC β 2021-09-20 09:36:29 UTC β β β β
β
β 12 β lavernwillms@runolfsdottirbogan.org β Marcy Gottlieb Sr. β Mollitia quia dolor. Libero laborum aperiam. Velit est eum. β 2021-09-08 19:22:49 UTC β 2021-09-20 09:36:29 UTC β β β β
β
β 13 β earlhills@mclaughlingreenholt.info β Adina Luettgen β In qui rem. Illum itaque dignissimos. Enim vitae tenetur. β 2021-09-08 10:16:12 UTC β 2021-09-20 09:36:29 UTC β β β β
β
β 14 β larry@rice.com β Carolina Kuhlman II β Ipsum ut fuga. Sunt id a. Rerum nulla sint. β 2021-09-03 23:11:42 UTC β 2021-09-20 09:36:29 UTC β β
β β
β
β 15 β randy@kuhicfritsch.name β Harvey Runolfsdottir β Dolorum officiis sed. Ut recusandae culpa. Odit aut nostrum. β 2021-09-08 04:28:38 UTC β 2021-09-20 09:36:29 UTC β β
β β
β
β 16 β lashaun@mooreleannon.co β Lucio Raynor β Et expedita rerum. Autem nesciunt labore. Suscipit aut eum. β 2021-09-06 20:47:51 UTC β 2021-09-20 09:36:29 UTC β β β β
β
β 17 β omeryost@becker.com β Rocky Hettinger β Ut deleniti voluptas. Explicabo voluptas rerum. Illum sapiente quo. β 2021-09-14 23:05:33 UTC β 2021-09-20 09:36:29 UTC β β β 2021-09-20 09:35:14 UTC β
β 18 β nilsa@corwinkub.name β Serena Brakus β Qui non provident. Omnis excepturi quasi. Ratione suscipit dolor. β 2021-09-14 01:06:02 UTC β 2021-09-20 09:36:29 UTC β β β β
β
β 19 β berniebednar@spinkamiller.co β Merlin Predovic β Omnis et minus. Tempore in laboriosam. Molestiae aut eveniet. β 2021-09-16 18:34:20 UTC β 2021-09-20 09:36:29 UTC β β β 2021-09-19 12:01:59 UTC β
β 20 β claude@smithamhaley.io β Claudette Thompson MD β Aut consectetur soluta. Laborum quia qui. Vel incidunt minima. β 2021-09-10 03:53:24 UTC β 2021-09-20 09:36:29 UTC β β
β β
β
β 21 β matilde@cormierstroman.name β Dalton Witting β Voluptatum provident earum. Ad esse odit. Quasi non ut. β 2021-09-10 04:51:53 UTC β 2021-09-20 09:36:29 UTC β β β β
β
β 22 β randistrosin@littel.io β Miss Lucio Kub β Ea quia sapiente. Reprehenderit esse ut. Veritatis magnam quia. β 2021-08-31 18:33:02 UTC β 2021-09-20 09:36:29 UTC β β β β
β
β 23 β noah@kuphal.co β Alonzo Stroman β Officia fugit eos. Qui quo et. Ducimus harum dignissimos. β 2021-09-13 14:36:31 UTC β 2021-09-20 09:36:29 UTC β β β β
β
β 24 β cristinaschneider@cole.biz β Dr. Newton Ritchie β Corporis suscipit recusandae. Voluptas voluptas quo. Non perferendis fugiat. β 2021-09-02 20:54:38 UTC β 2021-09-20 09:36:29 UTC β β β 2021-09-20 02:35:39 UTC β
β 25 β mirtha@spinkabayer.co β Kory Cummings β Aut ut aut. Quis voluptas sit. Consequatur quia voluptatibus. β 2021-09-17 08:45:02 UTC β 2021-09-20 09:36:29 UTC β β β β
β
β ββββββββΌβββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββ΄βββββββββ΄ββββββββββββββββββββββββββ¨
β Total β 25 β
βββββββββ·ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
While nothing stops you from adding Nazar to each project separately, I find it cumbersome to add it to every project I'm working on - it also alters REPL behaviour for other teammates, which is another reason why personally I don't recommend that approach. Anyway, here's quick how-to:
Add nazar
to Gemfile:
group :development, :test do
gem 'nazar', require: false
end
Then, you have to call Nazar.enable!
. If you're using Rails, you might want to add this snippet to config/application.rb
:
console do
require 'nazar'
Nazar.enable! # See configuration section for more options and
# Opt-in setup section if you don't want to enable it for every item
end
Otherwise, call it in bin/console
or any other script that launches your REPL.
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.
-
Create global gems path
mkdir -p ~/.gem/ruby/global
- You're welcome to use any other path for your global gemset -
Install nazar in your global gemset
gem install nazar -i ~/.gem/ruby/global
-
Load Nazar in your REPL rc file Add following snippet to your
.irbrc
or.pryrc
:
global_gemset_path = File.expand_path('~/.gem/ruby/global/gems')
if Dir.exist?(global_gemset_path)
global_gems_path = Dir.glob("#{global_gemset_path}/*/lib")
$LOAD_PATH.unshift(*global_gems_path)
end
%w[nazar].each do |gem| # add more gems you want to load globally
begin
require gem
rescue LoadError
end
end
Nazar.enable! if defined?(Nazar)
Nazar.config.formatter.layout
can be set to either :horizontal
, :vertical
or :auto
.
:auto
uses horizontal layout if it fits in your console size, otherwise it falls back to :vertical
layout.
Here's a preview of both layouts:
βββββββββ―βββββββββββββββββββββββββββββββββββββββ―βββββββββββββββββββββββ―ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ―ββββββββββββββββββββββββββ―ββββββββββββββββββββββββββ―βββββββββ―ββββββββββββββββββββββββββ
β id β email β name β description β created_at β updated_at β active β last_login_at β
β£ββββββββͺβββββββββββββββββββββββββββββββββββββββͺβββββββββββββββββββββββͺββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββͺββββββββββββββββββββββββββͺββββββββββββββββββββββββββͺβββββββββͺββββββββββββββββββββββββββ«
β 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 β β β β
β
β 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 β
β 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 β β β β
β
β 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 β
β 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 β β
β β
β
β ββββββββΌβββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββ΄βββββββββ΄ββββββββββββββββββββββββββ¨
β Total β 5 β
βββββββββ·βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
User.first(5)
βββββββββββββββββ―ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β id β 1 β
β email β delma@goldner.co β
β name β Mrs. Charis Brown β
β description β Quasi atque ea. Beatae corporis quia. Eveniet velit ad. β
β created_at β 2021-09-01 05:42:24 UTC β
β updated_at β 2021-09-20 09:36:29 UTC β
β active β β β
β last_login_at β β
β
β ββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ¨
β id β 2 β
β email β markpfeffer@wunschbraun.info β
β name β Ms. Sherice Champlin β
β description β Omnis ut illum. Non velit mollitia. Expedita facilis dignissimos. β
β created_at β 2021-09-10 07:27:00 UTC β
β updated_at β 2021-09-20 09:36:29 UTC β
β active β β β
β last_login_at β 2021-09-19 16:25:32 UTC β
β ββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ¨
β id β 3 β
β email β nathansimonis@kunde.org β
β name β Florentino Gleason β
β description β Non recusandae eos. Et voluptates iusto. Commodi est in. β
β created_at β 2021-09-07 18:24:45 UTC β
β updated_at β 2021-09-20 09:36:29 UTC β
β active β β β
β last_login_at β β
β
β ββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ¨
β id β 4 β
β email β edwardowilkinson@walkerschiller.info β
β name β Judie Boehm β
β description β Ut ea eum. Tempore voluptates praesentium. Animi sapiente distinctio. β
β created_at β 2021-09-05 02:11:36 UTC β
β updated_at β 2021-09-20 09:36:29 UTC β
β active β β β
β last_login_at β 2021-09-19 20:17:24 UTC β
β ββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ¨
β id β 5 β
β email β isaiahebert@brauncarroll.net β
β name β Mari Ullrich β
β description β Aperiam quas voluptas. Autem alias quia. Aut perspiciatis eos. β
β created_at β 2021-09-09 05:23:03 UTC β
β updated_at β 2021-09-20 09:36:29 UTC β
β active β β
β
β last_login_at β β
β
β ββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ¨
β Total β 5 β
βββββββββββββββββ·ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Nazar defines top level __(data, **options)
method, that can be useful for two things:
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:
__([{foo: :bar, test: 123},{foo: :baz, test: 456}])
βββββββββ―βββββββ
β foo β test β
β£ββββββββͺβββββββ«
β :bar β 123 β
β :baz β 456 β
β ββββββββΌβββββββ¨
β Total β 2 β
βββββββββ·βββββββ
It works with Structs and Hashes (or, more specifically - with any object that reponds to #keys
and #values
)
You can also enforce layout and/or pagination:
__([{foo: :bar, test: 123},{foo: :baz, test: 456}], layout: :vertical)
βββββββββ―βββββββ
β foo β :bar β
β test β 123 β
β ββββββββΌβββββββ¨
β foo β :baz β
β test β 456 β
β ββββββββΌβββββββ¨
β Total β 2 β
βββββββββ·βββββββ
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
Nazar.load!
User.all # Returns default output
__ User.all # Returns output enhanced by Nazar
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:
Nazar.enable!(extensions: [:active_record, :csv, :sequel])
will enhance output for Sequel as well.
You can also configure behaviour of Nazar:
Config | Default | Description |
---|---|---|
Nazar.config.colors.enabled |
true | Determines whether the output should be colorised or not |
Nazar.config.formatter.nil |
β
|
Sets character printed if the value was nil |
Nazar.config.formatter.layout |
:auto |
Determines which layout should be used. See Layouts for more details |
Nazar.config.formatter.paginate |
true |
Determines if results too long/wide should be printed directly, or paginated with less . Horizontal layout is always paginated. |
Nazar.config.formatter.boolean |
['β', 'β'] | First item in array is a character for true , second for false |
Nazar.config.enable_shorthand_method |
true | Determines if shorthand method should be defined. See Opt-in setup for more details |
Nazar.config.table.resize |
true |
Determines if the table should always be resized to take full width |
Nazar.config.table.min_width |
nil |
Sets minimum width. By default uses the longest header length |
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 |
Bug reports and pull requests are welcome on GitHub at https://github.com/krzyzak/nazar.