nazar 0.0.8 → 0.0.9

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: ae9a224c9ae75c4e9b85ef48d22c97ea0c293b42aa859cc03dd4e0f31abed150
4
- data.tar.gz: e2450f3e6a340c7bd6e1e239201c6bf7e7248c9e88d4e032d1e7e09be96d40aa
3
+ metadata.gz: 7204b0e6f3c925d89b8d8ac8806b938fa88d73c21a8c9d7cd71236578968960a
4
+ data.tar.gz: 40f2762c75425f5b0be957b60ba0812f65dcb4e2fce1fbb05e4d9f4c8314c12f
5
5
  SHA512:
6
- metadata.gz: 39ed17bba483fde391edcafe72f942f7f38777f25d1baa152ddfc5121a1e2019c686f736af537e46a65e4fca6edd7a6acc02858a8d569f9bf7376b9d9e8824f3
7
- data.tar.gz: 7318b8a9beb572d8a6732734b4847ea7bd2c856b32def45c91ee88034eef122026d5f340e88d40b983c106f793b1f5df0047d7d28526b192f3b916c311439f12
6
+ metadata.gz: 040ab5047820966aef1db0f65478ffc581849d1d83a9f54ae39c463908c71d016f847391378b259f3098ffddc87c14ab673f1d40e5b3b5b887e162685798eff1
7
+ data.tar.gz: 163d9c68f8f6f0c27d2a6d4eff9f9f89924d706a69e6d2acf37285afe1599f30d35151e0728b43dbec4253b8aaab8dba5d5de716de18d62b56c032f53da90212
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -4,8 +4,120 @@ Nazar improves defvault inspect output for console applications (supports IRB an
4
4
 
5
5
  **Nazar is under heavy development now. Expect bumpy ride or wait until the API will stabilise a bit ;)**
6
6
 
