Class: Mata
- Inherits:
-
Object
- Object
- Mata
- Defined in:
- lib/mata.rb,
lib/mata/agent.rb,
lib/mata/version.rb,
lib/mata/broadcaster.rb,
lib/mata/watch_tower.rb
Defined Under Namespace
Classes: Agent, Broadcaster, WatchTower
Constant Summary collapse
- VERSION =
"0.9.0"
Instance Method Summary collapse
- #call(environment) ⇒ Object
-
#initialize(app, options = {}) ⇒ Mata
constructor
A new instance of Mata.
- #stand_down ⇒ Object
Constructor Details
#initialize(app, options = {}) ⇒ Mata
Returns a new instance of Mata.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mata.rb', line 11 def initialize(app, = {}) @app = app return if ENV["MATA_DISABLED"] == "true" @watch_tower = WatchTower.new() @broadcaster = Broadcaster.new @agent = Agent.new @watch_tower.on_change { |files| @broadcaster.broadcast_to_all(files) } at_exit { stand_down } end |
Instance Method Details
#call(environment) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mata.rb', line 25 def call(environment) request = Rack::Request.new(environment) case request.path when "/__mata/events" @broadcaster.establish_contact(environment) when "/__mata/client.js" @broadcaster.deliver_payload else @agent.insert(*@app.call(environment)) end end |
#stand_down ⇒ Object
38 39 40 41 |
# File 'lib/mata.rb', line 38 def stand_down @watch_tower&.shutdown @broadcaster&.stand_down end |