ripl-em 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,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'rubygems' unless Object.const_defined?(:Gem)
3
+ require File.dirname(__FILE__) + "/lib/ripl/em"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ripl-em"
7
+ s.version = Ripl::Em::VERSION
8
+ s.authors = ["Gabriel Horner"]
9
+ s.email = "gabriel.horner@gmail.com"
10
+ s.homepage = "http://github.com/cldwalker/ripl-em"
11
+ s.summary = "A ripl plugin to run eventmachine code interactively"
12
+ s.description = "Run EventMachine code in a ripl shell - asynchronously of course"
13
+ s.required_rubygems_version = ">= 1.3.6"
14
+ s.add_dependency 'ripl', '>= 0.4.2'
15
+ s.add_dependency 'eventmachine'
16
+ s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile .gemspec}
17
+ s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
18
+ s.license = 'MIT'
19
+ end
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,2 @@
1
+ == 0.1.0
2
+ * Initial release!
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT LICENSE
2
+
3
+ Copyright (c) 2011 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,29 @@
1
+ == Description
2
+ Run EventMachine code in a ripl shell - asynchronously of course
3
+
4
+ == Install
5
+ Install the gem with:
6
+
7
+ gem install ripl-em
8
+
9
+ == Usage
10
+
11
+ $ ripl em
12
+ >> require 'em-http-request'
13
+ => true
14
+
15
+ >> def get(url); req = EM::HttpRequest.new(url).get; req.callback {|h| puts h.response }; end
16
+ => nil
17
+
18
+ # Make two requests and watch them return in reverse order
19
+ >> get 'http://robolot.herokuapp.com/sleep/10'
20
+ => [#\<Proc:0x00000101a76848@(ripl):4>]
21
+ >> get 'http://robolot.herokuapp.com/sleep/1'
22
+ => [#\<Proc:0x00000101a76848@(ripl):4>]
23
+ Sir, I slept for 1 second(s). Anything else I can zzz...
24
+ Sir, I slept for 10 second(s). Anything else I can zzz...
25
+
26
+ == Todo
27
+ * Autocompletion - Requires an Em::Connection that responds to both newlines and tabs. Any takers? :)
28
+ * Basic Readline behavior - Up/Down Arrow -> Previous/Next history
29
+ * Retry EM loop if callback raises error
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-em ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ripl/em'
4
+ Ripl.start
data/deps.rip ADDED
@@ -0,0 +1,2 @@
1
+ ripl >=0.4.2
2
+ eventmachine >=0
data/lib/ripl/em.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'ripl'
2
+ require 'eventmachine'
3
+
4
+ module Ripl::Em
5
+ VERSION = '0.1.0'
6
+
7
+ def get_input
8
+ history << @input
9
+ @input
10
+ end
11
+
12
+ def in_loop
13
+ catch(:ripl_exit) {
14
+ EM.run { EM.open_keyboard(KeyboardHandler) }
15
+ }
16
+ rescue
17
+ print_eval_error($!)
18
+ end
19
+
20
+ def before_loop
21
+ super
22
+ $stdout.sync = true
23
+ Ripl::Shell::EXIT_WORDS << "\x00" # Ctrl-D + Enter exit
24
+ trap("SIGINT") { handle_interrupt }
25
+ end
26
+
27
+ class KeyboardHandler < EM::Connection
28
+ include EM::Protocols::LineText2
29
+
30
+ def post_init
31
+ print Ripl.shell.prompt
32
+ end
33
+
34
+ def receive_line(line)
35
+ Ripl.shell.input = line
36
+ Ripl.shell.loop_once
37
+ print Ripl.shell.prompt
38
+ end
39
+ end
40
+ end
41
+
42
+ Ripl.config[:readline] = false
43
+ Ripl::Shell.include Ripl::Em
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ripl-em
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Gabriel Horner
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-12 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: ripl
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.4.2
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: eventmachine
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ description: Run EventMachine code in a ripl shell - asynchronously of course
39
+ email: gabriel.horner@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - README.rdoc
46
+ - LICENSE.txt
47
+ files:
48
+ - lib/ripl/em.rb
49
+ - bin/ripl-em
50
+ - LICENSE.txt
51
+ - CHANGELOG.rdoc
52
+ - README.rdoc
53
+ - deps.rip
54
+ - Rakefile
55
+ - .gemspec
56
+ has_rdoc: true
57
+ homepage: http://github.com/cldwalker/ripl-em
58
+ licenses:
59
+ - MIT
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 1.3.6
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.6.2
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: A ripl plugin to run eventmachine code interactively
84
+ test_files: []
85
+