Sha256: 9de618946be530554833f4644b65f59ebea4f67a183c00ba60350d76b37ce6fe

Contents?: true

Size: 1.75 KB

Versions: 20

Compression:

Stored size: 1.75 KB

Contents

require 'pry/commands/ls/interrogatable'

class Pry
  class Command::Ls < Pry::ClassCommand
    class Constants < Pry::Command::Ls::Formatter
      DEPRECATED_CONSTANTS = [:Fixnum, :Bignum, :TimeoutError, :NIL, :FALSE, :TRUE]
      DEPRECATED_CONSTANTS << :JavaPackageModuleTemplate if Pry::Helpers::BaseHelpers.jruby?
      include Pry::Command::Ls::Interrogatable

      def initialize(interrogatee, no_user_opts, opts, _pry_)
        super(_pry_)
        @interrogatee = interrogatee
        @no_user_opts = no_user_opts
        @default_switch = opts[:constants]
        @verbose_switch = opts[:verbose]
        @dconstants = opts.dconstants?
      end

      def correct_opts?
        super || (@no_user_opts && interrogating_a_module?)
      end

      def output_self
        mod = interrogatee_mod
        constants = WrappedModule.new(mod).constants(@verbose_switch)
        output_section('constants', grep.regexp[format(mod, constants)])
      end

      private

      def show_deprecated_constants?
        @dconstants == true
      end

      def format(mod, constants)
        constants.sort_by(&:downcase).map do |name|
          if Object.respond_to?(:deprecate_constant) and
            DEPRECATED_CONSTANTS.include?(name)      and
            !show_deprecated_constants?
            next
          end
          if const = (!mod.autoload?(name) && (mod.const_get(name) || true) rescue nil)
            if (const < Exception rescue false)
              color(:exception_constant, name)
            elsif (Module === mod.const_get(name) rescue false)
              color(:class_constant, name)
            else
              color(:constant, name)
            end
          else
            color(:unloaded_constant, name)
          end
        end
      end

    end
  end
end

Version data entries

20 entries across 20 versions & 8 rubygems

Version Path
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/pry-0.11.3/lib/pry/commands/ls/constants.rb
xaiml-0.1.3 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/commands/ls/constants.rb
xaiml-0.1.2 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/commands/ls/constants.rb
xaiml-0.1.1 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/commands/ls/constants.rb
xaiml-0.1.0 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/commands/ls/constants.rb
monero_wallet_gen-0.1.0 vendor/bundle/ruby/2.3.0/gems/pry-0.11.3/lib/pry/commands/ls/constants.rb
sb_prime_table-0.1.1 vendor/bundle/ruby/2.4.0/gems/pry-0.11.3/lib/pry/commands/ls/constants.rb
sb_prime_table-0.1.0 vendor/bundle/ruby/2.4.0/gems/pry-0.11.3/lib/pry/commands/ls/constants.rb
comiditaULL-0.1.1 vendor/bundle/ruby/2.3.0/gems/pry-0.11.2/lib/pry/commands/ls/constants.rb
comidita_ull-0.1.1 vendor/bundle/ruby/2.3.0/gems/pry-0.11.2/lib/pry/commands/ls/constants.rb
comidita_ull-0.1.0 vendor/bundle/ruby/2.3.0/gems/pry-0.11.2/lib/pry/commands/ls/constants.rb
pry-0.11.3 lib/pry/commands/ls/constants.rb
pry-0.11.3-java lib/pry/commands/ls/constants.rb
pry-0.11.2 lib/pry/commands/ls/constants.rb
pry-0.11.2-java lib/pry/commands/ls/constants.rb
tdiary-5.0.6 vendor/bundle/gems/pry-0.11.0/lib/pry/commands/ls/constants.rb
pry-0.11.1 lib/pry/commands/ls/constants.rb
pry-0.11.1-java lib/pry/commands/ls/constants.rb
pry-0.11.0 lib/pry/commands/ls/constants.rb
pry-0.11.0-java lib/pry/commands/ls/constants.rb