Sha256: f07d8d5cc1d10c2c1b8aab0e5235ae35148bacfae9eb285c0f60a8de78a2d21f

Contents?: true

Size: 1.98 KB

Versions: 8

Compression:

Stored size: 1.98 KB

Contents

require 'pry'

class Pry
  class REPL
    # To make the console more useful, we make it so we flush the event registry
    # after each line.  This makes it so events are triggered after each line.
    # To accomplish this we monkey-patch pry.
    def repl
      loop do
        case val = read
        when :control_c
          output.puts ''
          pry.reset_eval_string
        when :no_more_input
          output.puts '' if output.tty?
          break
        else
          output.puts '' if val.nil? && output.tty?
          return pry.exit_value unless pry.eval(val)
        end

        # Flush after each line
        Volt::Computation.flush!
        Volt::Timers.flush_next_tick_timers!
      end
    end
  end

  # The following causes promises in the console to auto-resolve, making it
  # easier to see your data, but harder to follow along.  Currently off by
  # default.
  if ENV['AUTO_RESOLVE']
    def evaluate_ruby(code)
      inject_sticky_locals!
      exec_hook :before_eval, code, self

      result = current_binding.eval(code, Pry.eval_path, Pry.current_line)

      if result.is_a?(Promise)
        result = result.sync
      end

      set_last_result(result, code)
    ensure
      update_input_history(code)
      exec_hook :after_eval, result, self
    end
  end
end

module Volt
  class Console
    module Helpers
      def store
        @volt_app.page.store
      end

      def page
        @volt_app.page.page
      end
    end

    def self.start
      require 'pry'

      $LOAD_PATH << 'lib'
      ENV['SERVER'] = 'true'

      require 'volt'
      require 'volt/boot'
      require 'volt/volt/core'
      require 'volt/server/socket_connection_handler_stub'

      # Boot the volt app
      volt_app = Volt.boot(Dir.pwd)

      SocketConnectionHandlerStub.dispatcher = Dispatcher.new(volt_app)

      Pry.config.prompt_name = 'volt'

      Pry.main.instance_variable_set('@volt_app', volt_app)
      Pry.main.send(:include, Volt::Console::Helpers)

      Pry.start
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
volt-0.9.4.pre3 lib/volt/cli/console.rb
volt-0.9.4.pre2 lib/volt/cli/console.rb
volt-0.9.4.pre1 lib/volt/cli/console.rb
volt-0.9.3 lib/volt/cli/console.rb
volt-0.9.3.pre6 lib/volt/cli/console.rb
volt-0.9.3.pre5 lib/volt/cli/console.rb
volt-0.9.3.pre4 lib/volt/cli/console.rb
volt-0.9.3.pre3 lib/volt/cli/console.rb