bombshell 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
data/bombshell.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bombshell}
8
- s.version = "0.0.0"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andy Rossmeissl"]
12
- s.date = %q{2011-01-24}
12
+ s.date = %q{2011-03-07}
13
13
  s.description = %q{Custom IRB consoles made easy}
14
14
  s.email = %q{andy@rossmeissl.net}
15
15
  s.extra_rdoc_files = [
@@ -25,7 +25,13 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "bombshell.gemspec",
28
+ "doc/brainstorm.rb",
28
29
  "lib/bombshell.rb",
30
+ "lib/bombshell/completor.rb",
31
+ "lib/bombshell/environment.rb",
32
+ "lib/bombshell/irb.rb",
33
+ "lib/bombshell/shell.rb",
34
+ "lib/bombshell/shell/commands.rb",
29
35
  "spec/bombshell_spec.rb",
30
36
  "spec/spec_helper.rb"
31
37
  ]
data/doc/brainstorm.rb ADDED
@@ -0,0 +1,56 @@
1
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'bombshell'
3
+
4
+ module Foo
5
+ class Shell < Bombshell::Environment
6
+ include Bombshell::Shell
7
+
8
+ before_launch do
9
+ @punctuation = '!'
10
+ end
11
+
12
+ before_launch do |arg|
13
+ puts arg if arg
14
+ end
15
+
16
+ having_launched do
17
+ @msg = 'Done' + self.class.punctuation
18
+ end
19
+
20
+ having_launched do
21
+ puts 'Welcome to FooShell'
22
+ end
23
+
24
+ prompt_with do
25
+ punctuation
26
+ end
27
+
28
+ def do_something
29
+ puts @msg
30
+ end
31
+
32
+ def sub
33
+ Subshell.launch
34
+ end
35
+
36
+ class << self
37
+ def punctuation
38
+ @punctuation
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ module Foo
45
+ class Subshell < Bombshell::Environment
46
+ include Bombshell::Shell
47
+
48
+ def do_something_else
49
+ puts '... and done'
50
+ end
51
+
52
+ prompt_with '[foo::subshell]'
53
+ end
54
+ end
55
+
56
+ Bombshell.launch(Foo::Shell)
data/lib/bombshell.rb CHANGED
@@ -0,0 +1,22 @@
1
+ require 'irb'
2
+
3
+ require 'bombshell/shell'
4
+ require 'bombshell/completor'
5
+ require 'bombshell/environment'
6
+ require 'bombshell/irb'
7
+
8
+ module Bombshell
9
+ def launch(shell)
10
+ begin
11
+ failure = shell.launch(ARGV.dup)
12
+ Kernel.exit(failure ? 1 : 0)
13
+ rescue SystemExit => e
14
+ Kernel.exit(e.status)
15
+ rescue Exception => e
16
+ STDERR.puts("#{e.message} (#{e.class})")
17
+ STDERR.puts(e.backtrace.join("\n"))
18
+ Kernel.exit(1)
19
+ end
20
+ end
21
+ module_function :launch
22
+ end
@@ -0,0 +1,18 @@
1
+ module Bombshell
2
+ class Completor
3
+ def initialize(shell)
4
+ @shell = shell
5
+ end
6
+
7
+ attr_reader :shell
8
+
9
+ def complete(fragment)
10
+ self.class.filter(shell.instance_methods).grep Regexp.new(Regexp.quote(fragment))
11
+ end
12
+
13
+ def self.filter(m)
14
+ m - Bombshell::Environment.instance_methods - Bombshell::Shell::Commands::HIDE
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,8 @@
1
+ module Bombshell
2
+ class Environment
3
+ instance_methods.each do |m|
4
+ undef_method m if m.to_s !~ /(?:^__|^nil\?$|^send$|^instance_eval$|^define_method$|^class$|^object_id|^instance_methods$)/
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ module IRB
4
+ def self.start_session(binding)
5
+ unless @__initialized
6
+ args = ARGV
7
+ ARGV.replace(ARGV.dup)
8
+ IRB.setup(nil)
9
+ ARGV.replace(args)
10
+ @__initialized = true
11
+ end
12
+
13
+ workspace = WorkSpace.new(binding)
14
+
15
+ @CONF[:PROMPT][:CARBON] = {
16
+ :PROMPT_I => "%m> ",
17
+ :PROMPT_S => "%m\"> ",
18
+ :PROMPT_C => "%m…>",
19
+ :PROMPT_N => "%m→>",
20
+ :RETURN => ''
21
+ }
22
+ @CONF[:PROMPT_MODE] = :CARBON
23
+
24
+ irb = Irb.new(workspace)
25
+
26
+ ::Readline.completion_proc = Bombshell::Completor.new(eval('self.class', binding)).method(:complete)
27
+
28
+ @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
29
+ @CONF[:MAIN_CONTEXT] = irb.context
30
+ catch(:IRB_EXIT) do
31
+ irb.eval_input
32
+ end
33
+ end
34
+ end
35
+
@@ -0,0 +1,62 @@
1
+ require 'bombshell/shell/commands'
2
+
3
+ module Bombshell
4
+ module Shell
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ base.instance_variable_set :@bombshell_callbacks, :before_launch => [], :having_launched => []
8
+ end
9
+
10
+ def to_s
11
+ _prompt
12
+ end
13
+
14
+ include Commands
15
+
16
+ def _prompt
17
+ if self.class.bombshell_prompt.is_a? String
18
+ self.class.bombshell_prompt
19
+ elsif self.class.bombshell_prompt.is_a? Proc and self.class.bombshell_prompt.arity == 1
20
+ self.class.bombshell_prompt.call self
21
+ elsif self.class.bombshell_prompt.is_a? Proc
22
+ self.class.bombshell_prompt.call
23
+ else
24
+ '[Bombshell]'
25
+ end
26
+ end
27
+
28
+ def get_binding
29
+ binding
30
+ end
31
+
32
+ module ClassMethods
33
+ def launch(arguments = [])
34
+ @bombshell_callbacks[:before_launch].each do |callback|
35
+ callback.call(*arguments.first(callback.arity))
36
+ end
37
+ shell = new
38
+ @bombshell_callbacks[:having_launched].each do |callback|
39
+ shell.instance_eval &callback
40
+ end
41
+ ::IRB.start_session(shell.get_binding)
42
+ end
43
+
44
+ def before_launch(&callback)
45
+ @bombshell_callbacks[:before_launch] << callback
46
+ end
47
+
48
+ def having_launched(&callback)
49
+ @bombshell_callbacks[:having_launched] << callback
50
+ end
51
+
52
+ def prompt_with(p = nil, &prompt)
53
+ @bombshell_prompt = p || prompt
54
+ end
55
+
56
+ def bombshell_prompt
57
+ @bombshell_prompt
58
+ end
59
+ end
60
+ end
61
+ end
62
+
@@ -0,0 +1,17 @@
1
+ module Bombshell
2
+ module Shell
3
+ module Commands
4
+ HIDE = [:method_missing, :get_binding, :_prompt, :to_s]
5
+
6
+ def quit
7
+ exit
8
+ end
9
+ def method_missing(*args)
10
+ return if [:extend, :respond_to?].include? args.first
11
+ puts "Unknown command #{args.first}"
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bombshell
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 0.0.0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andy Rossmeissl
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-24 00:00:00 -05:00
18
+ date: 2011-03-07 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -98,7 +98,13 @@ files:
98
98
  - Rakefile
99
99
  - VERSION
100
100
  - bombshell.gemspec
101
+ - doc/brainstorm.rb
101
102
  - lib/bombshell.rb
103
+ - lib/bombshell/completor.rb
104
+ - lib/bombshell/environment.rb
105
+ - lib/bombshell/irb.rb
106
+ - lib/bombshell/shell.rb
107
+ - lib/bombshell/shell/commands.rb
102
108
  - spec/bombshell_spec.rb
103
109
  - spec/spec_helper.rb
104
110
  has_rdoc: true