Class: Silhouette::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/silhouette/setup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptions

Returns a new instance of Options.



5
6
7
8
9
10
11
12
13
# File 'lib/silhouette/setup.rb', line 5

def initialize
  @compress = true
  @follow_lines = false
  @file = "silhouette.out"
  @coverage = false
  @all = false
  @describe = false
  @location = false
end

Instance Attribute Details

#allObject

Returns the value of attribute all.



16
17
18
# File 'lib/silhouette/setup.rb', line 16

def all
  @all
end

#compressObject

Returns the value of attribute compress.



15
16
17
# File 'lib/silhouette/setup.rb', line 15

def compress
  @compress
end

#coverageObject

Returns the value of attribute coverage.



15
16
17
# File 'lib/silhouette/setup.rb', line 15

def coverage
  @coverage
end

#describeObject

Returns the value of attribute describe.



16
17
18
# File 'lib/silhouette/setup.rb', line 16

def describe
  @describe
end

#fileObject

Returns the value of attribute file.



15
16
17
# File 'lib/silhouette/setup.rb', line 15

def file
  @file
end

#follow_linesObject

Returns the value of attribute follow_lines.



15
16
17
# File 'lib/silhouette/setup.rb', line 15

def follow_lines
  @follow_lines
end

#locationObject

Returns the value of attribute location.



16
17
18
# File 'lib/silhouette/setup.rb', line 16

def location
  @location
end

Instance Method Details

#detect_compressor(file) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/silhouette/setup.rb', line 18

def detect_compressor(file)
  `which bzip2`
  if $?.exitstatus == 0
    file.replace "#{file}.bz2"
    return "bzip2 -c > #{file}"
  end
  
  `which gzip`
  if $?.exitstatus == 0
    file.replace "#{file}.gz"
    return "gzip -c > #{file}"
  end
  return nil
end

#import_envObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/silhouette/setup.rb', line 33

def import_env
  if ENV["SILHOUETTE_FILE"]
    @file = ENV["SILHOUETTE_FILE"]
  end
  
  if ENV["NO_COMPRESS"]
    @compress = false
  end
  
  if ENV["FOLLOW_LINES"]
    @follow_lines = true
  end
  
  if ENV["COVERAGE"]
    @coverage = true
  end
  
  if ENV["ALL"]
    @all = true
  end
end

#setup_argsObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/silhouette/setup.rb', line 55

def setup_args
  args = []

  gzip = nil
  
  output = @file
  
  unless IO === @file
    if @compress
      compress = detect_compressor(file)
      if compress
        gzip = IO.popen(compress, "w")
        output = gzip
      else
        # Couldn't auto detect a compressor.
      end
    end
  end
  
  args << output

  if @follow_lines
    args << true
  end

  if @coverage
    if @describe
      STDERR.puts "Generating coverage information only."
    end
    args << Silhouette::COVERAGE
  end

  if @all
    args << Silhouette::ALL
  end
  
  unless @location
    @location = @file
  end

  at_exit {
    Silhouette.stop_profile
    STDERR.puts "Flushed profile information to #{@location}"
  }
  
  return [args, @location]
end