Module: MetricFu::Environment

Included in:
Configuration
Defined in:
lib/metric_fu/environment.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ruby_strangely_makes_accessors_private?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/metric_fu/environment.rb', line 124

def ruby_strangely_makes_accessors_private?
  @private_accessors ||= ruby192? || jruby?
end

Instance Method Details

#debug_infoObject



112
113
114
115
116
117
118
# File 'lib/metric_fu/environment.rb', line 112

def debug_info
  @debug_info ||= {
    "Ruby" => ruby_details,
    "Environment" => environment_details,
    "MetricFu" => library_details,
  }
end

#environment_detailsObject



78
79
80
81
82
83
84
85
86
87
# File 'lib/metric_fu/environment.rb', line 78

def environment_details
  @environment_details ||= {
    "VERBOSE" => $VERBOSE.inspect,
    "External Encoding" => Encoding.default_external.to_s,
    "Internal Encoding" => Encoding.default_internal.to_s,
    "Host Architecture" => RbConfig::CONFIG["build"],
    "Ruby Prefix"       => RbConfig::CONFIG["prefix"],
    "Ruby Options"      => ENV.keys.grep(/RUBYOPT/).map { |key| "#{key}=#{ENV[key]}" }.join(", "),
  }
end

#is_cruise_control_rb?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/metric_fu/environment.rb', line 29

def is_cruise_control_rb?
  !!ENV["CC_BUILD_ARTIFACTS"]
end

#jruby?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/metric_fu/environment.rb', line 33

def jruby?
  @jruby ||= !!RedCard.check(:jruby)
end

#library_detailsObject



103
104
105
106
107
108
109
110
# File 'lib/metric_fu/environment.rb', line 103

def library_details
  @library_details ||= {
    "Version" =>  version,
    "Verbose Mode" => verbose,
    "Enabled Metrics" => MetricFu::Metric.enabled_metrics.map(&:name),
    "Dependencies" => MetricFu::GemVersion.dependencies_summary,
  }
end

#mri?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/metric_fu/environment.rb', line 37

def mri?
  @mri ||= !!RedCard.check(:ruby)
end

#osx?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/metric_fu/environment.rb', line 120

def osx?
  @osx ||= platform.include?("darwin")
end

#platformObject

:nodoc:



70
71
72
# File 'lib/metric_fu/environment.rb', line 70

def platform #:nodoc:
  RUBY_PLATFORM
end

#rails?Boolean

Perform a simple check to try and guess if we’re running against a rails app.

TODO This should probably be made a bit more robust.

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
# File 'lib/metric_fu/environment.rb', line 19

def rails?
  @rails ||= begin
               exists = File.exist?("config/environment.rb")
               def MetricFu.rails?
                 exists
               end
               exists
             end
end

#rubinius?Boolean

Returns:

  • (Boolean)


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

def rubinius?
  @rubinius ||= !!RedCard.check(:rubinius)
end

#ruby18?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/metric_fu/environment.rb', line 49

def ruby18?
  @ruby18 ||= mri? && !!RedCard.check("1.8"..."1.9")
end

#ruby192?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/metric_fu/environment.rb', line 53

def ruby192?
  @ruby192 ||= mri? && ruby_version == "1.9.2"
end

#ruby_detailsObject

To consider $LOADED_FEATURES $LOAD_PATH



92
93
94
95
96
97
98
99
100
101
# File 'lib/metric_fu/environment.rb', line 92

def ruby_details
  @ruby_details ||= {
    "Engine" => ruby_flavor,
    "Version" => ruby_version,
    "Patchlevel" => (defined?(RUBY_PATCHLEVEL) && RUBY_PATCHLEVEL),
    "Ripper Support" => supports_ripper?,
    "Rubygems Version" => Gem::VERSION,
    "Long Description" => (defined?(RUBY_DESCRIPTION) ? RUBY_DESCRIPTION : platform),
  }
end

#ruby_flavorObject



41
42
43
# File 'lib/metric_fu/environment.rb', line 41

def ruby_flavor
  @ruby_flavor ||= RedCard.engine
end

#ruby_versionObject



45
46
47
# File 'lib/metric_fu/environment.rb', line 45

def ruby_version
  @ruby_version ||= RedCard.engine_version
end

#supports_ripper?Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
67
68
# File 'lib/metric_fu/environment.rb', line 61

def supports_ripper?
  @supports_ripper ||= begin
                         require "ripper"
                         true
                       rescue LoadError
                         false
                       end
end

#verboseObject

TODO: Set log_level here, instead



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

def verbose
  MetricFu.logger.debug_on
end

#verbose=(toggle) ⇒ Object



11
12
13
# File 'lib/metric_fu/environment.rb', line 11

def verbose=(toggle)
  MetricFu.logger.debug_on = toggle
end

#versionObject



74
75
76
# File 'lib/metric_fu/environment.rb', line 74

def version
  MetricFu::VERSION
end