pry-auto_benching.rb 1.4.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '094e7491e81ac6090aed5660ba17821cfafc5c018bb13e9319d521d99cda1134'
4
- data.tar.gz: f86774af5ba4d4e961c7e66f37496a7d6da6ba4719cd029a3af0049b4de5e3bc
3
+ metadata.gz: be1a301f4640fa309396d5060f2604de2c5cae2874af83386fdb78501d46e516
4
+ data.tar.gz: 339a0fe540e98b1383b01236c22a3393307549463982dcee42db424d0dcb1762
5
5
  SHA512:
6
- metadata.gz: 52f9391138d6c52889c65f9eb1d5ace8e9a5eb453d83d120a46e8b1c110be6e462408c888caf341505781e94113871f603b9f93aa024689acf90dc3c73772ed2
7
- data.tar.gz: c3f5fb37660fae9891db7fd53cc8e4c8eb969bb488b07270f8b2b8de2857c4cb2240a4128e7f0ea12b4a5d3242874a6f00ff80c347b2d08b70b993f1b46d4fb6
6
+ metadata.gz: 2fdc62c926d94143785aef3829dda820e34129edb21318623050437befcef2fefc934aaf196c52d725598fc33aba9b9a3c9472dd04f6e141f71f5ce5a596ee50
7
+ data.tar.gz: c9bc0911ad06d752849ba1c038b1f310702eab85e3c9dcc9d758eebe674d2778de5e3c72ef8c4a37569e638f1d9d6dd12226fa93c5d6ad1951a9e275f5109ec3
data/README.md CHANGED
@@ -20,23 +20,22 @@ Pry.configure do |config|
20
20
  config.auto_benching.clock_type = Process::CLOCK_REALTIME
21
21
 
22
22
  # Configure where benchmark results should be displayed, either
23
- # in the prompt or written to stdout. Default is :prompt.
23
+ # in the prompt or written to `_pry_.output`. Default is :prompt.
24
24
  config.auto_benching.target_display = ':prompt | :output'
25
25
 
26
- # Benchmark results are printed depending on the return value
27
- # of this lambda, by default results are always printed.
28
- config.auto_benching.speak_if = ->(pry, duration) {
29
- duration > 0.5
30
- }
26
+ # Benchmark results are printed or not depending on the return value
27
+ # of this lambda, by default results are printed when duration > 0.0.
28
+ config.auto_benching.display_duration_if = ->(pry, duration) { duration >= 0.2 }
31
29
 
32
30
  # The color to use for benchmark results when `target_display` is :prompt.
33
31
  # The default is :green.
34
32
  config.auto_benching.prompt_color = :red
35
33
 
