Module: Quick::Service

Extended by:
Service
Included in:
Service
Defined in:
lib/quick/service.rb

Instance Method Summary collapse

Instance Method Details

#eval(module_path, code, instance = true) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/quick/service.rb', line 63

def eval(module_path, code, instance=true)
  mod = resolve_path module_path
  if instance
    [true, mod.quick_instance.quick_binding.eval(code).inspect]
  else
    [true, mod.quick_binding.eval(code).inspect]
  end
rescue => e
  [false, e.message]
end

#hibernateObject



58
59
60
61
# File 'lib/quick/service.rb', line 58

def hibernate
  @hibernating = true
  stop
end

#mount_pointObject



103
104
105
# File 'lib/quick/service.rb', line 103

def mount_point
  @mount_point
end

#new_mod(parent_path, name, super_path = nil) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/quick/service.rb', line 74

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
  name
end

#priesObject



85
86
87
# File 'lib/quick/service.rb', line 85

def pries
  @pries ||= {}
end

#pry_at(module_path, instance = true) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/quick/service.rb', line 89

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



107
108
109
110
111
# File 'lib/quick/service.rb', line 107

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

#stopObject



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