ripl 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'rubygems' unless Object.const_defined?(:Gem)
3
+ require File.dirname(__FILE__) + "/lib/ripl/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ripl"
7
+ s.version = Ripl::VERSION
8
+ s.authors = ["Gabriel Horner"]
9
+ s.email = "gabriel.horner@gmail.com"
10
+ s.homepage = "http://github.com/cldwlaker/ripl"
11
+ s.summary = "A light, modular alternative to irb"
12
+ s.description = "Ruby Interactive Print Loop - A light, modular alternative to irb"
13
+ s.required_rubygems_version = ">= 1.3.6"
14
+ s.rubyforge_project = 'tagaholic'
15
+ s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile .gemspec}
16
+ s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
17
+ s.license = 'MIT'
18
+ end
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,2 @@
1
+ == 0.1.0
2
+ * Most basic working idea
data/LICENSE.txt ADDED
@@ -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.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ == Description
2
+
3
+ Ruby Interactive Print Loop - A light, modular alternative to irb
4
+
5
+ == Install
6
+
7
+ Install the gem with:
8
+
9
+ sudo gem install ripl
10
+
11
+ == Usage
12
+
13
+ $ ripl
14
+ >> ...
15
+
16
+ == Todo
17
+ * Everything!
data/Rakefile ADDED
@@ -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
data/bin/ripl ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ripl'
4
+ Ripl.start
data/lib/ripl.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'ripl/shell'
2
+ require 'ripl/version'
3
+
4
+ module Ripl
5
+ extend self
6
+
7
+ def start(options={})
8
+ shell(options).loop
9
+ end
10
+
11
+ def shell(options={})
12
+ @shell ||= begin
13
+ require 'ripl/readline_shell'
14
+ ReadlineShell.new(options)
15
+ rescue LoadError
16
+ Shell.new(options)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ module Ripl
2
+ module Completion
3
+ def start_completion
4
+ require 'bond'
5
+ Bond.start
6
+ true
7
+ rescue LoadError
8
+ false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ require 'readline'
2
+ require 'ripl/completion'
3
+
4
+ class Ripl::ReadlineShell < Ripl::Shell
5
+ include Ripl::Completion
6
+
7
+ def get_input
8
+ Readline.readline @options[:prompt], true
9
+ end
10
+
11
+ def history_file
12
+ @history_file ||= File.expand_path(@options[:history])
13
+ end
14
+
15
+ def before_loop
16
+ start_completion
17
+ super
18
+ File.exists?(history_file) &&
19
+ IO.readlines(history_file).each {|e| Readline::HISTORY << e.chomp }
20
+ end
21
+
22
+ def after_loop
23
+ File.open(history_file, 'w') {|f| f.write Readline::HISTORY.to_a.join("\n") }
24
+ end
25
+ end
data/lib/ripl/shell.rb ADDED
@@ -0,0 +1,61 @@
1
+ module Ripl
2
+ class Shell
3
+ OPTIONS = {:name=>'ripl', :line=>1, :result_prompt=>'=> ', :prompt=>'>> ',
4
+ :binding=>TOPLEVEL_BINDING, :irbrc=>'~/.irbrc', :history=>'~/.irb_history'}
5
+
6
+ attr_accessor :line, :binding, :result_prompt
7
+ def initialize(options={})
8
+ @options = OPTIONS.merge options
9
+ @name, @binding, @line = @options.values_at(:name, :binding, :line)
10
+ before_loop
11
+ end
12
+
13
+ def before_loop
14
+ load_rc
15
+ end
16
+
17
+ def load_rc
18
+ load @options[:irbrc] if File.exists?(File.expand_path(@options[:irbrc]))
19
+ end
20
+
21
+ def loop
22
+ while true do
23
+ input = get_input
24
+ break if input == 'exit'
25
+ puts loop_once(input)
26
+ end
27
+ after_loop
28
+ end
29
+
30
+ def after_loop; end
31
+
32
+ def get_input
33
+ print @options[:prompt]
34
+ $stdin.gets.chomp
35
+ end
36
+
37
+ def loop_once(input)
38
+ begin
39
+ result = eval_line(input)
40
+ rescue Exception => e
41
+ print_eval_error(e)
42
+ end
43
+
44
+ eval("_ = #{result.inspect}", @binding) rescue nil
45
+ @line += 1
46
+ format_result result
47
+ end
48
+
49
+ def eval_line(str)
50
+ eval(str, @binding, "(#{@name})", @line)
51
+ end
52
+
53
+ def print_eval_error(e)
54
+ warn "#{e.class}: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
55
+ end
56
+
57
+ def format_result(result)
58
+ @options[:result_prompt] + result.inspect
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module Ripl
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ripl
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-10-27 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Ruby Interactive Print Loop - A light, modular alternative to irb
23
+ email: gabriel.horner@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ - LICENSE.txt
31
+ files:
32
+ - lib/ripl/completion.rb
33
+ - lib/ripl/readline_shell.rb
34
+ - lib/ripl/shell.rb
35
+ - lib/ripl/version.rb
36
+ - lib/ripl.rb
37
+ - bin/ripl
38
+ - LICENSE.txt
39
+ - CHANGELOG.rdoc
40
+ - README.rdoc
41
+ - Rakefile
42
+ - .gemspec
43
+ has_rdoc: true
44
+ homepage: http://github.com/cldwlaker/ripl
45
+ licenses:
46
+ - MIT
47
+ post_install_message:
48
+ rdoc_options: []
49
+
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 23
67
+ segments:
68
+ - 1
69
+ - 3
70
+ - 6
71
+ version: 1.3.6
72
+ requirements: []
73
+
74
+ rubyforge_project: tagaholic
75
+ rubygems_version: 1.3.7
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: A light, modular alternative to irb
79
+ test_files: []
80
+