Class: Hoe::Debugging::ValgrindHelper
- Inherits:
-
Object
- Object
- Hoe::Debugging::ValgrindHelper
- Defined in:
- lib/hoe/debugging.rb
Constant Summary collapse
- DEFAULT_DIRECTORY_NAME =
"suppressions"
Instance Attribute Summary collapse
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
Instance Method Summary collapse
- #formatted_ruby_version ⇒ Object
-
#initialize(project_name, options = {}) ⇒ ValgrindHelper
constructor
A new instance of ValgrindHelper.
- #matching_suppression_files ⇒ Object
- #parse_suppressions_from(logfile_name) ⇒ Object
- #save_suppressions_from(logfile, options = {}) ⇒ Object
- #valgrind ⇒ Object
- #version_matches ⇒ Object
Constructor Details
#initialize(project_name, options = {}) ⇒ ValgrindHelper
Returns a new instance of ValgrindHelper.
139 140 141 142 |
# File 'lib/hoe/debugging.rb', line 139 def initialize project_name, ={} @project_name = project_name @directory = [:directory] || DEFAULT_DIRECTORY_NAME end |
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
137 138 139 |
# File 'lib/hoe/debugging.rb', line 137 def directory @directory end |
#project_name ⇒ Object
Returns the value of attribute project_name.
137 138 139 |
# File 'lib/hoe/debugging.rb', line 137 def project_name @project_name end |
Instance Method Details
#formatted_ruby_version ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/hoe/debugging.rb', line 144 def formatted_ruby_version engine = if defined?(RUBY_DESCRIPTION) && RUBY_DESCRIPTION =~ /Ruby Enterprise Edition/ "ree" else defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby" end %Q{#{engine}-#{RUBY_VERSION}.#{RUBY_PATCHLEVEL}} end |
#matching_suppression_files ⇒ Object
192 193 194 195 196 197 198 199 |
# File 'lib/hoe/debugging.rb', line 192 def matching_suppression_files matching_files = [] version_matches.each do |version_string| matching_files += Dir[File.join(directory, "#{project_name}_#{version_string}.supp")] matching_files += Dir[File.join(directory, "#{project_name}_#{version_string}_*.supp")] end matching_files end |
#parse_suppressions_from(logfile_name) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/hoe/debugging.rb', line 161 def parse_suppressions_from logfile_name suppressions = [] File.open logfile_name do |logfile| suppression = nil while ! logfile.eof? do line = logfile.readline if suppression.nil? if line =~ /\<insert_a_suppression_name_here\>/ suppression = String.new "{\n" suppression << line end else suppression << line if line =~ /^\}$/ suppressions << suppression suppression = nil end end end end suppressions.uniq.join end |
#save_suppressions_from(logfile, options = {}) ⇒ Object
184 185 186 187 188 189 190 |
# File 'lib/hoe/debugging.rb', line 184 def save_suppressions_from logfile, ={} ensure_directory_exists suppressions = parse_suppressions_from logfile filename = File.join directory, "#{project_name}_#{formatted_ruby_version}.supp" File.open(filename, "w") { |out| out.write suppressions } filename end |
#valgrind ⇒ Object
201 202 203 204 205 |
# File 'lib/hoe/debugging.rb', line 201 def valgrind # note that valgrind will generally crap out on rubies >= 2.1 # unless we increase the max stack size beyond the default "ulimit -s unlimited && valgrind" end |
#version_matches ⇒ Object
153 154 155 156 157 158 159 |
# File 'lib/hoe/debugging.rb', line 153 def version_matches matches = [formatted_ruby_version] # e.g. "ruby-2.5.1.57" matches << formatted_ruby_version.split(".")[0,3].join(".") # e.g. "ruby-2.5.1" matches << formatted_ruby_version.split(".")[0,2].join(".") # e.g. "ruby-2.5" matches << formatted_ruby_version.split(".")[0,1].join(".") # e.g. "ruby-2" matches end |