Module: Critique

Defined in:
lib/critique.rb,
lib/critique/version.rb,
lib/critique/profiling.rb

Defined Under Namespace

Modules: ClassMethods, Profiling

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.disable!Object



16
17
18
19
20
21
22
23
# File 'lib/critique.rb', line 16

def disable!
  module_eval <<-RUBY, __FILE__, __LINE__+1
    def self.profile(*)
      yield
    end
  RUBY
  @_enabled = false
end

.enable!Object



25
26
27
28
29
30
31
32
# File 'lib/critique.rb', line 25

def enable!
  module_eval <<-RUBY, __FILE__, __LINE__+1
    def self.profile(*args, &block)
      Profiling.profile(*(args.insert(1,2)), &block)
    end
  RUBY
  @_enabled = true
end

.enabled?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/critique.rb', line 34

def enabled?
  @_enabled || false
end

.included(base) ⇒ Object



8
9
10
# File 'lib/critique.rb', line 8

def included(base)
  base.extend(ClassMethods)
end

.loggerObject



46
47
48
# File 'lib/critique.rb', line 46

def logger
  @_logger ||= Logger.new($stdout)
end

.logger=(logger) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/critique.rb', line 38

def logger=(logger)
  if logger.is_a?(IO) || logger.is_a?(String)
    @_logger = Logger.new(logger)
  else
    @_logger = logger
  end
end

.profileObject



12
13
14
# File 'lib/critique.rb', line 12

def profile(*)
  yield
end

Instance Method Details

#critique(*args, &block) ⇒ Object



57
58
59
# File 'lib/critique.rb', line 57

def critique(*args, &block)
  Critique.profile(*([self] + args), &block)
end