Class: ExaTemplate
- Inherits:
-
Object
- Object
- ExaTemplate
- Defined in:
- lib/exa-template.rb
Instance Method Summary collapse
-
#initialize(template, destination, route_refresh = 5) ⇒ ExaTemplate
constructor
A new instance of ExaTemplate.
- #parse_events ⇒ Object
Constructor Details
#initialize(template, destination, route_refresh = 5) ⇒ ExaTemplate
Returns a new instance of ExaTemplate.
5 6 7 8 9 10 11 |
# File 'lib/exa-template.rb', line 5 def initialize(template, destination, route_refresh = 5) @template = template @destination = destination @bindings = binding @services = reset_services @route_refresh = route_refresh end |
Instance Method Details
#parse_events ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/exa-template.rb', line 13 def parse_events loop do chunks = [] begin loop do chunks << STDIN.read_nonblock(4096) end rescue IO::WaitReadable retry if IO.select([STDIN], [], [], @route_refresh) chunks.join.chomp.split("\n").each do |line| event = JSON.parse(line) next unless event['type'] == 'update' parse_services(event) @bindings.local_variable_set(:services, @services) render_template end route_refresh end end end |