Module: PuppetRepl::Support::Play
- Included in:
- PuppetRepl::Support
- Defined in:
- lib/puppet-repl/support/play.rb
Instance Method Summary collapse
- #convert_to_text(url) ⇒ Object
- #play_back(config = {}) ⇒ Object
- #play_back_string(str) ⇒ Object
- #play_back_url(url) ⇒ Object
Instance Method Details
#convert_to_text(url) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/puppet-repl/support/play.rb', line 17 def convert_to_text(url) require 'uri' url_data = URI(url) case url_data.host when /^github.com/ if url_data.path =~ /blob/ url.gsub('blob', 'raw') end when /^gist.github.com/ unless url_data.path =~ /raw/ url = url += '.txt' end when /^gitlab.com/ if url_data.path =~ /snippets/ url += '/raw' unless url_data.path =~ /raw/ url else url.gsub('blob', 'raw') end else url end end |
#play_back(config = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/puppet-repl/support/play.rb', line 5 def play_back(config={}) if config[:play] if config[:play] =~ /^http/ play_back_url(config[:play]) elsif File.exists? config[:play] play_back_string(File.read(config[:play])) else config[:play] out_buffer.puts "puppet-repl can't play #{config[:play]}'" end end end |
#play_back_string(str) ⇒ Object
53 54 55 |
# File 'lib/puppet-repl/support/play.rb', line 53 def play_back_string(str) handle_input(str) end |
#play_back_url(url) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/puppet-repl/support/play.rb', line 41 def play_back_url(url) begin require 'open-uri' require 'net/http' converted_url = convert_to_text(url) str = open(converted_url).read play_back_string(str) rescue SocketError abort "puppet-repl can't play `#{converted_url}'" end end |