Sha256: b79df1d55579bccea3f24092006f6e0ecc54746de8d6921809d5c1d193c4f787
Contents?: true
Size: 1.32 KB
Versions: 1
Compression:
Stored size: 1.32 KB
Contents
#!/usr/bin/env ruby # frozen_string_literal: true require 'listen' require_relative '../lib/living_document.rb' # rubocop:disable Style/TopLevelMethodDefinition def evaluate_code_and_update_source_file(file_path) puts('Running code...') code_in_file = File.read(file_path) code_to_write = LivingDocument::DocumentEvaluator.new( document: code_in_file, ).evaluated_document $printed_objects_last_run = [] puts("Writing file! #{Time.now}") File.write(file_path, code_to_write) end # rubocop:enable Style/TopLevelMethodDefinition file_path = ARGV[0] if file_path.nil? puts('You must provide a file path argument, e.g. `livdoc personal/ruby.rb`.') exit(1) end last_file_update = Time.now listener = Listen.to(Dir.pwd, only: /\A#{Regexp.escape(file_path)}\z/) do |_modified, _added, _removed| # Don't enter infinitely recursive loop, since the code below triggers file updates. # After file has been updated, wait at least 0.5 seconds before listener processes again. next if (Time.now - last_file_update) < 0.5 evaluate_code_and_update_source_file(file_path) last_file_update = Time.now end listener.start system('clear') evaluate_code_and_update_source_file(file_path) puts('Waiting for file changes...') at_exit do print('Stopping listener ... ') listener.stop puts('done.') end sleep
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
living_document-1.0.0 | exe/livdoc |