Module: Staticme

Extended by:
Staticme, Arguments
Includes:
Events::Dispatcher
Included in:
Staticme
Defined in:
lib/staticme.rb,
lib/staticme/app.rb,
lib/staticme/runner.rb,
lib/staticme/scripts.rb,
lib/staticme/arguments.rb,
lib/staticme/web_socket.rb,
lib/staticme/thin_runner.rb,
lib/staticme/events/dispatcher.rb,
lib/staticme/scripts/autoreload.rb,
lib/staticme/events/emitters/file_changed.rb

Defined Under Namespace

Modules: Arguments, Events, Scripts Classes: App, Runner, ThinRunner, WebSocket

Constant Summary

Constants included from Arguments

Arguments::ARGS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Arguments

parse_input

Methods included from Events::Dispatcher

included

Instance Attribute Details

#appObject

Returns the value of attribute app.



22
23
24
# File 'lib/staticme.rb', line 22

def app
  @app
end

#loggerObject

Returns the value of attribute logger.



22
23
24
# File 'lib/staticme.rb', line 22

def logger
  @logger
end

#paramsObject

Returns the value of attribute params.



22
23
24
# File 'lib/staticme.rb', line 22

def params
  @params
end

#runnerObject

Returns the value of attribute runner.



22
23
24
# File 'lib/staticme.rb', line 22

def runner
  @runner
end

#wsObject

Returns the value of attribute ws.



22
23
24
# File 'lib/staticme.rb', line 22

def ws
  @ws
end

Instance Method Details

#broadcast(data) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/staticme.rb', line 49

def broadcast(data)
  begin
    ws.emit(data)
  rescue
    logger.warn('Unable to broadcast event')
  end
end

#run!(argv, &blk) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/staticme.rb', line 28

def run!(argv, &blk)

  self.params = parse_input(argv)
  self.app = Staticme::App.new(params).bind
  self.logger = ::Logger.new(STDOUT)
  self.logger.level = ::Logger::DEBUG
  self.runner = Staticme::ThinRunner.new
  self.ws = Staticme::WebSocket.new(params)

  register_event_handlers

  emit(:staticme_inited)

  runner.start(app, params) do |server|
    emit(:web_server_started, server)
    logger.debug('Web server started')
    ws.run!
    blk.call(server) if !blk.nil?
  end
end

#stop!Object



57
58
59
60
# File 'lib/staticme.rb', line 57

def stop!
  self.emit(:staticme_terminated)
  runner.stop
end