Sha256: 4163510c13845091a4c65745a988fb0aa528c3037b9eb805830d8ca20ec8df11

Contents?: true

Size: 1.4 KB

Versions: 19

Compression:

Stored size: 1.4 KB

Contents

require_relative "show_source_with_c_internals/code_fetcher"

module Pry::CInternals
  class ShowSourceWithCInternals < Pry::Command::ShowSource
    def options(opt)
      super(opt)
      opt.on :c, "c-source", "Show source of a C identifier in MRI (rather than Ruby method of same name)"
    end

    def show_c_source
      if opts.present?(:all)
        result, file = CodeFetcher.new(line_number_style: line_number_style)
                         .fetch_all_definitions(obj_name)
      else
        result, file = CodeFetcher.new(line_number_style: line_number_style)
                         .fetch_first_definition(obj_name)
      end
      if result
        set_file_and_dir_locals(file)
        _pry_.pager.page result
      else
        raise Pry::CommandError, no_definition_message
      end
    end

    def process
      if opts.present?(:c) && !_pry_.config.skip_cruby_source
        show_c_source
        return
      else
        super
      end
    rescue Pry::CommandError
      raise if _pry_.config.skip_cruby_source
      show_c_source
    end

    private

    # We can number lines with their actual line numbers
    # or starting with 1 (base-one)
    def line_number_style
      if opts.present?(:'base-one')
        :'base-one'
      elsif opts.present?(:'line-numbers')
        :'line-numbers'
      else
        nil
      end
    end

    Pry::Commands.add_command(ShowSourceWithCInternals)
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
pry-doc-1.1.0 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-1.0.0 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-0.13.5 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-0.13.4 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-0.13.3 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-0.13.2 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-0.13.2pre7 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-0.13.2pre6 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-0.13.2pre5 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-0.13.2pre4 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-0.13.2pre3 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-0.13.2pre2 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-0.13.2pre1 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-0.13.1 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-0.13.0 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-0.13.0pre14 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-0.13.0pre13 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-0.13.0pre12 lib/pry-doc/pry_ext/show_source_with_c_internals.rb
pry-doc-0.13.0pre11 lib/pry-doc/pry_ext/show_source_with_c_internals.rb