Class: HookAction

Inherits:
Object
  • Object
show all
Defined in:
lib/pry-state/hook_action.rb

Constant Summary collapse

IGNORABLE_LOCAL_VARS =
[:__, :_, :_ex_, :_pry_, :_out_, :_in_, :_dir_, :_file_]
CONTROLLER_INSTANCE_VARIABLES =
[:@_request, :@_response, :@_routes]
RSPEC_INSTANCE_VARIABLES =
[:@__inspect_output, :@__memoized]
IGNORABLE_INSTANCE_VARS =
CONTROLLER_INSTANCE_VARIABLES + RSPEC_INSTANCE_VARIABLES
IGNORABLE_GLOBAL_VARS =
[:$@]

Instance Method Summary collapse

Constructor Details

#initialize(binding, pry) ⇒ HookAction

Returns a new instance of HookAction.



11
12
13
# File 'lib/pry-state/hook_action.rb', line 11

def initialize binding, pry
  @binding, @pry = binding, pry
end

Instance Method Details

#actObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pry-state/hook_action.rb', line 15

def act
  # when using guard, locals :e, :lib, :pry_state_prev get printed.
  # this 'if' cuts them off.
  if @binding.eval("self.class") == Object
    return
  end

  if ENV['SHOW_GLOBAL_VARIABLES']
    (binding.eval('global_variables').sort - IGNORABLE_GLOBAL_VARS).each do |var|
      eval_and_print var, var_color: 'white', value_colore: 'yellow'
    end
  end

  unless ENV['HIDE_INSTANCE_VARIABLES']
    (binding.eval('instance_variables').sort - IGNORABLE_INSTANCE_VARS).each do |var|
      eval_and_print var, var_color: 'green'
    end
  end

  unless ENV['HIDE_LOCAL_VARIABLES']
    (binding.eval('local_variables').sort - IGNORABLE_LOCAL_VARS).each do |var|
      eval_and_print var, var_color: 'cyan'
    end
  end
end