Module: WTF

Defined in:
lib/wtf-tools.rb,
lib/wtf/dumper.rb,
lib/wtf/query_tracker.rb,
lib/wtf/method_tracker.rb

Defined Under Namespace

Modules: MethodTracker, QueryTracker Classes: Dumper

Class Method Summary collapse

Class Method Details

.files_pathObject



15
16
17
18
19
20
21
22
# File 'lib/wtf-tools.rb', line 15

def files_path
  if options[:files]
    dirs = FileUtils.mkdir_p(options[:files])
    dirs.first
  else
    Dir.getwd
  end
end

.optionsObject



11
12
13
# File 'lib/wtf-tools.rb', line 11

def options
  @options ||= {}
end

.options=(value) ⇒ Object



7
8
9
# File 'lib/wtf-tools.rb', line 7

def options=(value)
  @options = value
end

.output_optionsObject



24
25
26
# File 'lib/wtf-tools.rb', line 24

def output_options
  Hash(options[:output])
end

.sql(*args) ⇒ Object



41
42
43
# File 'lib/wtf-tools.rb', line 41

def sql(*args)
  WTF::QueryTracker.start_tracking(*args)
end

.time(*args) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/wtf-tools.rb', line 45

def time(*args)
  require 'absolute_time'

  precision = args.shift if args.first.is_a?(Fixnum)
  precision ||= 3
  before = AbsoluteTime.now
  result = yield
  duration = AbsoluteTime.now - before
  WTF::Dumper.new(duration.round(precision), *args).call
  result
end

.track(*objects) ⇒ Object

TODO: separately track ActiveRecord finders usage in the related methods



29
30
31
32
33
34
35
# File 'lib/wtf-tools.rb', line 29

def track(*objects)
  WTF::MethodTracker.start_tracking(*objects)
  if block_given?
    yield
    track_finish
  end
end

.track_finishObject



37
38
39
# File 'lib/wtf-tools.rb', line 37

def track_finish
  WTF::MethodTracker.finish
end