pry-larry 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8de86f32c7be4710144ba5781385d2114d7ca5ba
4
+ data.tar.gz: 13b0cdda5e0351baba30e35b0c81ddaa65069955
5
+ SHA512:
6
+ metadata.gz: 1e276eaf3307a5dae9f262153a7f4cc30d5eff36ce15dd0336a80700902d1c85b8e50cde33a3df0f13deaf55056f2e09d16cec338f3c1a04da50b9015780d2b5
7
+ data.tar.gz: e1cc0f9f2f3b7f5a149dd400e236ac2bc1ab046a5688eb051295d8873ad439bb25af971daf66e10f184060b286d568ba10966228722055bbd43810a93d476bab
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ Gemfile.lock
2
+ *#
3
+ *~
4
+ *.gem
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ __v0.3.0__
2
+ * The Larry command aliases "start" as "wakeup", and "stop" as "chill".
3
+ * Add a 'banner' to the 'larry' command.
4
+ * Print confirmation when running the 'larry start' and 'larry stop' commands.
5
+
6
+ __v0.2.0__
7
+
8
+ * Change the default of 'auto_start' configuration option to true.
9
+ * Change the default implementation of 'speak_if' configuration option to return true when 'walltime' is > 0.1s.
10
+ * Move the conditional require of 'pry' to top of lib/pry-larry.rb file.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ [![Code Climate](https://codeclimate.com/github/jazzonmymind/pry-larry.rb/badges/gpa.svg)](https://codeclimate.com/github/jazzonmymind/pry-larry.rb)
2
+
3
+ __pry-larry.rb__
4
+
5
+ Larry is a plugin for Pry.
6
+ He keeps track of elapsed wall-clock time and tells you how long code or a Pry command
7
+ you ran took to complete.
8
+
9
+ __Configuration__
10
+
11
+ The `.pryrc` file in your home directory or in the current working directory can be used
12
+ to change the defaults of Larry. The example uses an API from Pry that might not be released
13
+ yet(`Pry.configure`) but the old way is [still supported](https://github.com/pry/pry/pull/1502).
14
+
15
+ ```ruby
16
+ Pry.configure do |config|
17
+ config.larry.auto_start = false # default is true
18
+ config.larry.speak_if = ->(walltime) { # default is speak if walltime is > 0.1s
19
+ walltime > 0.5
20
+ }
21
+ end
22
+ ```
23
+
24
+ __Examples__
25
+
26
+ __1.__
27
+
28
+ ![Screenshot Example](http://i.imgur.com/iMEChec.png)
29
+
30
+ __Install__
31
+
32
+ There isn't a published gem on rubygems.org but there is a gemspec in the repository
33
+ that can be used to build a gem from source. If you are using Bundler the git repository
34
+ can be used to build a gem:
35
+
36
+ ```ruby
37
+ gem "pry-larry", git: "https://github.com/jazzonmymind/pry-larry.rb.git", tag: "v0.3.0"
38
+ ```
39
+
40
+ __License__
41
+
42
+ ```
43
+ This is free and unencumbered software released into the public domain.
44
+
45
+ Anyone is free to copy, modify, publish, use, compile, sell, or
46
+ distribute this software, either in source code form or as a compiled
47
+ binary, for any purpose, commercial or non-commercial, and by any
48
+ means.
49
+
50
+ In jurisdictions that recognize copyright laws, the author or authors
51
+ of this software dedicate any and all copyright interest in the
52
+ software to the public domain.
53
+
54
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
55
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
56
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
57
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
58
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
59
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
60
+ OTHER DEALINGS IN THE SOFTWARE.
61
+ ```
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'bundler/setup'
2
+ Bundler.require :default
3
+ task :default do
4
+ TOPLEVEL_BINDING.pry
5
+ end
@@ -0,0 +1,5 @@
1
+ class Pry
2
+ module Larry
3
+ VERSION = "0.3.0"
4
+ end
5
+ end
data/lib/pry-larry.rb ADDED
@@ -0,0 +1,76 @@
1
+ require 'pry' if not defined?(Pry::ClassCommand)
2
+ module Pry::Larry
3
+ MESSAGE_FORMAT = "%{LarrySays} %{WallTime}s"
4
+ MEMORY = Hash.new{|h,k| h[k] = [] }
5
+ BEFORE_EVAL = ->(_, pry) do
6
+ MEMORY[pry.hash].push Time.now.to_f
7
+ end
8
+ AFTER_EVAL = ->(_, pry) do
9
+ walltime = Time.now.to_f - MEMORY[pry.hash][-1]
10
+ if pry.config.larry.speak_if.call(walltime)
11
+ pry.pager.page MESSAGE_FORMAT % {
12
+ :LarrySays => Pry::Helpers::Text.green("Larry says:"),
13
+ :WallTime => sprintf("%.2f", walltime)
14
+ }
15
+ end
16
+ end
17
+ BEFORE_SESSION = ->(_,_, pry) do
18
+ Pry::Larry.start(pry) if pry.config.larry.auto_start
19
+ end
20
+ AFTER_SESSION = ->(_, _, pry) do
21
+ MEMORY.delete(pry.hash)
22
+ end
23
+
24
+ def self.start(pry)
25
+ if not pry.config.hooks.hook_exists? :before_eval, BEFORE_EVAL.hash
26
+ pry.config.hooks.add_hook :before_eval, BEFORE_EVAL.hash, BEFORE_EVAL
27
+ pry.config.hooks.add_hook :after_eval, AFTER_EVAL.hash , AFTER_EVAL
28
+ pry.config.hooks.add_hook :after_session, AFTER_SESSION.hash , AFTER_SESSION
29
+ end
30
+ end
31
+
32
+ def self.stop(pry)
33
+ pry.config.hooks.delete_hook :before_eval, BEFORE_EVAL.hash
34
+ pry.config.hooks.delete_hook :after_eval , AFTER_EVAL.hash
35
+ pry.config.hooks.delete_hook :after_session , AFTER_SESSION.hash
36
+ MEMORY[pry.hash].clear
37
+ end
38
+
39
+ class << self
40
+ alias_method :wakeup, :start
41
+ alias_method :chill, :stop
42
+ end
43
+
44
+ class LarryCommand < Pry::ClassCommand
45
+ match /larry (start|wakeup|stop|chill)\z/
46
+ group 'pry-larry'
47
+ description 'Ask larry to start or stop counting wall-clock time.'
48
+ command_options argument_required: true
49
+ banner <<-CMDBANNER
50
+ Usage: larry [start|stop]
51
+ Ask Larry to start or stop counting wall clock time.
52
+ CMDBANNER
53
+
54
+ TENSE_MAPPING = {
55
+ 'start' => 'started',
56
+ 'wakeup' => 'woken up',
57
+ 'chill' => 'chilled',
58
+ 'stop' => 'stopped'
59
+ }
60
+ TENSE_MAPPING.default_proc = lambda{|k,h| k}
61
+ START_COMMANDS = ["start", "wakeup"]
62
+
63
+ def process(input)
64
+ if START_COMMANDS.include?(input)
65
+ Pry::Larry.start(_pry_)
66
+ _pry_.pager.page("Alright, I have #{TENSE_MAPPING[input]}.")
67
+ else
68
+ Pry::Larry.stop(_pry_)
69
+ _pry_.pager.page("Alright, I have #{TENSE_MAPPING[input]}.")
70
+ end
71
+ end
72
+ end
73
+ Pry::Commands.add_command(LarryCommand)
74
+ Pry.config.hooks.add_hook :before_session, BEFORE_SESSION.hash, BEFORE_SESSION
75
+ Pry.config.larry = Pry::Config.from_hash({auto_start: true, speak_if: ->(walltime){ walltime > 0.1 }}, nil)
76
+ end
data/pry-larry.gemspec ADDED
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.push './lib'
2
+ require 'pry-larry/version'
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "pry-larry"
5
+ spec.version = Pry::Larry::VERSION
6
+ spec.authors = ["jazzonmymind"]
7
+ spec.email = "robert@jazzonmymind.xyz"
8
+ spec.summary = "Larry is a plugin for Pry that tracks wall clock time."
9
+ spec.description = "Larry keeps track of elapsed wall-clock time and tells you how long code or a Pry command you ran took to complete."
10
+ spec.homepage = "https://github.com/jazzonmymind/pry-larry.rb"
11
+ spec.licenses = ['Nonstandard']
12
+ spec.add_runtime_dependency "pry", "~> 0.10"
13
+ spec.files = `git ls-files`.each_line.map {|s| s.strip.chomp }
14
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pry-larry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - jazzonmymind
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.10'
27
+ description: Larry keeps track of elapsed wall-clock time and tells you how long code
28
+ or a Pry command you ran took to complete.
29
+ email: robert@jazzonmymind.xyz
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - CHANGELOG.md
36
+ - Gemfile
37
+ - README.md
38
+ - Rakefile
39
+ - lib/pry-larry.rb
40
+ - lib/pry-larry/version.rb
41
+ - pry-larry.gemspec
42
+ homepage: https://github.com/jazzonmymind/pry-larry.rb
43
+ licenses:
44
+ - Nonstandard
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.5.1
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Larry is a plugin for Pry that tracks wall clock time.
66
+ test_files: []
67
+ has_rdoc: