module Ripl::Play
Constants
- VERSION
Public Class Methods
gems_to_install(str)
click to toggle source
# File lib/ripl/play.rb, line 70 def gems_to_install(str) gems = str.scan(/require\s*['"]([^'"\s]+)['"]/).flatten gems.reject {|e| requireable(e) }.map {|e| e.include?('/') ? e[/^[^\/]+/] : e }.uniq.map {|e| e[/^active_/] ? e.sub('_', '') : e } end
install_gems(str)
click to toggle source
# File lib/ripl/play.rb, line 59 def install_gems(str) gems = gems_to_install(str) return if gems.empty? print "Can I install the following gems: #{gems.join(', ')} ? ([y]/n)" if $stdin.gets.to_s[/^n/] abort "Please install these gems manually: #{gems.join(' ')}" else system(ENV['GEM'] || 'gem', 'install', *gems) end end
requireable(lib)
click to toggle source
# File lib/ripl/play.rb, line 77 def requireable(lib) require lib true rescue LoadError false end
Public Instance Methods
before_loop()
click to toggle source
Calls superclass method
# File lib/ripl/play.rb, line 6 def before_loop super play_back config[:play_quiet] = false require 'ripl/readline' end
get_input()
click to toggle source
# File lib/ripl/play.rb, line 17 def get_input puts(prompt + @play_input) @play_input end
play_back()
click to toggle source
# File lib/ripl/play.rb, line 22 def play_back if !$stdin.tty? play_back_string($stdin.read) $stdin.reopen '/dev/tty' elsif config[:play][/^http/] play_back_url(config[:play]) elsif File.exists? config[:play] play_back_string(File.read(config[:play])) else abort "ripl can't play `#{config[:play]}'" end end
play_back_string(str)
click to toggle source
# File lib/ripl/play.rb, line 50 def play_back_string(str) Ripl::Play.install_gems(str) if config[:play_install] str.split("\n").each {|input| @play_input = input loop_once } end
play_back_url(url)
click to toggle source
# File lib/ripl/play.rb, line 35 def play_back_url(url) require 'open-uri' require 'net/http' if url[/gist.github.com\/[a-z\d]+$/] url += '.txt' elsif url[/github.com.*blob/] url.sub!('blob', 'raw') end play_back_string open(url).string rescue SocketError abort "ripl can't play `#{url}'" end
print_result(*)
click to toggle source
Calls superclass method
# File lib/ripl/play.rb, line 13 def print_result(*) super unless config[:play_quiet] end