summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/pry/default_commands/gist.rb23
-rw-r--r--lib/pry/wrapped_module.rb2
2 files changed, 11 insertions, 14 deletions
diff --git a/lib/pry/default_commands/gist.rb b/lib/pry/default_commands/gist.rb
index fe0f6a3b..160aa76c 100644
--- a/lib/pry/default_commands/gist.rb
+++ b/lib/pry/default_commands/gist.rb
@@ -22,12 +22,12 @@ class Pry
command_options :shellwords => false
attr_accessor :content
- attr_accessor :code_type
+ attr_accessor :filename
def setup
require 'jist'
self.content = ""
- self.code_type = :ruby
+ self.filename = "a.rb"
end
def options(opt)
@@ -35,23 +35,25 @@ class Pry
opt.on :m, :method, "Gist a method's source.", :argument => true do |meth_name|
meth = get_method_or_raise(meth_name, target, {})
self.content << meth.source << "\n"
- self.code_type = meth.source_type
+ self.filename = meth.source_file
end
opt.on :d, :doc, "Gist a method's documentation.", :argument => true do |meth_name|
meth = get_method_or_raise(meth_name, target, {})
text.no_color do
self.content << process_comment_markup(meth.doc, self.code_type) << "\n"
end
- self.code_type = :plain
+ self.filename = meth.source_file + ".doc"
end
opt.on :k, :command, "Gist a command's source.", :argument => true do |command_name|
command = find_command(command_name)
block = Pry::Method.new(command.block)
self.content << block.source << "\n"
+ self.filename = block.source_file
end
opt.on :c, :class, "Gist a class or module's source.", :argument => true do |class_name|
mod = Pry::WrappedModule.from_str(class_name, target)
self.content << mod.source << "\n"
+ self.filename = mod.source_file
end
opt.on :var, "Gist a variable's content.", :argument => true do |variable_name|
begin
@@ -69,6 +71,7 @@ class Pry
opt.on :f, :file, "Gist a file.", :argument => true do |file|
self.content << File.read(File.expand_path(file)) << "\n"
+ self.filename = file
end
opt.on :o, :out, "Gist entries from Pry's output result history. Takes an index or range.", :optional_argument => true,
:as => Range, :default => -1 do |range|
@@ -120,16 +123,12 @@ class Pry
end
def perform_gist
- type_map = { :ruby => "rb", :c => "c", :plain => "plain" }
-
- extname = opts.present?(:file) ? ".#{gist_file_extension(opts[:f])}" : ".#{type_map[self.code_type]}"
-
if opts.present?(:lines)
self.content = restrict_to_lines(content, opts[:l])
end
- response = Jist.gist(self.content, :filename => extname,
- :public => !!opts[:p])
+ response = Jist.gist(content, :filename => File.basename(filename),
+ :public => !!opts[:p])
if response
copy(response['html_url'])
@@ -137,10 +136,6 @@ class Pry
end
end
- def gist_file_extension(file_name)
- file_name.split(".").last
- end
-
def convert_to_range(n)
if !n.is_a?(Range)
(n..n)
diff --git a/lib/pry/wrapped_module.rb b/lib/pry/wrapped_module.rb
index e587c6cd..190d8dd5 100644
--- a/lib/pry/wrapped_module.rb
+++ b/lib/pry/wrapped_module.rb
@@ -125,12 +125,14 @@ class Pry
def file
Array(source_location).first
end
+ alias_method :source_file, :file
# @return [Fixnum, nil] The associated line for the module (i.e
# the primary candidate: highest ranked monkeypatch).
def line
Array(source_location).last
end
+ alias_method :source_line, :line
# Returns documentation for the module, with preference given to yard docs if
# available. This documentation is for the primary candidate, if