Sha256: bdeaa9c6adeecdb46675a4f8f3594236ae2d3089df3efff5e68dead79107f5b8

Contents?: true

Size: 1.48 KB

Versions: 30

Compression:

Stored size: 1.48 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                      #=> identical to reload-code self
    BANNER

    def process
      code_object = Pry::CodeObject.lookup(obj_name, _pry_)

      check_for_reloadability(code_object)
      reload_code_object(code_object)
    end

    private

    def reload_code_object(code_object)
      load code_object.source_file
      output.puts "#{obj_name} was reloaded!"
    end

    def obj_name
      @obj_name ||= args.empty? ? "self" : args.join(" ")
    end

    def check_for_reloadability(code_object)
      if !code_object || !code_object.source_file
        raise CommandError, "Cannot locate #{obj_name}!"
      elsif !File.exists?(code_object.source_file)
        raise CommandError, "Cannot reload #{obj_name} 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

30 entries across 30 versions & 3 rubygems

Version Path
torquebox-console-0.3.0 vendor/bundle/jruby/1.9/gems/pry-0.9.12-java/lib/pry/commands/reload_code.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/pry-0.9.12.1/lib/pry/commands/reload_code.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/pry-0.9.12.1/lib/pry/commands/reload_code.rb
pry-0.9.12.1 lib/pry/commands/reload_code.rb
pry-0.9.12.1-i386-mswin32 lib/pry/commands/reload_code.rb
pry-0.9.12.1-i386-mingw32 lib/pry/commands/reload_code.rb
pry-0.9.12.1-java lib/pry/commands/reload_code.rb
pry-0.9.12.1pre1 lib/pry/commands/reload_code.rb
pry-0.9.12.1pre1-i386-mswin32 lib/pry/commands/reload_code.rb
pry-0.9.12.1pre1-i386-mingw32 lib/pry/commands/reload_code.rb
pry-0.9.12.1pre1-java lib/pry/commands/reload_code.rb
torquebox-console-0.2.5 vendor/bundle/jruby/1.9/gems/pry-0.9.12-java/lib/pry/commands/reload_code.rb
torquebox-console-0.2.4 vendor/bundle/jruby/1.9/gems/pry-0.9.12-java/lib/pry/commands/reload_code.rb
torquebox-console-0.2.3 vendor/bundle/jruby/1.9/gems/pry-0.9.12-java/lib/pry/commands/reload_code.rb
pry-0.9.12 lib/pry/commands/reload_code.rb
pry-0.9.12-i386-mswin32 lib/pry/commands/reload_code.rb
pry-0.9.12-i386-mingw32 lib/pry/commands/reload_code.rb
pry-0.9.12-java lib/pry/commands/reload_code.rb
pry-0.9.12pre3 lib/pry/commands/reload_code.rb
pry-0.9.12pre3-i386-mswin32 lib/pry/commands/reload_code.rb