Class: Tavola::Demonstration

Inherits:
Object
  • Object
show all
Defined in:
lib/tavola/demonstrations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, path) ⇒ Demonstration

Returns a new instance of Demonstration.



32
33
34
35
# File 'lib/tavola/demonstrations.rb', line 32

def initialize config, path
  @config = config
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



30
31
32
# File 'lib/tavola/demonstrations.rb', line 30

def path
  @path
end

Instance Method Details

#qed_augment(path) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/tavola/demonstrations.rb', line 68

def qed_augment path
  # Mostly a copy from Session#run in QED.
  settings = ::QED::Settings.new()
  session  = ::QED::Session.new(settings)

  io = StringIO.new
  reporter = QED::Reporter.new(io: io)
  
  session.prepare_loadpath
  session.require_libraries

  demo = ::QED::Demo.new(path, at: root)
  demo.steps

  ::QED::Evaluator.run(demo, observers: [reporter], settings: settings)

  io.string
end

#relative_pathObject



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

def relative_path
  remove_root(path)
end

#renderObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/tavola/demonstrations.rb', line 46

def render
  r, w = IO.pipe

  pid = fork do
    result = qed_augment(path)

    w.write [result.size].pack('L') # 32 bit native endian
    w.write result

    w.close
  end
  pid, status = Process.wait2(pid)

  size = r.read(4).unpack('L').first

  result = r.read(size)

  r.close

  return result
end

#rootObject



37
38
39
# File 'lib/tavola/demonstrations.rb', line 37

def root
  root = @config.base_dir
end