1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Refactor gist to new command-class API

This commit is contained in:
Conrad Irwin 2011-12-31 00:58:24 +00:00
parent d797a209d9
commit 689e47899b

View file

@ -57,27 +57,16 @@ class Pry
require 'pry/command_context'
command("gist", "Gist a method or expression history to github. Type `gist --help` for more info.",{:requires_gem => "gist", :shellwords => false, :definition => Pry::CommandContext.new{
class << self
attr_accessor :opts
command_class "gist", "Gist a method or expression history to github. Type `gist --help` for more info.", :requires_gem => "gist", :shellwords => false do
attr_accessor :content
attr_accessor :code_type
attr_accessor :input_ranges
end
def call(*args)
def initialize
require 'gist'
gather_options(args)
process_options
perform_gist
end
def gather_options(args)
self.input_ranges = []
self.opts = parse_options!(args) do |opt|
def options(opt)
opt.banner unindent <<-USAGE
Usage: gist [OPTIONS] [METH]
Gist method (doc or source) or input expression to github.
@ -85,7 +74,7 @@ class Pry
e.g: gist -m my_method
e.g: gist -d my_method
e.g: gist -i 1..10
USAGE
USAGE
opt.on :d, :doc, "Gist a method's documentation.", true
opt.on :m, :method, "Gist a method's source.", true
@ -97,9 +86,8 @@ class Pry
input_ranges << absolute_index_range(range, _pry_.input_array.length)
end
end
end
def process_options
def run
if opts.present?(:in)
in_option
elsif opts.present?(:file)
@ -109,6 +97,8 @@ class Pry
elsif opts.present?(:method)
method_option
end
perform_gist
end
def in_option
@ -200,8 +190,8 @@ class Pry
end
content
end
}})
end
end
end
end