quick 0.1 → 0.2

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.
Files changed (4) hide show
  1. data/bin/quick +33 -28
  2. data/lib/quick/service.rb +6 -3
  3. data/lib/quick.rb +59 -0
  4. metadata +2 -2
data/bin/quick CHANGED
@@ -2,25 +2,11 @@
2
2
  require 'thor'
3
3
  require 'brb'
4
4
  require 'pathname'
5
- require 'pry-remote-em/client'
6
5
  require 'uri'
7
6
  require_relative '../lib/quick'
8
7
 
9
- def brb_service
10
- uri = File.read('#brb_uri')
11
- service = BrB::Tunnel.create nil, uri
12
- if service.error?
13
- puts "failed to connect to the Quick instance"
14
- exit 2
15
- end
16
- service
17
- rescue Errno::ENOENT
18
- puts "not in a Quick directory"
19
- exit 1
20
- end
21
-
22
8
  class QuickCLI < Thor
23
- desc "start MOUNT_DIR", "run Quick, mounting the FS on MOUNT_DIR"
9
+ desc 'start MOUNT_DIR', "run Quick, mounting the FS on MOUNT_DIR"
24
10
  option :foreground, type: :boolean, aliases: :f
25
11
  def start(dir)
26
12
  if File.file? dir or
@@ -39,32 +25,51 @@ class QuickCLI < Thor
39
25
  exit
40
26
  end
41
27
  end
42
- Quick::Service.run dir
28
+ Quick.run dir
43
29
  Dir.rmdir dir unless existed
44
30
  end
45
31
 
46
- desc "stop", "stop the Quick instance that owns your CWD"
32
+ desc 'stop', "stop your current Quick instance"
47
33
  def stop
48
- brb_service.stop
49
- sleep 0.1
34
+ Quick.stop
50
35
  end
51
36
 
52
- desc "pry", "start a pry in the module corresponding to your CWD"
37
+ desc 'pry', "start a pry in an instance of the current module"
53
38
  option :module, type: :boolean, aliases: :m
54
39
  def pry
55
- service = brb_service
56
- root = Pathname.new service.mount_point_block
57
- path = Pathname.pwd.relative_path_from root
58
- uri = service.pry_at_block(path.to_path, !options.module?)
40
+ uri = Quick.pry_here !options.module?
59
41
  system "pry-remote-em #{uri}"
60
- exit
61
- EM.run do
62
- PryRemoteEm::Client.start(uri.host, uri.port) {|e| EM.stop}
42
+ end
43
+
44
+ desc 'module NAME', "create a new module here"
45
+ def module(name)
46
+ Quick.module_here name
47
+ end
48
+
49
+ map 'class' => :class_
50
+ desc 'class NAME [SUPERCLASS_PATH]', "create a new class here"
51
+ def class_(name, super_path='Object')
52
+ Quick.class_here name, super_path
53
+ end
54
+
55
+ desc 'eval CODE', "evaluate some code in an instance of the current module"
56
+ option :module, type: :boolean, aliases: :m
57
+ def eval(code)
58
+ success, result = Quick.eval_here code, !options.module?
59
+ if success
60
+ puts "=> #{result}"
61
+ else
62
+ puts "error: #{result}"
63
63
  end
64
64
  end
65
65
  end
66
66
 
67
- QuickCLI.start
67
+ begin
68
+ QuickCLI.start
69
+ rescue RuntimeError => e
70
+ puts e.message
71
+ exit 1
72
+ end
68
73
 
69
74
  # vim:tabstop=2 shiftwidth=2 noexpandtab:
70
75
 
data/lib/quick/service.rb CHANGED
@@ -17,7 +17,7 @@ end
17
17
 
18
18
  module Quick
19
19
  module Service
20
- module_function
20
+ extend self
21
21
 
22
22
  # warning: run/stop/hibernate are pretty awful because I
23
23
  # don't actually know how to use EventMachine properly.
@@ -63,10 +63,12 @@ module Quick
63
63
  def eval(module_path, code, instance=true)
64
64
  mod = resolve_path module_path
65
65
  if instance
66
- mod.quick_instance.quick_binding.eval code
66
+ [true, mod.quick_instance.quick_binding.eval(code).inspect]
67
67
  else
68
- mod.quick_binding.eval code
68
+ [true, mod.quick_binding.eval(code).inspect]
69
69
  end
70
+ rescue => e
71
+ [false, e.message]
70
72
  end
71
73
 
72
74
  def new_mod(parent_path, name, super_path=nil)
@@ -77,6 +79,7 @@ module Quick
77
79
  superclass = resolve_path super_path
78
80
  parent.const_set name, Class.new(superclass)
79
81
  end
82
+ name
80
83
  end
81
84
 
82
85
  def pries
data/lib/quick.rb CHANGED
@@ -2,3 +2,62 @@ require_relative 'quick/core_ext'
2
2
  require_relative 'quick/fs'
3
3
  require_relative 'quick/service'
4
4
 
5
+ module Quick
6
+ extend self
7
+
8
+ def brb_service
9
+ @brb_service ||=
10
+ begin
11
+ uri = File.read('#brb_uri')
12
+ service = BrB::Tunnel.create nil, uri
13
+ if service.error?
14
+ raise "failed to connect to the Quick instance"
15
+ end
16
+ service
17
+ end
18
+ rescue Errno::ENOENT
19
+ raise "not in a Quick directory"
20
+ end
21
+
22
+ def run(dir)
23
+ Quick::Service.run dir
24
+ end
25
+
26
+ def stop
27
+ brb_service.stop
28
+ sleep 1
29
+ end
30
+
31
+ def pry_here(instance=true)
32
+ brb_service.pry_at_block pwd_from_root, instance
33
+ end
34
+
35
+ def eval_here(code, instance=true)
36
+ brb_service.eval_block pwd_from_root, code, instance
37
+ end
38
+
39
+ def module_here(name)
40
+ raise "invalid module name" unless ('A'..'Z').include? name[0]
41
+ brb_service.new_mod_block pwd_from_root, name
42
+ end
43
+
44
+ def class_here(name, super_path='Object')
45
+ raise "invalid class name" unless ('A'..'Z').include? name[0]
46
+ p [pwd_from_root, name, from_root(super_path)]
47
+ brb_service.new_mod_block pwd_from_root, name, from_root(super_path)
48
+ end
49
+
50
+ def pwd_from_root
51
+ from_root Dir.pwd
52
+ end
53
+
54
+ def from_root(path)
55
+ pn = Pathname.new path
56
+ return path if pn.relative?
57
+ root = Pathname.new brb_service.mount_point_block
58
+ pn.relative_path_from(root).to_path
59
+ end
60
+ end
61
+
62
+ # vim:tabstop=2 shiftwidth=2 noexpandtab:
63
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quick
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -129,6 +129,6 @@ rubyforge_project:
129
129
  rubygems_version: 1.8.23
130
130
  signing_key:
131
131
  specification_version: 3
132
- summary: A Smalltalk-ish live dev environment for Ruby.
132
+ summary: Code in a living environment!
133
133
  test_files: []
134
134
  has_rdoc: