ripl-play 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.required_rubygems_version = ">= 1.3.6"
14
14
  s.rubyforge_project = 'tagaholic'
15
15
  s.executables = ['ripl-play', 'ripl-record']
16
- s.add_dependency 'ripl', '>= 0.2.6'
16
+ s.add_dependency 'ripl', '>= 0.2.7'
17
17
  s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile .gemspec}
18
18
  s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
19
19
  s.license = 'MIT'
@@ -1,3 +1,6 @@
1
+ == 0.2.0
2
+ * Add -i option to autoinstall gems detected in input
3
+
1
4
  == 0.1.1
2
5
  * Take out exit words from a recording
3
6
 
@@ -11,11 +11,14 @@ To be able to playback multi-line code:
11
11
 
12
12
  sudo gem install ripl-multi_line
13
13
 
14
+ # Add to ~/.riplrc
15
+ require 'ripl/multi_line'
16
+
14
17
  == Usage
15
18
 
16
- With this plugin, ripl gains commands play and record.
19
+ <tt>ripl play</tt> plays its input, line by line, as if each line were input by a user.
17
20
 
18
- <tt>ripl play</tt> plays its input, line by line, as if each line were input by a user. To play a url:
21
+ To play a url:
19
22
 
20
23
  $ ripl play https://gist.github.com/725338
21
24
  >> a = 10 ** 2
@@ -31,6 +34,13 @@ To playback a url quietly (i.e. you just want to load the url into ripl):
31
34
  >> a + 10
32
35
  >>
33
36
 
37
+ To playback a url with relevant gems automatically installed (you may want to create an rvm
38
+ gemset before doing this)
39
+
40
+ $ ripl play https://gist.github.com/622668 -i
41
+ Can I install the following gems: tilt, erubis ? ([y]/n)
42
+ ....
43
+
34
44
  Urls should point to raw text except for gists and any github file url
35
45
  ({like this}[https://github.com/cldwalker/irbfiles/blob/master/boson/commands/core/string.rb])
36
46
  which are autoconverted.
@@ -4,10 +4,11 @@ require 'ripl'
4
4
  require 'ripl/play'
5
5
 
6
6
  if ARGV.delete('-h') || ARGV.delete('--help')
7
- puts "Usage: ripl-play [-q|--quiet] [-h|--help] [FILE='ripl_play']"
7
+ puts "Usage: ripl-play [-q|--quiet] [-i|--install] [-h|--help] [FILE='ripl_play']"
8
8
  exit
9
9
  end
10
+ Ripl.config[:play_install] = ARGV.delete('-i') || ARGV.delete('--install')
10
11
  Ripl.config[:play_quiet] = ARGV.delete('-q') || ARGV.delete('--quiet')
11
- Ripl.config[:play] = ARGV[0].dup if ARGV[0]
12
+ Ripl.config[:play] = ARGV.shift.dup if ARGV[0]
12
13
 
13
14
  Ripl.start
data/deps.rip CHANGED
@@ -1 +1 @@
1
- ripl >=0.2.6
1
+ ripl >=0.2.7
@@ -1,7 +1,7 @@
1
1
  require 'ripl'
2
2
 
3
3
  module Ripl::Play
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
5
5
 
6
6
  def before_loop
7
7
  super
@@ -48,11 +48,39 @@ module Ripl::Play
48
48
  end
49
49
 
50
50
  def play_back_string(str)
51
+ Ripl::Play.install_gems(str) if config[:play_install]
51
52
  str.split("\n").each {|input|
52
53
  @play_input = input
53
54
  loop_once
54
55
  }
55
56
  end
57
+
58
+ class << self
59
+ def install_gems(str)
60
+ gems = gems_to_install(str)
61
+ return if gems.empty?
62
+ print "Can I install the following gems: #{gems.join(', ')} ? ([y]/n)"
63
+ if $stdin.gets.to_s[/^n/]
64
+ abort "Please install these gems manually: #{gems.join(' ')}"
65
+ else
66
+ system(ENV['GEM'] || 'gem', 'install', *gems)
67
+ end
68
+ end
69
+
70
+ def gems_to_install(str)
71
+ gems = str.scan(/require\s*['"]([^'"\s]+)['"]/).flatten
72
+ gems.reject {|e| requireable(e) }.map {|e|
73
+ e.include?('/') ? e[/^[^\/]+/] : e
74
+ }.uniq.map {|e| e[/^active_/] ? e.sub('_', '') : e }
75
+ end
76
+
77
+ def requireable(lib)
78
+ require lib
79
+ true
80
+ rescue LoadError
81
+ false
82
+ end
83
+ end
56
84
  end
57
85
 
58
86
  Ripl::Shell.send :include, Ripl::Play
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ripl-play
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gabriel Horner
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-03 00:00:00 -05:00
18
+ date: 2010-12-04 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,12 +26,12 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 27
29
+ hash: 25
30
30
  segments:
31
31
  - 0
32
32
  - 2
33
- - 6
34
- version: 0.2.6
33
+ - 7
34
+ version: 0.2.7
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
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.