pry-jist 1.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 +7 -0
- data/lib/pry-jist.rb +4 -0
- data/lib/pry-jist/gist.rb +119 -0
- data/lib/pry-jist/version.rb +3 -0
- data/spec/gist_spec.rb +8 -0
- data/spec/spec_helper.rb +8 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ccf02ebbd1ef8b402e5a0e6256ded5ecb4596d1e
|
4
|
+
data.tar.gz: 2ba17ce2a154dd997a845a65fa0f7ef091918313
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f057736e4aa74137eeb4a0bc5cd560a8266d56b8394a4ff40cdb32cd07e317335f04f148393dace1ab17ce88c906a1fc0194e7de637e376f91817c402db1770f
|
7
|
+
data.tar.gz: 2f4bb22696dbdfd6de981ea6c863329347f9f12e2ba89e274be63001e26ba2d32c5df28e2739796c6453ce10668059be02b22e4711efbb2db8b50f2561fb603d
|
data/lib/pry-jist.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'gist'
|
2
|
+
|
3
|
+
module PryJist
|
4
|
+
# @since v1.0.0
|
5
|
+
class Gist < Pry::ClassCommand
|
6
|
+
match 'gist'
|
7
|
+
group 'Misc'
|
8
|
+
description 'Upload code, docs, history to https://gist.github.com/.'
|
9
|
+
|
10
|
+
banner <<-'BANNER'
|
11
|
+
Usage: gist [OPTIONS] [--help]
|
12
|
+
|
13
|
+
The gist command enables you to gist code from files and methods to github.
|
14
|
+
|
15
|
+
gist -i 20 --lines 1..3
|
16
|
+
gist Pry#repl --lines 1..-1
|
17
|
+
gist Rakefile --lines 5
|
18
|
+
BANNER
|
19
|
+
|
20
|
+
def options(opt)
|
21
|
+
@input_expression_ranges = []
|
22
|
+
@output_result_ranges = []
|
23
|
+
|
24
|
+
opt.on :l, :lines, "Restrict to a subset of lines. Takes a line number or range",
|
25
|
+
optional_argument: true, as: Range, default: 1..-1
|
26
|
+
opt.on :o, :out, "Select lines from Pry's output result history. Takes an index " \
|
27
|
+
"or range",
|
28
|
+
optional_argument: true, as: Range, default: -5..-1 do |r|
|
29
|
+
output_result_ranges << (r || (-5..-1))
|
30
|
+
end
|
31
|
+
opt.on :i, :in, "Select lines from Pry's input expression history. Takes an " \
|
32
|
+
"index or range",
|
33
|
+
optional_argument: true, as: Range, default: -5..-1 do |r|
|
34
|
+
input_expression_ranges << (r || (-5..-1))
|
35
|
+
end
|
36
|
+
opt.on :s, :super, "Select the 'super' method. Can be repeated to traverse " \
|
37
|
+
"the ancestors",
|
38
|
+
as: :count
|
39
|
+
opt.on :d, :doc, "Select lines from the code object's documentation"
|
40
|
+
opt.on :login, "Authenticate the gist gem with GitHub"
|
41
|
+
opt.on :p, :public, "Create a public gist (default: false)", default: false
|
42
|
+
opt.on :clip, "Copy the selected content to clipboard instead, do NOT " \
|
43
|
+
"gist it", default: false
|
44
|
+
end
|
45
|
+
|
46
|
+
def process # rubocop:disable Metrics/AbcSize
|
47
|
+
return ::Gist.login! if opts.present?(:login)
|
48
|
+
|
49
|
+
cc = Pry::Command::CodeCollector.new(args, opts, _pry_)
|
50
|
+
|
51
|
+
raise Pry::CommandError, "Found no code to gist." if cc.content =~ /\A\s*\z/
|
52
|
+
|
53
|
+
if opts.present?(:clip)
|
54
|
+
clipboard_content(cc.content)
|
55
|
+
else
|
56
|
+
# we're overriding the default behavior of the 'in' option (as
|
57
|
+
# defined on CodeCollector) with our local behaviour.
|
58
|
+
content = opts.present?(:in) ? input_content : cc.content
|
59
|
+
gist_content content, cc.file
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def clipboard_content(content)
|
64
|
+
::Gist.copy(content)
|
65
|
+
output.puts "Copied content to clipboard!"
|
66
|
+
end
|
67
|
+
|
68
|
+
def input_content # rubocop:disable Metrics/AbcSize
|
69
|
+
content = ""
|
70
|
+
Pry::Command::CodeCollector.input_expression_ranges.each do |range|
|
71
|
+
input_expressions = _pry_.input_ring[range] || []
|
72
|
+
Array(input_expressions).each_with_index do |code, index|
|
73
|
+
corrected_index = index + range.first
|
74
|
+
next unless code && code != ""
|
75
|
+
|
76
|
+
content << code
|
77
|
+
next unless code !~ /;\Z/
|
78
|
+
|
79
|
+
content << comment_expression_result_for_gist(
|
80
|
+
_pry_.config.gist.inspecter.call(_pry_.output_ring[corrected_index])
|
81
|
+
).to_s
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
content
|
86
|
+
end
|
87
|
+
|
88
|
+
def comment_expression_result_for_gist(result)
|
89
|
+
content = ""
|
90
|
+
result.lines.each_with_index do |line, index|
|
91
|
+
content << index == 0 ? "# => #{line}" : "# #{line}"
|
92
|
+
end
|
93
|
+
|
94
|
+
content
|
95
|
+
end
|
96
|
+
|
97
|
+
def gist_content(content, filename)
|
98
|
+
response = ::Gist.gist(
|
99
|
+
content,
|
100
|
+
filename: filename || "pry_gist.rb",
|
101
|
+
public: !!opts[:p] # rubocop:disable Style/DoubleNegation
|
102
|
+
)
|
103
|
+
return unless response
|
104
|
+
|
105
|
+
url = response['html_url']
|
106
|
+
message = "Gist created at URL #{url}"
|
107
|
+
begin
|
108
|
+
::Gist.copy(url)
|
109
|
+
message << ", which is now in the clipboard."
|
110
|
+
rescue ::Gist::ClipboardError # rubocop:disable Lint/HandleExceptions
|
111
|
+
end
|
112
|
+
|
113
|
+
output.puts message
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
Pry::Commands.add_command(PryJist::Gist)
|
119
|
+
Pry::Commands.alias_command 'clipit', 'gist --clip'
|
data/spec/gist_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pry-jist
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kyrylo Silin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-12 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.12'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: gist
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- silin@kyrylo.org
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- lib/pry-jist.rb
|
77
|
+
- lib/pry-jist/gist.rb
|
78
|
+
- lib/pry-jist/version.rb
|
79
|
+
- spec/gist_spec.rb
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
homepage: http://pryrepl.org
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.9'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.6.13
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Upload code, docs, history to https://gist.github.com/
|
105
|
+
test_files:
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/gist_spec.rb
|