Class: Live::Session

Inherits:
Object show all
Includes:
HighLine::SystemExtensions
Defined in:
lib/live.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = "#{Dir.tmpdir}/live-rb") ⇒ Session

Starts a live session using a named pipe to receive code from a remote source and evaluates it within a context, a bit like an IRB session but evaluates code sent from a text editor

Raises:

  • (Exception)

45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/live.rb', line 45

def initialize path = "#{Dir.tmpdir}/live-rb" 
  raise Exception.new("Another session sems to be running: #{path}") if File.exist? path
  puts Notice.new("Live Session: #{path}")

  %x{mkfifo #{path}}
  @pipe, @path, @key_bindings = File.open(path, 'r+'), path, {}

  begin
    new_context and key_listen and run!
  ensure
    File.delete(path) if File.exists? path
  end
end

Instance Attribute Details

#key_bindingsObject (readonly)

Returns the value of attribute key_bindings


42
43
44
# File 'lib/live.rb', line 42

def key_bindings
  @key_bindings
end

#pathObject (readonly)

Returns the value of attribute path


42
43
44
# File 'lib/live.rb', line 42

def path
  @path
end

Instance Method Details

#new_contextObject


70
71
72
# File 'lib/live.rb', line 70

def new_context
  @context = Context.new(self)
end

#puts(obj) ⇒ Object


63
64
65
66
67
68
# File 'lib/live.rb', line 63

def puts obj
  super obj.colored_inspect
  # Hackish solution for cursor position
  super "\e[200D"
  super "\e[2A"
end

#quit!Object


59
60
61
# File 'lib/live.rb', line 59

def quit!
  File.delete(@path) && exit
end