Sha256: 9feba488873b718fa5fd0f2357e8baac064a60059b3bc6fe6044190aef7e9b30

Contents?: true

Size: 787 Bytes

Versions: 1

Compression:

Stored size: 787 Bytes

Contents

require "pry"

module Safeconsole
  class PryConfig
    def self.add_hooks
      Pry.hooks.add_hook(:after_read, "safeconsole__transaction_watcher") do |output, binding, pry|
        if defined?(ActiveRecord) && binding.last_exception.is_a?(ActiveRecord::StatementInvalid)
          puts Messages.invalid_query
        end
      end

      Pry.hooks.add_hook(:after_eval, "safeconsole__exit") do |output, binding, _pry|
        if Object.const_defined?(:Safeconsole) && (binding.config.prompt_name == "safeconsole")
          SessionWatcher.command_ran

          binding.eval("exit") if Console.done?

          if output == "safeconsole#refresh"
            SessionWatcher.transaction_commands = 0
            binding.eval("exit")
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
safeconsole-1.0.0 lib/safeconsole/pry_config.rb