Module: Monkey

Defined in:
lib/monkey.rb,
lib/monkey/ext.rb,
lib/monkey/engine.rb,
lib/monkey/backend.rb,
lib/monkey/matcher.rb,
lib/monkey/version.rb,
lib/monkey/ext/file.rb,
lib/monkey/ext/array.rb,
lib/monkey/autoloader.rb,
lib/monkey/ext/module.rb,
lib/monkey/ext/object.rb,
lib/monkey/ext/string.rb,
lib/monkey/ext/symbol.rb,
lib/monkey/ext/pathname.rb,
lib/monkey/ext/enumerable.rb,
lib/monkey/backend/common/tap.rb,
lib/monkey/backend/common/parent.rb,
lib/monkey/backend/common/extract_options.rb,
lib/monkey/backend/common/singleton_class.rb

Defined Under Namespace

Modules: Autoloader, Backend, Engine, Ext, Version Classes: Matcher

Class Method Summary collapse

Class Method Details

.backendObject


7
8
9
# File 'lib/monkey.rb', line 7

def self.backend
  Backend.backend
end

.backend=(backend) ⇒ Object


2
3
4
5
# File 'lib/monkey.rb', line 2

def self.backend=(backend)
  Backend.setup! backend
  backend
end

.delete_from_backtrace(error, &block) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
# File 'lib/monkey.rb', line 40

def self.delete_from_backtrace(error, &block)
  if error.respond_to? :awesome_backtrace
    # HACK: we rely on the internal data structure, btw
    locations = error.instance_variable_get :@locations
    return unless locations
    locations.reject! { |l| yield l.position }
    error.instance_variable_set :@backtrace, nil
  else
    error.backtrace.reject!(&block)
  end
end

.hide_invisibles!(&block) ⇒ Object


36
37
38
# File 'lib/monkey.rb', line 36

def self.hide_invisibles!(&block)
  show_invisibles!(false, &block)
end

.invisible(*from) ⇒ Object


11
12
13
14
15
16
17
18
19
20
# File 'lib/monkey.rb', line 11

def self.invisible(*from)
  yield
rescue Exception => error
  unless show_invisibles?
    from << caller.first[/^[^:]*/] if from.empty?
    from << __FILE__
    delete_from_backtrace(error) { |l| from.any? { |f| l.include? f } }
  end
  raise error
end

.show_invisibles!(show = true) ⇒ Object


26
27
28
29
30
31
32
33
34
# File 'lib/monkey.rb', line 26

def self.show_invisibles!(show = true)
  return @show_invisibles = show unless block_given?
  # actually, that is not thread-safe. but that's no issue, as
  # it is quite unlikely and does not cause any harm.
  show_invisibles_was, @show_invisibles = @show_invisibles, show
  result = yield
  @show_invisibles = show_invisibles_was
  result
end

.show_invisibles?Boolean

Returns:

  • (Boolean)

22
23
24
# File 'lib/monkey.rb', line 22

def self.show_invisibles?
  !!@show_invisibles
end