irb-power_assert 0.2.0 → 0.3.1

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: 6c7d86f7b11fc69ce48487d130a5e3b32fb65925ba3f96a99034d676b2ffea0a
4
- data.tar.gz: 48c6d1db24acd71805152e9212f4d3f2a1885523f54d773697c31004a9d3a940
3
+ metadata.gz: 34cab348502eee4a1187962266285e636698fa21fd0b79f95f1a7ca36f1fe498
4
+ data.tar.gz: d4c4e37efd959eea65260eda2aca9388a083382459bd7fc3db8ecc6b488bb2ae
5
5
  SHA512:
6
- metadata.gz: a9e5c07f853b5b654bfc53479b213c2c548f1c66f57d625ee835453bccb94c414b25e6d46dd4f09b10e5fdf5334249cda29e4284782a67eac0a5a4846b115417
7
- data.tar.gz: 52e92b6370fa6ef874955b7ca859d4b74b578e0dd68e3c6db6699b7197e1db97fd7b2f3548a0b872c832c245cb71cd6f9c1477b4f0331f543394dcf08442e3eb
6
+ metadata.gz: 71f5530d85217e1493182c8c9078f0a3271c41d2b386c7f5b9e9221ac7b237cd56325862c767fac6dfefaf3c980df9381376c63d7485f699564fb5f7685c0beb
7
+ data.tar.gz: 9fc63bdefc97312dcfc16a1e7afd543a1ce30252956aadc321bd44112d38afa1291b5be4771a617d1dbd6eb4f37f897199d9990d935439722e86c2e44ed4d74e
data/README.md CHANGED
@@ -3,34 +3,21 @@
3
3
  [![Build Status](https://github.com/kachick/irb-power_assert/actions/workflows/ci-ruby.yml/badge.svg?branch=main)](https://github.com/kachick/irb-power_assert/actions/workflows/ci-ruby.yml?query=branch%3Amain+)
4
4
  [![Gem Version](https://badge.fury.io/rb/irb-power_assert.svg)](http://badge.fury.io/rb/irb-power_assert)
5
5
 
6
- ## Overview
7
-
8
- ![screenshot - expression](https://user-images.githubusercontent.com/1180335/119386011-efc1bb00-bd01-11eb-80c4-1aea86fa3781.png)
9
-
10
- [ruby/power_assert](https://github.com/ruby/power_assert) is a recent my favorites.\
11
- (the author is [@k-tsj](https://github.com/k-tsj), thank you!)
12
-
13
- It is super helpful in complex testing.
14
-
15
- Don't say [ruby/irb](https://github.com/ruby/irb) is old-fashioned.
16
-
17
- I just would get irb version of
18
- [yui-knk/pry-power_assert](https://github.com/yui-knk/pry-power_assert)
19
-
20
- Honor should be bestowed upon them.
6
+ Use power_assert inspection in irb
21
7
 
22
8
  ## Usage
23
9
 
24
- Require Ruby 3.1 or higher # Tested only in ruby-head and the last 2 stable versions
10
+ Tested only in ruby-head and the last 2 stable versions\
11
+ So require Ruby 3.2 or higher
25
12
 
26
13
  ```console
27
14
  $ gem install irb-power_assert
28
- Should be installed!
15
+ ...installed
29
16
  ```
30
17
 
31
18
  ```console
32
19
  $ irb -r irb-power_assert
33
- # Then enabled this gem!
20
+ # enabled this gem
34
21
  ```
35
22
 
36
23
  Or specify in your `~/.irbrc` as below
@@ -41,37 +28,14 @@ require 'irb/power_assert'
41
28
 
42
29
  ```console
43
30
  $ irb
44
- # Then enabled this gem!
31
+ irb(main):004> help pa
32
+ Print PowerAssert inspection for the given expression.
45
33
  ```
46
34
 
47
35
  Then you can use `pa` as an IRB command.
48
36
 
49
- ```ruby
50
- irb(main):001:0> pa %q{ "0".class == "3".to_i.times.map {|i| i + 1 }.class }
51
- result: false
52
-
53
- "0".class == "3".to_i.times.map {|i| i + 1 }.class
54
- | | | | | |
55
- | | | | | Array
56
- | | | | [1, 2, 3]
57
- | | | #<Enumerator: ...>
58
- | | 3
59
- | false
60
- String
61
- => nil
62
- ```
63
-
64
- The `pa` just takes strings of the code.
65
-
66
- If you want to directly pass `expression`, [.irbrc](examples/.irbrc) is the hack for single line code.\
67
- if you don't have the file yet, putting the file as one of your `$IRBRC`, `$XDG_CONFIG_HOME/irb/irbrc` or `$HOME/.irbrc`
68
-
69
- Then you can use the `pa` as below...
70
-
71
37
  ```ruby
72
38
  irb(main):001:0> pa "0".class == "3".to_i.times.map {|i| i + 1 }.class
73
- result: false
74
-
75
39
  "0".class == "3".to_i.times.map {|i| i + 1 }.class
76
40
  | | | | | |
77
41
  | | | | | Array
@@ -80,11 +44,31 @@ result: false
80
44
  | | 3
81
45
  | false
82
46
  String
83
- => nil
47
+
48
+ => false
84
49
  ```
85
50
 
51
+ No hack is needed in your irbrc
52
+
53
+ ## Thanks!
54
+
55
+ [ruby/power_assert](https://github.com/ruby/power_assert) is a recent my favorites.\
56
+ (the author is [@k-tsj](https://github.com/k-tsj), thank you!)
57
+
58
+ It is super helpful in complex testing.
59
+
60
+ Don't say [ruby/irb](https://github.com/ruby/irb) is old-fashioned.
61
+
62
+ I just would get irb version of
63
+ [yui-knk/pry-power_assert](https://github.com/yui-knk/pry-power_assert).
64
+
65
+ Latest IRB is much helpful to [create own command](https://github.com/ruby/irb/pull/886)
66
+
67
+ Honor should be bestowed upon them.
68
+
86
69
  ## References
87
70
 
88
71
  - [power-assert-js/power-assert](https://github.com/power-assert-js/power-assert)
89
72
  - [Power Assert in Ruby](https://speakerdeck.com/k_tsj/power-assert-in-ruby)
90
73
  - [ja - IRB is new than Pry](https://k0kubun.hatenablog.com/entry/2021/04/02/211455)
74
+ - [pry-power_assert implementation](https://github.com/yui-knk/pry-power_assert/blob/2d10ee3df8efaf9c448f31d51bff8033a1792739/lib/pry-power_assert.rb#L26-L35)
data/lib/irb/cmd/pa.rb CHANGED
@@ -1,24 +1,45 @@
1
1
  # coding: us-ascii
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'irb/cmd/nop'
5
4
  require 'power_assert'
6
5
  require 'power_assert/colorize'
7
6
 
8
7
  module IRB
9
- module ExtendCommand
10
- class Pa < Nop
11
- def execute(expression)
12
- # The implementation basically taken from https://github.com/yui-knk/pry-power_assert/blob/2d10ee3df8efaf9c448f31d51bff8033a1792739/lib/pry-power_assert.rb#L26-L35, thank you!
13
- result = +'result: '
14
-
15
- ::PowerAssert.start(expression, source_binding: irb_context.workspace.binding) do |pa|
16
- result << pa.yield.inspect << "\n\n"
17
- result << pa.message_proc.call
18
- end
19
-
20
- puts result
8
+ class PaCommand < IRB::Command::Base
9
+ description 'Show inspections for each result.'
10
+ category 'Misc'
11
+ help_message 'Print PowerAssert inspection for the given expression.'
12
+
13
+ def usage
14
+ <<~'EOD'
15
+ `pa` command will work for expressions that includes method calling.
16
+ e.g. `pa (2 * 3 * 7).abs == 1010102.to_s.to_i(2)`
17
+ EOD
18
+ end
19
+
20
+ def execute(expression)
21
+ if expression == ''
22
+ # Avoid warn and raise here, warn does not appear in irb and exception sounds like a IRB bug
23
+ puts usage
24
+ return
25
+ end
26
+
27
+ result = nil
28
+ inspection = nil
29
+ ::PowerAssert.start(expression, source_binding: irb_context.workspace.binding) do |pa|
30
+ result = pa.yield
31
+ inspection = pa.message_proc.call
21
32
  end
33
+
34
+ if inspection == ''
35
+ puts usage
36
+ else
37
+ puts inspection, "\n"
38
+ end
39
+
40
+ puts "=> #{result.inspect}"
22
41
  end
23
42
  end
43
+
44
+ Command.register(:pa, PaCommand)
24
45
  end
@@ -3,6 +3,6 @@
3
3
 
4
4
  module IRB
5
5
  module PowerAssert
6
- VERSION = '0.2.0'
6
+ VERSION = '0.3.1'
7
7
  end
8
8
  end
@@ -4,19 +4,10 @@
4
4
 
5
5
  require 'irb'
6
6
  require 'power_assert'
7
- require_relative 'cmd/pa'
8
-
9
- module IRB
10
- module PowerAssert
11
- end
12
-
13
- module ExtendCommandBundle
14
- def_extend_command(:irb_pa, :Pa, "#{__dir__}/cmd/pa.rb", [:pa, NO_OVERRIDE])
15
- end
16
- end
7
+ require_relative 'power_assert/version'
17
8
 
18
9
  module PowerAssert
19
10
  INTERNAL_LIB_DIRS[IRB::PowerAssert] = File.dirname(File.dirname(caller_locations(1, 1).first.path))
20
11
  end
21
12
 
22
- require_relative 'power_assert/version'
13
+ require_relative 'cmd/pa'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irb-power_assert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenichi Kamiya
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 1980-01-01 00:00:00.000000000 Z
11
+ date: 2024-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: irb
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.4.1
19
+ version: 1.13.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '2.0'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 1.4.1
29
+ version: 1.13.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2.0'
@@ -50,7 +50,7 @@ dependencies:
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '3.0'
53
- description: power_assert in irb
53
+ description: Use power_assert inspection in irb
54
54
  email:
55
55
  - kachick1+ruby@gmail.com
56
56
  executables: []
@@ -67,11 +67,10 @@ homepage: https://github.com/kachick/irb-power_assert
67
67
  licenses:
68
68
  - MIT
69
69
  metadata:
70
- homepage_uri: https://github.com/kachick/irb-power_assert
71
70
  source_code_uri: https://github.com/kachick/irb-power_assert
72
71
  bug_tracker_uri: https://github.com/kachick/irb-power_assert/issues
73
72
  rubygems_mfa_required: 'true'
74
- post_install_message:
73
+ post_install_message:
75
74
  rdoc_options: []
76
75
  require_paths:
77
76
  - lib
@@ -79,15 +78,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
78
  requirements:
80
79
  - - ">="
81
80
  - !ruby/object:Gem::Version
82
- version: '3.1'
81
+ version: '3.2'
83
82
  required_rubygems_version: !ruby/object:Gem::Requirement
84
83
  requirements:
85
84
  - - ">="
86
85
  - !ruby/object:Gem::Version
87
86
  version: '0'
88
87
  requirements: []
89
- rubygems_version: 3.4.10
90
- signing_key:
88
+ rubygems_version: 3.5.3
89
+ signing_key:
91
90
  specification_version: 4
92
91
  summary: power_assert in irb
93
92
  test_files: []