ripl-play 0.1.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.
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'rubygems' unless Object.const_defined?(:Gem)
3
+ require File.dirname(__FILE__) + "/lib/ripl/play"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ripl-play"
7
+ s.version = Ripl::Play::VERSION
8
+ s.authors = ["Gabriel Horner"]
9
+ s.email = "gabriel.horner@gmail.com"
10
+ s.homepage = "http://github.com/cldwalker/ripl-play"
11
+ s.summary = "A ripl plugin to playback and record inputs in ripl"
12
+ s.description = "A ripl plugin to playback ruby code in ripl coming from files, urls or stdin. Also records a ripl session for playback later."
13
+ s.required_rubygems_version = ">= 1.3.6"
14
+ s.rubyforge_project = 'tagaholic'
15
+ s.executables = ['ripl-play', 'ripl-record']
16
+ s.add_dependency 'ripl', '>= 0.2.5'
17
+ s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile .gemspec}
18
+ s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
19
+ s.license = 'MIT'
20
+ end
@@ -0,0 +1,2 @@
1
+ == 0.1.0
2
+ * Initial release
@@ -0,0 +1,22 @@
1
+ The MIT LICENSE
2
+
3
+ Copyright (c) 2010 Gabriel Horner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,68 @@
1
+ == Description
2
+ A ripl plugin to playback ruby code in ripl coming from files, urls or stdin. Also records a ripl
3
+ session for playback later.
4
+
5
+ == Install
6
+ Install the gem with:
7
+
8
+ sudo gem install ripl-play
9
+
10
+ To be able to playback multi-line code:
11
+
12
+ sudo gem install ripl-multi_line
13
+
14
+ == Usage
15
+
16
+ With this plugin, ripl gains commands play and record.
17
+
18
+ `ripl play` plays its input, line by line, as if each line were input by a user. To play a url:
19
+
20
+ $ ripl play https://gist.github.com/725338
21
+ >> a = 10 ** 2
22
+ => 100
23
+ >> a + 10
24
+ => 110
25
+ >>
26
+
27
+ To playback a url quietly (i.e. you just want to load the url into ripl):
28
+
29
+ $ ripl play https://gist.github.com/725338 -q
30
+ >> a = 10 ** 2
31
+ >> a + 10
32
+ >>
33
+
34
+ Urls should point to raw text except for gists and any github file url
35
+ ({like this}[https://github.com/cldwalker/irbfiles/blob/master/boson/commands/core/string.rb])
36
+ which are autoconverted.
37
+
38
+ `ripl play` can also playback files or from stdin:
39
+
40
+ # Plays script.rb line by line
41
+ $ ripl play script.rb
42
+ >> ...
43
+
44
+ # Plays back last 10 lines of irb history
45
+ $ tail -10 ~/.irb_history | ripl play
46
+ >> ...
47
+
48
+ If you want to share a ripl session for playback later, start ripl with record:
49
+
50
+ # By default record saves to ripl_tape. Pass an argument to explicitly name the file
51
+ $ ripl record
52
+ >> :do_something
53
+ => :do_something
54
+ >> ...
55
+ => ...
56
+ <Control-D>
57
+
58
+ After exiting, the file ripl_tape will contain all of your inputs from that session.
59
+ Now anyone can playback that session with `ripl play`:
60
+
61
+ # play defaults to ripl_tape
62
+ # Assuming you're in the same directory as ripl_tape
63
+ $ ripl play
64
+ >> :do_something
65
+ => :do_something
66
+ >> ...
67
+ => ...
68
+ >>
@@ -0,0 +1,35 @@
1
+ require 'rake'
2
+ require 'fileutils'
3
+
4
+ def gemspec
5
+ @gemspec ||= eval(File.read('.gemspec'), binding, '.gemspec')
6
+ end
7
+
8
+ desc "Build the gem"
9
+ task :gem=>:gemspec do
10
+ sh "gem build .gemspec"
11
+ FileUtils.mkdir_p 'pkg'
12
+ FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
13
+ end
14
+
15
+ desc "Install the gem locally"
16
+ task :install => :gem do
17
+ sh %{gem install pkg/#{gemspec.name}-#{gemspec.version}}
18
+ end
19
+
20
+ desc "Generate the gemspec"
21
+ task :generate do
22
+ puts gemspec.to_ruby
23
+ end
24
+
25
+ desc "Validate the gemspec"
26
+ task :gemspec do
27
+ gemspec.validate
28
+ end
29
+
30
+ desc 'Run tests'
31
+ task :test do |t|
32
+ sh 'bacon -q -Ilib -I. test/*_test.rb'
33
+ end
34
+
35
+ task :default => :test
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ripl'
4
+ require 'ripl/play'
5
+
6
+ if ARGV.delete('-h') || ARGV.delete('--help')
7
+ puts "Usage: ripl-play [-q|--quiet] [-h|--help] [FILE='ripl_play']"
8
+ exit
9
+ end
10
+ Ripl.config[:play_quiet] = ARGV.delete('-q') || ARGV.delete('--quiet')
11
+ Ripl.config[:play] = ARGV[0].dup if ARGV[0]
12
+
13
+ Ripl.start
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ripl'
4
+ require 'ripl/record'
5
+ if ARGV.delete('-h') || ARGV.delete('--help')
6
+ puts "Usage: ripl-record [-h|--help] [FILE='ripl_play']"
7
+ exit
8
+ end
9
+ Ripl.config[:play] = ARGV[0].dup if ARGV[0]
10
+ Ripl.start
@@ -0,0 +1 @@
1
+ ripl >=0.2.5
@@ -0,0 +1,60 @@
1
+ require 'ripl'
2
+
3
+ module Ripl::Play
4
+ VERSION = '0.1.0'
5
+
6
+ def before_loop
7
+ super
8
+ play_back
9
+ config[:play_quiet] = false
10
+ require 'ripl/readline'
11
+ end
12
+
13
+ def print_result(*)
14
+ super unless config[:play_quiet]
15
+ end
16
+
17
+ def get_input
18
+ puts(prompt + @play_input)
19
+ @play_input
20
+ end
21
+
22
+ def play_back
23
+ if !$stdin.tty?
24
+ play_back_string($stdin.read)
25
+ $stdin.reopen '/dev/tty'
26
+ elsif config[:play][/^http/]
27
+ play_back_url(config[:play])
28
+ elsif File.exists? config[:play]
29
+ play_back_string(File.read(config[:play]))
30
+ else
31
+ abort "ripl can't play `#{config[:play]}'"
32
+ end
33
+ end
34
+
35
+ def play_back_url(url)
36
+ require 'open-uri'
37
+ require 'net/http'
38
+
39
+ if url[/gist.github.com\/[a-z\d]+$/]
40
+ url += '.txt'
41
+ elsif url[/github.com.*blob/]
42
+ url.sub!('blob', 'raw')
43
+ end
44
+
45
+ play_back_string open(url).string
46
+ rescue SocketError
47
+ abort "ripl can't play `#{url}'"
48
+ end
49
+
50
+ def play_back_string(str)
51
+ str.split("\n").each {|input|
52
+ @play_input = input
53
+ loop_once
54
+ }
55
+ end
56
+ end
57
+
58
+ Ripl::Shell.send :include, Ripl::Play
59
+ Ripl.config[:readline] = false
60
+ Ripl.config[:play] = 'ripl_tape'
@@ -0,0 +1,12 @@
1
+ require 'ripl'
2
+
3
+ module Ripl::Record
4
+ def after_loop
5
+ super
6
+ saved_history = Array(history).reverse.slice(0, @line - 1).reverse
7
+ File.open(config[:play], 'w') {|f| f.write saved_history.join("\n") }
8
+ end
9
+ end
10
+
11
+ Ripl::Shell.send :include, Ripl::Record
12
+ Ripl.config[:play] = 'ripl_tape'
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ripl-play
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Gabriel Horner
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-12-02 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: ripl
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 29
30
+ segments:
31
+ - 0
32
+ - 2
33
+ - 5
34
+ version: 0.2.5
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: A ripl plugin to playback ruby code in ripl coming from files, urls or stdin. Also records a ripl session for playback later.
38
+ email: gabriel.horner@gmail.com
39
+ executables:
40
+ - ripl-play
41
+ - ripl-record
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - README.rdoc
46
+ - LICENSE.txt
47
+ files:
48
+ - lib/ripl/play.rb
49
+ - lib/ripl/record.rb
50
+ - bin/ripl-play
51
+ - bin/ripl-record
52
+ - LICENSE.txt
53
+ - CHANGELOG.rdoc
54
+ - README.rdoc
55
+ - deps.rip
56
+ - Rakefile
57
+ - .gemspec
58
+ has_rdoc: true
59
+ homepage: http://github.com/cldwalker/ripl-play
60
+ licenses:
61
+ - MIT
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 23
82
+ segments:
83
+ - 1
84
+ - 3
85
+ - 6
86
+ version: 1.3.6
87
+ requirements: []
88
+
89
+ rubyforge_project: tagaholic
90
+ rubygems_version: 1.3.7
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: A ripl plugin to playback and record inputs in ripl
94
+ test_files: []
95
+