pry-popularity 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pry-popularity.rb +57 -0
- metadata +48 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
class PryPopularity
|
3
|
+
Pry::Commands.create_command 'pry-popularity' do
|
4
|
+
description 'Sort pry input history by frequency of use'
|
5
|
+
command_options :requires_gem => 'jist', :keep_retval => true
|
6
|
+
|
7
|
+
def options opt
|
8
|
+
opt.on :g, :gist, 'Gist the result'
|
9
|
+
end
|
10
|
+
|
11
|
+
def process
|
12
|
+
# TODO accept arg for other file
|
13
|
+
lines = File.readlines Pry.config.history.file
|
14
|
+
popularity = Hash.new 0
|
15
|
+
$stderr.print <<-EOT
|
16
|
+
Found #{lines.size} history lines, scoring (each dot is 100 lines):
|
17
|
+
EOT
|
18
|
+
cache = {}
|
19
|
+
count = 0
|
20
|
+
lines.map do |e|
|
21
|
+
# TODO convert this to a Hash instead, so we can extract
|
22
|
+
# more info (at some point)
|
23
|
+
thing = cache[e]
|
24
|
+
unless thing
|
25
|
+
thing = cache[e] =
|
26
|
+
if cmd = _pry_.commands.find_command(e)
|
27
|
+
cmd.match
|
28
|
+
else
|
29
|
+
'[ruby code]'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
popularity[thing] += 1
|
33
|
+
count += 1
|
34
|
+
if 0 == count % 100
|
35
|
+
$stderr.print '.'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
$stderr.puts
|
39
|
+
|
40
|
+
report = ''
|
41
|
+
popularity.sort_by{|k,v| v}.each do |thing, score|
|
42
|
+
report += "#{score} × #{thing}\n"
|
43
|
+
end
|
44
|
+
output.puts report
|
45
|
+
|
46
|
+
if opts.present? :gist
|
47
|
+
require 'jist'
|
48
|
+
res = Jist.gist report, :filename => 'pry-popularity'
|
49
|
+
output.puts 'Gisted at ' + res['html_url']
|
50
|
+
else
|
51
|
+
warn '(Note that you can run with -g, A.K.A. --gist)'
|
52
|
+
end
|
53
|
+
bangs = '!' * rand(4)
|
54
|
+
"You're a cool guy"+bangs
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pry-popularity
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- rondale-sc
|
9
|
+
- ☈king
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-12-19 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: Sort pry input history by frequency of use
|
16
|
+
email: pry-popularity@sharpsaw.org
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/pry-popularity.rb
|
22
|
+
homepage: http://github.com/rking/pry-popularity
|
23
|
+
licenses:
|
24
|
+
- CC0
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.24
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: Sort pry input history by frequency of use
|
47
|
+
test_files: []
|
48
|
+
has_rdoc:
|