Module: MindControl

Defined in:
lib/mind_control.rb,
lib/mind_control/cui.rb,
lib/mind_control/repl.rb,
lib/mind_control/client.rb,
lib/mind_control/server.rb,
lib/mind_control/version.rb,
lib/mind_control/loggable.rb,
lib/mind_control/pry_commands.rb

Defined Under Namespace

Modules: Client, Loggable Classes: CUI, REPL, Server

Constant Summary collapse

DEFAULT_SOCKETS_DIR =

Default directory for UNIX socket files.

"/tmp/ruby_mind_control"
VERSION =
"0.4.0"
PryCommands =
::Pry::CommandSet.new

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject

Returns the value of attribute logger.



12
13
14
# File 'lib/mind_control.rb', line 12

def logger
  @logger
end

Class Method Details

.start(options = {}) ⇒ Object

Start MindControl server.

Parameters:

  • options (Hash) (defaults to: {})

    @option options [Object] :target (TOPLEVEL_BINDING)

    REPL target context.
    

    @option option [Hash] :pry ({})

    Options for Pry instance.
    

    @option options [String] :name ($PROGRAM_NAME)

    Program name.
    

    @option options [String] :sockets_dir (DEFAULT_SOCKETS_DIR)

    Directory where control socket will be created.
    


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/mind_control.rb', line 30

def self.start( options = {} )
  raise "MindControl already started!" if @server && @server.running?

  # Name that will be displayed in process list of mind-control client.
  # The default is process name of the host program (eg. "ruby").
  process_name = options[ :name ] || $PROGRAM_NAME

  # Make name filesystem safe
  # NB: we can't use gsub! because $PROGRAM_NAME is frozen
  process_name = process_name.gsub( /[^[[:alnum:]]\-_]/, "_" )

  # Some shared temp directory for sockets.
  socket_dir = options[ :sockets_dir ] || DEFAULT_SOCKETS_DIR

  # Construct unique socket path for current process
  socket_name = "#{process_name}.#{Process.pid}.sock"
  socket_path = File.join( socket_dir, socket_name )

  # Construct REPL (NB: same settings for all connections!)
  repl = MindControl::REPL.new( options[ :target ] || TOPLEVEL_BINDING, options[ :pry ] || {} )

  # Start server
  @server = MindControl::Server.new( socket_path, repl )
  @server.start

  return nil
end

.stopObject

Stop MindControl server.



61
62
63
64
65
66
# File 'lib/mind_control.rb', line 61

def self.stop
  return unless @server

  @server.stop
  @server = nil
end