Module: Quick::Service
- Defined in:
- lib/quick/service.rb
Class Method Summary collapse
- .eval(module_path, code, instance = true) ⇒ Object
- .hibernate ⇒ Object
- .mount_point ⇒ Object
- .new_mod(parent_path, name, super_path = nil) ⇒ Object
- .pries ⇒ Object
- .pry_at(module_path, instance = true) ⇒ Object
- .resolve_path(path) ⇒ Object
-
.run(mount_point) ⇒ Object
warning: run/stop/hibernate are pretty awful because I don’t actually know how to use EventMachine properly.
- .stop ⇒ Object
Class Method Details
.eval(module_path, code, instance = true) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/quick/service.rb', line 63 def eval(module_path, code, instance=true) mod = resolve_path module_path if instance mod.quick_instance.quick_binding.eval code else mod.quick_binding.eval code end end |
.hibernate ⇒ Object
58 59 60 61 |
# File 'lib/quick/service.rb', line 58 def hibernate @hibernating = true stop end |
.mount_point ⇒ Object
100 101 102 |
# File 'lib/quick/service.rb', line 100 def mount_point @mount_point end |
.new_mod(parent_path, name, super_path = nil) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/quick/service.rb', line 72 def new_mod(parent_path, name, super_path=nil) parent = resolve_path parent_path unless super_path parent.const_set name, Module.new else superclass = resolve_path super_path parent.const_set name, Class.new(superclass) end end |
.pries ⇒ Object
82 83 84 |
# File 'lib/quick/service.rb', line 82 def pries @pries ||= {} end |
.pry_at(module_path, instance = true) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/quick/service.rb', line 86 def pry_at(module_path, instance=true) mod = resolve_path module_path target = if instance mod.quick_instance.quick_binding else mod.quick_binding end if pries.key? target pries[target] else pries[target] = target.remote_pry_em 'localhost', :auto end end |
.resolve_path(path) ⇒ Object
104 105 106 107 108 |
# File 'lib/quick/service.rb', line 104 def resolve_path(path) path = path.sub /\A(\/|\.|\.\.)/, '' parts = path.split '/' parts.inject(Object) {|mod, name| mod.const_get name} end |
.run(mount_point) ⇒ Object
warning: run/stop/hibernate are pretty awful because I don’t actually know how to use EventMachine properly. If you know how to make these better, PLEASE feel free to submit a pull request!
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/quick/service.rb', line 26 def run(mount_point) loop do raise "already running" if @running @mount_point = File.absolute_path mount_point @root = FS::ModuleDir.new Object Thread.new do FuseFS.start @root, @mount_point end EM.run do BrB::Service.start_service object: self @running = true end if @hibernating sleep 10 @hibernating = false else break end end ensure FuseFS.unmount end |
.stop ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/quick/service.rb', line 49 def stop raise "not running" unless @running @running = false FuseFS.unmount FuseFS.exit BrB::Service.stop_service EM.stop end |