Module: Ghaki::Report::Mixin::Basic

Includes:
Logger::Mixin, Stats::Mixin
Defined in:
lib/ghaki/report/mixin/basic.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

:nodoc:



16
17
18
# File 'lib/ghaki/report/mixin/basic.rb', line 16

def self.included klass #:nodoc:
  klass.extend ClassMethods
end

Instance Method Details

#initialize(opts = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ghaki/report/mixin/basic.rb', line 20

def initialize opts={}
  self.report_name = opts[:report_name] unless opts[:report_name].nil?
  @stats = opts[:stats]
  if not opts[:logger].nil?
    @logger = opts[:logger]
  elsif not opts[:log_file_name].nil?
    @logger = Ghaki::Logger::Base.new( :file_name => opts[:log_file_name] )
  elsif not opts[:log_file_handle].nil?
    @logger = Ghaki::Logger::Base.new( :file_handle => opts[:log_file_handle] )
  end
end

#major_report_wrap(title = nil, &block) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/ghaki/report/mixin/basic.rb', line 62

def major_report_wrap title=nil, &block
  logger.major.wrap( report_name(title) ) do
    begin
      block.call
    ensure
      stats.flush self.logger
    end
  end
end

#minor_report_wrap(title = nil, &block) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/ghaki/report/mixin/basic.rb', line 52

def minor_report_wrap title=nil, &block
  logger.minor.wrap( report_name(title) ) do
    begin
      block.call
    ensure
      stats.flush self.logger
    end
  end
end

#report_name(title = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/ghaki/report/mixin/basic.rb', line 42

def report_name title=nil
  if title.nil?
    @report_name || self.class.report_name
  elsif title[0,1] == '.'
    (@report_name || self.class.report_name) + title
  else
    title
  end
end

#report_name=(title) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/ghaki/report/mixin/basic.rb', line 32

def report_name= title
  if title.nil?
    @report_name = self.class.report_name
  elsif title[0,1] == '.'
    @report_name = (@report_name || self.class.report_name) + title
  else
    @report_name = title
  end
end