7
- [![asciicast](https://asciinema.org/a/436814.png)](https://asciinema.org/a/436814)
7
+ Turn this:
8
+ ```ruby
9
+ >> User.all
10
+ User Load (0.4ms) SELECT "users".* FROM "users" /* loading for inspect */ LIMIT ? [["LIMIT", 11]]
11
+ => #<ActiveRecord::Relation [#<User id: 1, email: "delma@goldner.co", 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: "markpfeffer@wunschbraun.info", 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: "nathansimonis@kunde.org", 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: "edwardowilkinson@walkerschiller.info", 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: "isaiahebert@brauncarroll.net", 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: "alexander@anderson.io", 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: "chirunolfon@keler.io", 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: "johnny@anderson.net", 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: "yahairakuhn@schneider.com", 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: "tommye@schuppe.biz", 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>, ...]>
12
+ ```
13
+ Into this:
8
14
 
15
+ ```ruby
16
+ >> User.all
17
+ (0.6ms) SELECT sqlite_version(*)
18
+ User Load (0.8ms) SELECT "users".* FROM "users"
19
+ ┏━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━┓
20
+ ┃ id │ email │ name │ description │ created_at │ updated_at │ active │ last_login_at ┃
21
+ ┣═══════╪══════════════════════════════════════╪═══════════════════════╪═════════════════════════════════════════════════════════════════════════════════════════╪═════════════════════════╪═════════════════════════╪════════╪═════════════════════════┫
22
+ ┃ 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 │ ✗ │ ∅ ┃
23
+ ┃ 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 ┃
24
+ ┃ 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 │ ✗ │ ∅ ┃
25
+ ┃ 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 ┃
26
+ ┃ 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 │ ∅ │ ∅ ┃
27
+ ┃ 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 ┃
28
+ ┃ 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 ┃
29
+ ┃ 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 │ ∅ │ ∅ ┃
30
+ ┃ 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 ┃
31
+ ┃ 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 │ ∅ │ ∅ ┃
32
+ ┃ 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 │ ✗ │ ∅ ┃
33
+ ┃ 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 │ ✗ │ ∅ ┃
34
+ ┃ 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 │ ✗ │ ∅ ┃
35
+ ┃ 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 │ ∅ │ ∅ ┃
36
+ ┃ 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 │ ∅ │ ∅ ┃
37
+ ┃ 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 │ ✗ │ ∅ ┃
38
+ ┃ 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 ┃
39
+ ┃ 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 │ ✗ │ ∅ ┃
40
+ ┃ 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 ┃
41
+ ┃ 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 │ ∅ │ ∅ ┃
42
+ ┃ 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 │ ✗ │ ∅ ┃
43
+ ┃ 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 │ ✗ │ ∅ ┃
44
+ ┃ 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 │ ✗ │ ∅ ┃
45
+ ┃ 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 ┃
46
+ ┃ 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 │ ✗ │ ∅ ┃
47
+ ┠───────┼──────────────────────────────────────┴───────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────┴─────────────────────────┴─────────────────────────┴────────┴─────────────────────────┨
48
+ ┃ Total │ 25 ┃
49
+ ┗━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
50
+ ```
51
+
52
+ ## Installation
53
+
54
+ ### Per-project installation
55
+
56
+ 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:
57
+
58
+ Add `nazar` to Gemfile:
59
+ ```ruby
60
+ group :development, :test do
61
+ gem 'nazar', require: false
62
+ end
63
+ ```
64
+ Then, you have to call `Nazar.enable!`. If you're using Rails, you might want to add this snippet to `config/application.rb`:
65
+
66
+ ```ruby
67
+ console do
68
+ require 'nazar'
69
+
70
+ Nazar.enable! # see configuration section for more options
71
+ end
72
+ ```
73
+ Otherwise, call it in `bin/console` or any other script that launches your REPL.
74
+
75
+ ### Global installation
76
+
77
+ 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.
78
+
79
+ - **Create global gems path**
80
+
81
+ `mkdir -p ~/.gem/ruby/global` - You're welcome to use any other path for your global gemset
82
+ - **Install nazar in your global gemset**
83
+
84
+ `gem install nazar -i ~/.gem/ruby/global`
85
+ - **Load Nazar in your REPL rc file**
86
+ Add following snippet to your `.irbrc` or `.pryrc`:
87
+
88
+ ```ruby
89
+ global_gemset_path = File.expand_path('~/.gem/ruby/global/gems')
90
+
91
+ if Dir.exist?(global_gemset_path)
92
+ global_gems_path = Dir.glob("#{global_gemset_path}/*/lib")
93
+
94
+ $LOAD_PATH.unshift(*global_gems_path)
95
+ end
96
+
97
+ %w[nazar].each do |gem|
98
+ begin
99
+ require gem
100
+ rescue LoadError
101
+ end
102
+ end
103
+
104
+ Nazar.enable! if defined?(Nazar)
105
+ ```
106
+
107
+ ## Configuration
108
+
109
+ 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:
110
+
111
+ `Nazar.enable!(extensions: [:active_record, :csv, :sequel])` will enhance outout for <a href="https://github.com/jeremyevans/sequel/">Sequel</a> as well.
112
+
113
+ You can also configure behaviour of Nazar:
114
+
115
+ | Config | Default | Description |
116
+ | ------ | ------- | ----------- |
117
+ | `Nazar.config.colors.enabled` | true | Determines whether the output should be colorised or not |
118
+ | `Nazar.config.formatter.nil` | `∅` | Sets character printed if the value was nil |
119
+ | `Nazar.config.formatter.boolean` | ['✓', '✗'] | First item in array is a character for `true`, second for `false` |
120
+
9
121
  ## Contributing
10
122
 
11
123
  Bug reports and pull requests are welcome on GitHub at https://github.com/krzyzak/nazar.
data/lib/nazar/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nazar
4
- VERSION = '0.0.8'
4
+ VERSION = '0.0.9'
5
5
  end
data/lib/nazar.rb CHANGED
@@ -68,19 +68,10 @@ module Nazar
68
68
  formatters << Nazar::Formatter.const_get(klass_name)
69
69
  end
70
70
 
71
- def enable_for_irb!
72
- ::IRB::Irb.class_eval do
73
- alias_method :__original_output_value__, :output_value
74
- def output_value(omit = false) # rubocop:disable Style/OptionalBooleanParameter
75
- renderer = Nazar::Renderer.new(@context.last_value)
76
- renderer.valid? ? renderer.render : __original_output_value__(omit)
77
- end
78
- end
79
- end
71
+ def pry_proc
72
+ return unless defined?(Pry)
80
73
 
81
- def enable_for_pry!
82
- @__original_pry_print = Pry.config.print
83
- Pry.config.print = proc do |output, value, instance|
74
+ proc do |output, value, instance|
84
75
  renderer = Nazar::Renderer.new(value)
85
76
  renderer.valid? ? renderer.render : @__original_pry_print.call(output, value, instance)
86
77
  end
@@ -90,16 +81,43 @@ module Nazar
90
81
  return unless @enabled
91
82
 
92
83
  disable_for_irb! if defined?(IRB)
84
+ disable_for_pry! if defined?(Pry)
93
85
 
94
86
  @enabled = false
95
87
  end
96
88
 
89
+ private
90
+
91
+ def enable_for_irb!
92
+ ::IRB::Irb.class_eval do
93
+ alias_method :__original_output_value__, :output_value
94
+ def output_value(omit = false) # rubocop:disable Style/OptionalBooleanParameter
95
+ renderer = Nazar::Renderer.new(@context.last_value)
96
+ renderer.valid? ? renderer.render : __original_output_value__(omit)
97
+ end
98
+ end
99
+ end
100
+
101
+ def enable_for_pry!
102
+ @__original_pry_print ||= Pry.config.print
103
+
104
+ if Pry.toplevel_binding.local_variable_defined?(:pry_instance)
105
+ Pry.toplevel_binding.eval('pry_instance.config.print = Nazar.pry_proc', __FILE__, __LINE__)
106
+ else
107
+ Pry.config.print = Nazar.pry_proc
108
+ end
109
+ end
110
+
97
111
  def disable_for_irb!
98
112
  ::IRB::Irb.send(:alias_method, :output_value, :__original_output_value__)
99
113
  end
100
114
 
101
115
  def disable_for_pry!
102
- nil
116
+ Pry.toplevel_binding.eval(
117
+ 'pry_instance.config.print = Nazar.instance_variable_get(:@__original_pry_print)',
118
+ __FILE__,
119
+ __LINE__
120
+ )
103
121
  end
104
122
  end
105
123
  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.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michał Krzyżanowski
metadata.gz.sig CHANGED
Binary file