Sha256: 6e54a4568213c410ec6c03680253e2fc4154e4587734bf7a590930ed81e77a1b

Contents?: true

Size: 1.91 KB

Versions: 135

Compression:

Stored size: 1.91 KB

Contents

class Pry
  class Command::ReloadCode < Pry::ClassCommand
    match 'reload-code'
    group 'Misc'
    description 'Reload the source file that contains the specified code object.'

    banner <<-'BANNER'
      Reload the source file that contains the specified code object.

      e.g reload-code MyClass#my_method    #=> reload a method
          reload-code MyClass              #=> reload a class
          reload-code my-command           #=> reload a pry command
          reload-code self                 #=> reload the current object
          reload-code                      #=> reload the current file or object
    BANNER

    def process
      if !args.empty?
        reload_object(args.join(" "))
      elsif internal_binding?(target)
        reload_object("self")
      else
        reload_current_file
      end
    end

    private

    def current_file
      File.expand_path target.eval("__FILE__")
    end

    def reload_current_file
      if !File.exists?(current_file)
        raise CommandError, "Current file: #{current_file} cannot be found on disk!"
      end

      load current_file
      output.puts "The current file: #{current_file} was reloaded!"
    end

    def reload_object(identifier)
      code_object = Pry::CodeObject.lookup(identifier, _pry_)
      check_for_reloadability(code_object, identifier)
      load code_object.source_file
      output.puts "#{identifier} was reloaded!"
    end

    def check_for_reloadability(code_object, identifier)
      if !code_object || !code_object.source_file
        raise CommandError, "Cannot locate #{identifier}!"
      elsif !File.exists?(code_object.source_file)
        raise CommandError,
          "Cannot reload #{identifier} as it has no associated file on disk. " \
          "File found was: #{code_object.source_file}"
      end
    end
  end

  Pry::Commands.add_command(Pry::Command::ReloadCode)
  Pry::Commands.alias_command 'reload-method', 'reload-code'
end

Version data entries

135 entries across 128 versions & 29 rubygems

Version Path
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/pry-0.10.4-java/lib/pry/commands/reload_code.rb