Class: Crabfarm::Live::Manager

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/crabfarm/live/manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManager

Returns a new instance of Manager.



15
16
17
# File 'lib/crabfarm/live/manager.rb', line 15

def initialize
  reserve_port
end

Instance Attribute Details

#browser_adapterObject (readonly)

Returns the value of attribute browser_adapter.



11
12
13
# File 'lib/crabfarm/live/manager.rb', line 11

def browser_adapter
  @browser_adapter
end

#primary_driverObject (readonly)

Returns the value of attribute primary_driver.



11
12
13
# File 'lib/crabfarm/live/manager.rb', line 11

def primary_driver
  @primary_driver
end

#proxy_portObject (readonly)

Returns the value of attribute proxy_port.



11
12
13
# File 'lib/crabfarm/live/manager.rb', line 11

def proxy_port
  @proxy_port
end

Instance Method Details

#block_requestsObject



37
38
39
40
41
42
43
44
# File 'lib/crabfarm/live/manager.rb', line 37

def block_requests
  begin
    stop_crabtrap
    return yield
  ensure
    restart_crabtrap nil
  end
end

#resetObject



32
33
34
35
# File 'lib/crabfarm/live/manager.rb', line 32

def reset
  reset_primary_driver
  @viewer.reset
end

#restart_crabtrap(_memento = nil) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/crabfarm/live/manager.rb', line 60

def restart_crabtrap(_memento=nil)
  options = if _memento
    path = Utils::Resolve.memento_path _memento
    raise ConfigurationError.new "No memento found at #{path}" unless File.exists? path
    { mode: :replay, bucket_path: path }
  else
    { mode: :pass }
  end

  stop_crabtrap
  start_crabtrap options
end

#show_content(_content) ⇒ Object



50
51
52
# File 'lib/crabfarm/live/manager.rb', line 50

def show_content(_content)
  block_requests { @viewer.show_content(_content) }
end

#show_file(_path) ⇒ Object



46
47
48
# File 'lib/crabfarm/live/manager.rb', line 46

def show_file(_path)
  block_requests { @viewer.show_file(_path) }
end

#show_primary_contentsObject



54
55
56
57
58
# File 'lib/crabfarm/live/manager.rb', line 54

def show_primary_contents
  unless @viewer_driver.nil?
    @viewer.show_content(primary_driver.to_html)
  end
end

#startObject



19
20
21
22
23
24
# File 'lib/crabfarm/live/manager.rb', line 19

def start
  restart_crabtrap
  load_browser_adapter
  load_primary_driver_and_viewer
  @viewer.welcome
end

#stopObject



26
27
28
29
30
# File 'lib/crabfarm/live/manager.rb', line 26

def stop
  release_primary_driver
  release_viewer_driver
  stop_crabtrap
end