Class: Pry::Command::Ls::Constants

Inherits:
Formatter show all
Includes:
Interrogatable
Defined in:
lib/pry/commands/ls/constants.rb

Constant Summary collapse

DEPRECATED_CONSTANTS =
[:Fixnum, :Bignum, :TimeoutError, :NIL, :FALSE, :TRUE]

Instance Attribute Summary

Attributes inherited from Formatter

#_pry_, #grep

Instance Method Summary collapse

Methods included from Interrogatable

#interrogatee_mod, #interrogating_a_module?

Methods inherited from Formatter

#color, #format_value, #output_section, #write_out

Constructor Details

#initialize(interrogatee, no_user_opts, opts, _pry_) ⇒ Constants

Returns a new instance of Constants



10
11
12
13
14
15
16
17
# File 'lib/pry/commands/ls/constants.rb', line 10

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

Instance Method Details

#correct_opts?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/pry/commands/ls/constants.rb', line 19

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

#format(mod, constants) ⇒ Object (private)



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/pry/commands/ls/constants.rb', line 35

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

#output_selfObject



23
24
25
26
27
# File 'lib/pry/commands/ls/constants.rb', line 23

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

#show_deprecated_constants?Boolean (private)

Returns:

  • (Boolean)


31
32
33
# File 'lib/pry/commands/ls/constants.rb', line 31

def show_deprecated_constants?
  @dconstants == true
end