36
- # A lambda for presenting the benchmark results when `target_display`
37
- # is :output. Default is: "Benchmark: %.2fs".
38
- config.auto_benching.speaker = ->(pry, duration) {
39
- pry.pager.page sprintf("Elapsed time: %.2fs", duration)
34
+ # A lambda that returns a string for display on `_pry_.output` (usually $stdout).
35
+ # This lambda is used when `target_display` is equal to `:output`.
36
+ # Default is: "pry-auto_benching.rb: %.2fs".
37
+ config.auto_benching.output_string = ->(pry, duration) {
38
+ sprintf("elapsed time: %.2fs", duration)
40
39
  }
41
40
  end
42
41
  ```
@@ -1,5 +1,5 @@
1
1
  class Pry
2
2
  module AutoBenching
3
- VERSION = "1.4.0"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
@@ -1,4 +1,16 @@
1
1
  module Pry::AutoBenching
2
+ write_duration = -> (pry, duration) {
3
+ auto_benching = pry.config.auto_benching
4
+ if auto_benching.target_display == :prompt
5
+ pry.config.prompt_name = Pry.lazy { "#{Pry::Helpers::Text.send(auto_benching.prompt_color, duration.to_s + 's')} " }
6
+ elsif auto_benching.target_display == :output
7
+ pry.pager.page auto_benching.output_string.call(pry, duration)
8
+ else
9
+ raise Pry::CommandError,
10
+ "_pry_.config.auto_benching.target_display has an invalid value (#{auto_benching.target_display})"
11
+ end
12
+ }
13
+
2
14
  MEMORY = Hash.new{|h,k| h[k] = [] }
3
15
 
4
16
  BEFORE_EVAL = ->(_, pry) do
@@ -6,36 +18,23 @@ module Pry::AutoBenching
6
18
  MEMORY[pry.hash].push Process.clock_gettime(clock_type)
7
19
  end
8
20
 
9
- write_result = ->(pry, duration) {
10
- target_display = pry.config.auto_benching.target_display
11
- if target_display == :prompt
12
- prompt_color = pry.config.auto_benching.prompt_color
13
- pry.config.prompt_name = Pry.lazy {
14
- "#{Pry::Helpers::Text.send(prompt_color, duration.to_s + 's')} "
15
- }
16
- elsif target_display == :output
17
- pry.config.auto_benching.speaker.call(pry, duration)
18
- else
19
- raise Pry::CommandError, "_pry_.config.auto_benching.target_display has an invalid value (#{target_display})"
20
- end
21
- }
22
-
23
21
  AFTER_EVAL = ->(input, pry) do
24
- clock_type = pry.config.auto_benching.clock_type
25
- duration = (sprintf "%.2f", Process.clock_gettime(clock_type) - MEMORY[pry.hash].pop).to_f
22
+ auto_benching = pry.config.auto_benching
23
+ duration = (sprintf "%.2f", Process.clock_gettime(auto_benching.clock_type) - MEMORY[pry.hash].pop).to_f
26
24
  if input.nil? # Pry command
27
- if pry.config.auto_benching.benchmark_commands and
28
- pry.config.auto_benching.speak_if.call(pry, duration)
29
- write_result.(pry, duration)
25
+ if auto_benching.benchmark_commands and
26
+ auto_benching.display_duration_if.call(pry, duration)
27
+ write_duration.call(pry, duration)
28
+ elsif auto_benching.target_display == :prompt
29
+ pry.config.prompt_name = Pry::Prompt::DEFAULT_NAME
30
30
  end
31
- else
32
- if pry.config.auto_benching.speak_if.call(pry, duration)
33
- write_result.(pry, duration)
34
- else
35
- pry.config.prompt_name = 'pry'
31
+ else # Ruby code
32
+ if auto_benching.display_duration_if.call(pry, duration)
33
+ write_duration.call(pry, duration)
34
+ elsif auto_benching.target_display == :prompt
35
+ pry.config.prompt_name = Pry::Prompt::DEFAULT_NAME
36
36
  end
37
37
  end
38
- pry.config.prompt_name = 'pry' if pry.config.auto_benching.target_display != :prompt
39
38
  end
40
39
 
41
40
  BEFORE_SESSION = ->(_,_, pry) do
@@ -95,13 +94,13 @@ Pry.configure do |config|
95
94
  target_display: :prompt,
96
95
  prompt_color: :green,
97
96
  clock_type: Process::CLOCK_MONOTONIC,
97
+ display_duration_if: ->(pry, duration) { duration > 0.0 },
98
98
  benchmark_commands: true,
99
- speak_if: ->(pry, duration) { duration > 0.0 },
100
- speaker: ->(pry, duration) {
101
- pry.pager.page format("%{AutoBenchingSays} %{Duration}s", {
102
- :AutoBenchingSays => pry.color ?
103
- Pry::Helpers::Text.green("pry-auto_benching.rb:") :
104
- "pry-auto_benching.rb:",
99
+ output_string: ->(pry, duration) {
100
+ format("%{TextDesc} %{Duration}s", {
101
+ :TextDesc => pry.color ?
102
+ Pry::Helpers::Text.green("pry-auto_benching.rb:") :
103
+ "pry-auto_benching.rb:",
105
104
  :Duration => sprintf("%.2f", duration)
106
105
  })
107
106
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-auto_benching.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Gleeson