simplecov 0.13.0 → 0.17.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +99 -3
  3. data/CONTRIBUTING.md +12 -9
  4. data/ISSUE_TEMPLATE.md +23 -0
  5. data/{MIT-LICENSE → LICENSE} +1 -1
  6. data/README.md +90 -43
  7. data/doc/alternate-formatters.md +21 -1
  8. data/doc/editor-integration.md +6 -1
  9. data/lib/simplecov.rb +131 -13
  10. data/lib/simplecov/command_guesser.rb +2 -0
  11. data/lib/simplecov/configuration.rb +34 -25
  12. data/lib/simplecov/defaults.rb +12 -82
  13. data/lib/simplecov/exit_codes.rb +2 -0
  14. data/lib/simplecov/file_list.rb +7 -5
  15. data/lib/simplecov/filter.rb +41 -4
  16. data/lib/simplecov/formatter.rb +2 -0
  17. data/lib/simplecov/formatter/multi_formatter.rb +2 -0
  18. data/lib/simplecov/formatter/simple_formatter.rb +3 -1
  19. data/lib/simplecov/jruby_fix.rb +2 -0
  20. data/lib/simplecov/last_run.rb +5 -1
  21. data/lib/simplecov/lines_classifier.rb +48 -0
  22. data/lib/simplecov/load_global_config.rb +8 -0
  23. data/lib/simplecov/no_defaults.rb +2 -0
  24. data/lib/simplecov/profiles.rb +2 -0
  25. data/lib/simplecov/profiles/bundler_filter.rb +5 -0
  26. data/lib/simplecov/profiles/hidden_filter.rb +5 -0
  27. data/lib/simplecov/profiles/rails.rb +18 -0
  28. data/lib/simplecov/profiles/root_filter.rb +10 -0
  29. data/lib/simplecov/profiles/test_frameworks.rb +8 -0
  30. data/lib/simplecov/railtie.rb +2 -0
  31. data/lib/simplecov/railties/tasks.rake +2 -0
  32. data/lib/simplecov/raw_coverage.rb +41 -0
  33. data/lib/simplecov/result.rb +2 -1
  34. data/lib/simplecov/result_merger.rb +56 -21
  35. data/lib/simplecov/source_file.rb +43 -34
  36. data/lib/simplecov/version.rb +3 -23
  37. metadata +131 -99
  38. data/.gitignore +0 -31
  39. data/.rspec +0 -3
  40. data/.rubocop.yml +0 -84
  41. data/.travis.yml +0 -32
  42. data/.yardopts +0 -1
  43. data/Gemfile +0 -38
  44. data/Rakefile +0 -41
  45. data/cucumber.yml +0 -13
  46. data/features/config_autoload.feature +0 -46
  47. data/features/config_command_name.feature +0 -45
  48. data/features/config_coverage_dir.feature +0 -33
  49. data/features/config_deactivate_merging.feature +0 -42
  50. data/features/config_formatters.feature +0 -77
  51. data/features/config_merge_timeout.feature +0 -39
  52. data/features/config_nocov_token.feature +0 -79
  53. data/features/config_profiles.feature +0 -44
  54. data/features/config_project_name.feature +0 -27
  55. data/features/config_styles.feature +0 -121
  56. data/features/config_tracked_files.feature +0 -29
  57. data/features/cucumber_basic.feature +0 -29
  58. data/features/maximum_coverage_drop.feature +0 -36
  59. data/features/merging_test_unit_and_rspec.feature +0 -44
  60. data/features/minimum_coverage.feature +0 -59
  61. data/features/refuse_coverage_drop.feature +0 -35
  62. data/features/rspec_basic.feature +0 -32
  63. data/features/rspec_fails_on_initialization.feature +0 -14
  64. data/features/rspec_groups_and_filters_basic.feature +0 -29
  65. data/features/rspec_groups_and_filters_complex.feature +0 -37
  66. data/features/rspec_groups_using_filter_class.feature +0 -41
  67. data/features/rspec_without_simplecov.feature +0 -20
  68. data/features/skipping_code_blocks_manually.feature +0 -70
  69. data/features/step_definitions/html_steps.rb +0 -44
  70. data/features/step_definitions/simplecov_steps.rb +0 -68
  71. data/features/step_definitions/transformers.rb +0 -13
  72. data/features/step_definitions/web_steps.rb +0 -64
  73. data/features/support/env.rb +0 -50
  74. data/features/test_unit_basic.feature +0 -34
  75. data/features/test_unit_groups_and_filters_basic.feature +0 -29
  76. data/features/test_unit_groups_and_filters_complex.feature +0 -35
  77. data/features/test_unit_groups_using_filter_class.feature +0 -40
  78. data/features/test_unit_without_simplecov.feature +0 -20
  79. data/features/unicode_compatiblity.feature +0 -67
  80. data/lib/simplecov/merge_helpers.rb +0 -37
  81. data/simplecov.gemspec +0 -27
  82. data/spec/1_8_fallbacks_spec.rb +0 -31
  83. data/spec/command_guesser_spec.rb +0 -48
  84. data/spec/deleted_source_spec.rb +0 -12
  85. data/spec/faked_project/Gemfile +0 -6
  86. data/spec/faked_project/Rakefile +0 -8
  87. data/spec/faked_project/cucumber.yml +0 -13
  88. data/spec/faked_project/features/step_definitions/my_steps.rb +0 -22
  89. data/spec/faked_project/features/support/env.rb +0 -12
  90. data/spec/faked_project/features/test_stuff.feature +0 -6
  91. data/spec/faked_project/lib/faked_project.rb +0 -11
  92. data/spec/faked_project/lib/faked_project/framework_specific.rb +0 -18
  93. data/spec/faked_project/lib/faked_project/meta_magic.rb +0 -24
  94. data/spec/faked_project/lib/faked_project/some_class.rb +0 -28
  95. data/spec/faked_project/lib/faked_project/untested_class.rb +0 -11
  96. data/spec/faked_project/spec/faked_spec.rb +0 -11
  97. data/spec/faked_project/spec/forking_spec.rb +0 -8
  98. data/spec/faked_project/spec/meta_magic_spec.rb +0 -15
  99. data/spec/faked_project/spec/some_class_spec.rb +0 -13
  100. data/spec/faked_project/spec/spec_helper.rb +0 -11
  101. data/spec/faked_project/test/faked_test.rb +0 -11
  102. data/spec/faked_project/test/meta_magic_test.rb +0 -13
  103. data/spec/faked_project/test/some_class_test.rb +0 -15
  104. data/spec/faked_project/test/test_helper.rb +0 -12
  105. data/spec/file_list_spec.rb +0 -50
  106. data/spec/filters_spec.rb +0 -98
  107. data/spec/fixtures/app/controllers/sample_controller.rb +0 -10
  108. data/spec/fixtures/app/models/user.rb +0 -10
  109. data/spec/fixtures/deleted_source_sample.rb +0 -15
  110. data/spec/fixtures/frameworks/rspec_bad.rb +0 -9
  111. data/spec/fixtures/frameworks/rspec_good.rb +0 -9
  112. data/spec/fixtures/frameworks/testunit_bad.rb +0 -9
  113. data/spec/fixtures/frameworks/testunit_good.rb +0 -9
  114. data/spec/fixtures/iso-8859.rb +0 -3
  115. data/spec/fixtures/resultset1.rb +0 -4
  116. data/spec/fixtures/resultset2.rb +0 -4
  117. data/spec/fixtures/sample.rb +0 -16
  118. data/spec/fixtures/utf-8.rb +0 -3
  119. data/spec/helper.rb +0 -24
  120. data/spec/merge_helpers_spec.rb +0 -126
  121. data/spec/multi_formatter_spec.rb +0 -20
  122. data/spec/result_spec.rb +0 -209
  123. data/spec/return_codes_spec.rb +0 -34
  124. data/spec/source_file_line_spec.rb +0 -155
  125. data/spec/source_file_spec.rb +0 -77
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleCov
2
4
  module ExitCodes
3
5
  SUCCESS = 0
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # An array of SimpleCov SourceFile instances with additional collection helper
2
4
  # methods for calculating coverage across them etc.
3
5
  module SimpleCov
@@ -5,25 +7,25 @@ module SimpleCov
5
7
  # Returns the count of lines that have coverage
6
8
  def covered_lines
7
9
  return 0.0 if empty?
8
- map { |f| f.covered_lines.count }.inject(&:+)
10
+ map { |f| f.covered_lines.count }.inject(:+)
9
11
  end
10
12
 
11
13
  # Returns the count of lines that have been missed
12
14
  def missed_lines
13
15
  return 0.0 if empty?
14
- map { |f| f.missed_lines.count }.inject(&:+)
16
+ map { |f| f.missed_lines.count }.inject(:+)
15
17
  end
16
18
 
17
19
  # Returns the count of lines that are not relevant for coverage
18
20
  def never_lines
19
21
  return 0.0 if empty?
20
- map { |f| f.never_lines.count }.inject(&:+)
22
+ map { |f| f.never_lines.count }.inject(:+)
21
23
  end
22
24
 
23
25
  # Returns the count of skipped lines
24
26
  def skipped_lines
25
27
  return 0.0 if empty?
26
- map { |f| f.skipped_lines.count }.inject(&:+)
28
+ map { |f| f.skipped_lines.count }.inject(:+)
27
29
  end
28
30
 
29
31
  # Computes the coverage based upon lines covered and lines missed for each file
@@ -53,7 +55,7 @@ module SimpleCov
53
55
  # @return [Float]
54
56
  def covered_strength
55
57
  return 0.0 if empty? || lines_of_code.zero?
56
- Float(map { |f| f.covered_strength * f.lines_of_code }.inject(&:+) / lines_of_code)
58
+ Float(map { |f| f.covered_strength * f.lines_of_code }.inject(:+) / lines_of_code)
57
59
  end
58
60
  end
59
61
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleCov
2
4
  #
3
5
  # Base filter class. Inherit from this to create custom filters,
@@ -24,13 +26,40 @@ module SimpleCov
24
26
  warn "#{Kernel.caller.first}: [DEPRECATION] #passes? is deprecated. Use #matches? instead."
25
27
  matches?(source_file)
26
28
  end
29
+
30
+ def self.build_filter(filter_argument)
31
+ return filter_argument if filter_argument.is_a?(SimpleCov::Filter)
32
+ class_for_argument(filter_argument).new(filter_argument)
33
+ end
34
+
35
+ def self.class_for_argument(filter_argument)
36
+ if filter_argument.is_a?(String)
37
+ SimpleCov::StringFilter
38
+ elsif filter_argument.is_a?(Regexp)
39
+ SimpleCov::RegexFilter
40
+ elsif filter_argument.is_a?(Array)
41
+ SimpleCov::ArrayFilter
42
+ elsif filter_argument.is_a?(Proc)
43
+ SimpleCov::BlockFilter
44
+ else
45
+ raise ArgumentError, "You have provided an unrecognized filter type"
46
+ end
47
+ end
27
48
  end
28
49
 
29
50
  class StringFilter < SimpleCov::Filter
30
51
  # Returns true when the given source file's filename matches the
31
52
  # string configured when initializing this Filter with StringFilter.new('somestring)
32
53
  def matches?(source_file)
33
- (source_file.filename =~ /#{filter_argument}/)
54
+ source_file.project_filename.include?(filter_argument)
55
+ end
56
+ end
57
+
58
+ class RegexFilter < SimpleCov::Filter
59
+ # Returns true when the given source file's filename matches the
60
+ # regex configured when initializing this Filter with RegexFilter.new(/someregex/)
61
+ def matches?(source_file)
62
+ (source_file.project_filename =~ filter_argument)
34
63
  end
35
64
  end
36
65
 
@@ -43,11 +72,19 @@ module SimpleCov
43
72
  end
44
73
 
45
74
  class ArrayFilter < SimpleCov::Filter
46
- # Returns true if any of the file paths passed in the given array matches the string
47
- # configured when initializing this Filter with StringFilter.new(['some/path', 'other/path'])
75
+ def initialize(filter_argument)
76
+ filter_objects = filter_argument.map do |arg|
77
+ Filter.build_filter(arg)
78
+ end
79
+
80
+ super(filter_objects)
81
+ end
82
+
83
+ # Returns true if any of the filters in the array match the given source file.
84
+ # Configure this Filter like StringFilter.new(['some/path', /^some_regex/, Proc.new {|src_file| ... }])
48
85
  def matches?(source_files_list)
49
86
  filter_argument.any? do |arg|
50
- source_files_list.filename =~ /#{arg}/
87
+ arg.matches?(source_files_list)
51
88
  end
52
89
  end
53
90
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleCov
2
4
  # TODO: Documentation on how to build your own formatters
3
5
  module Formatter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleCov
2
4
  module Formatter
3
5
  class MultiFormatter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # A ridiculously simple formatter for SimpleCov results.
3
5
  #
@@ -6,7 +8,7 @@ module SimpleCov
6
8
  class SimpleFormatter
7
9
  # Takes a SimpleCov::Result and generates a string out of it
8
10
  def format(result)
9
- output = ""
11
+ output = "".dup
10
12
  result.groups.each do |name, files|
11
13
  output << "Group: #{name}\n"
12
14
  output << "=" * 40
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if defined?(JRUBY_VERSION) && JRUBY_VERSION.to_f < 1.7
2
4
  require "jruby"
3
5
  java_import "org.jruby.ast.NodeType"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "json"
2
4
 
3
5
  module SimpleCov
@@ -9,7 +11,9 @@ module SimpleCov
9
11
 
10
12
  def read
11
13
  return nil unless File.exist?(last_run_path)
12
- JSON.parse(File.read(last_run_path))
14
+ json = File.read(last_run_path)
15
+ return nil if json.strip.empty?
16
+ JSON.parse(json)
13
17
  end
14
18
 
15
19
  def write(json)
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleCov
4
+ # Classifies whether lines are relevant for code coverage analysis.
5
+ # Comments & whitespace lines, and :nocov: token blocks, are considered not relevant.
6
+
7
+ class LinesClassifier
8
+ RELEVANT = 0
9
+ NOT_RELEVANT = nil
10
+
11
+ WHITESPACE_LINE = /^\s*$/
12
+ COMMENT_LINE = /^\s*#/
13
+ WHITESPACE_OR_COMMENT_LINE = Regexp.union(WHITESPACE_LINE, COMMENT_LINE)
14
+
15
+ def self.no_cov_line
16
+ /^(\s*)#(\s*)(\:#{SimpleCov.nocov_token}\:)/o
17
+ end
18
+
19
+ def self.no_cov_line?(line)
20
+ line =~ no_cov_line
21
+ rescue ArgumentError
22
+ # E.g., line contains an invalid byte sequence in UTF-8
23
+ false
24
+ end
25
+
26
+ def self.whitespace_line?(line)
27
+ line =~ WHITESPACE_OR_COMMENT_LINE
28
+ rescue ArgumentError
29
+ # E.g., line contains an invalid byte sequence in UTF-8
30
+ false
31
+ end
32
+
33
+ def classify(lines)
34
+ skipping = false
35
+
36
+ lines.map do |line|
37
+ if self.class.no_cov_line?(line)
38
+ skipping = !skipping
39
+ NOT_RELEVANT
40
+ elsif skipping || self.class.whitespace_line?(line)
41
+ NOT_RELEVANT
42
+ else
43
+ RELEVANT
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "etc"
4
+ home_dir = (ENV["HOME"] && File.expand_path("~")) || Etc.getpwuid.dir || (ENV["USER"] && File.expand_path("~#{ENV['USER']}"))
5
+ if home_dir
6
+ global_config_path = File.join(home_dir, ".simplecov")
7
+ load global_config_path if File.exist?(global_config_path)
8
+ end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ENV["SIMPLECOV_NO_DEFAULTS"] = "yes, no defaults"
2
4
  require "simplecov"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # Profiles are SimpleCov configuration procs that can be easily
3
5
  # loaded using SimpleCov.start :rails and defined using
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.profiles.define "bundler_filter" do
4
+ add_filter "/vendor/bundle/"
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.profiles.define "hidden_filter" do
4
+ add_filter %r{^/\..*}
5
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.profiles.define "rails" do
4
+ load_profile "test_frameworks"
5
+
6
+ add_filter %r{^/config/}
7
+ add_filter %r{^/db/}
8
+
9
+ add_group "Controllers", "app/controllers"
10
+ add_group "Channels", "app/channels"
11
+ add_group "Models", "app/models"
12
+ add_group "Mailers", "app/mailers"
13
+ add_group "Helpers", "app/helpers"
14
+ add_group "Jobs", %w[app/jobs app/workers]
15
+ add_group "Libraries", "lib/"
16
+
17
+ track_files "{app,lib}/**/*.rb"
18
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.profiles.define "root_filter" do
4
+ # Exclude all files outside of simplecov root
5
+ root_filter = nil
6
+ add_filter do |src|
7
+ root_filter ||= /\A#{Regexp.escape(SimpleCov.root + File::SEPARATOR)}/io
8
+ src.filename !~ root_filter
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ SimpleCov.profiles.define "test_frameworks" do
4
+ add_filter "/test/"
5
+ add_filter "/features/"
6
+ add_filter "/spec/"
7
+ add_filter "/autotest/"
8
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleCov
2
4
  class Railtie < ::Rails::Railtie
3
5
  rake_tasks do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rake/testtask"
2
4
  Rake::TestTask.new do |t|
3
5
  t.name = "simplecov"
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleCov
4
+ module RawCoverage
5
+ module_function
6
+
7
+ # Merges multiple Coverage.result hashes
8
+ def merge_results(*results)
9
+ results.reduce({}) do |result, merged|
10
+ merge_resultsets(result, merged)
11
+ end
12
+ end
13
+
14
+ # Merges two Coverage.result hashes
15
+ def merge_resultsets(result1, result2)
16
+ (result1.keys | result2.keys).each_with_object({}) do |filename, merged|
17
+ file1 = result1[filename]
18
+ file2 = result2[filename]
19
+ merged[filename] = merge_file_coverage(file1, file2)
20
+ end
21
+ end
22
+
23
+ def merge_file_coverage(file1, file2)
24
+ return (file1 || file2).dup unless file1 && file2
25
+
26
+ file1.map.with_index do |count1, index|
27
+ count2 = file2[index]
28
+ merge_line_coverage(count1, count2)
29
+ end
30
+ end
31
+
32
+ def merge_line_coverage(count1, count2)
33
+ sum = count1.to_i + count2.to_i
34
+ if sum.zero? && (count1.nil? || count2.nil?)
35
+ nil
36
+ else
37
+ sum
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "digest/sha1"
2
4
  require "forwardable"
3
5
 
@@ -24,7 +26,6 @@ module SimpleCov
24
26
  # Initialize a new SimpleCov::Result from given Coverage.result (a Hash of filenames each containing an array of
25
27
  # coverage data)
26
28
  def initialize(original_result)
27
- original_result = original_result.dup.extend(SimpleCov::HashMergeHelper) unless original_result.is_a? SimpleCov::HashMergeHelper
28
29
  @original_result = original_result.freeze
29
30
  @files = SimpleCov::FileList.new(original_result.map do |filename, coverage|
30
31
  SimpleCov::SourceFile.new(filename, coverage) if File.file?(filename)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "json"
2
4
 
3
5
  #
@@ -17,25 +19,31 @@ module SimpleCov
17
19
  File.join(SimpleCov.coverage_path, ".resultset.json.lock")
18
20
  end
19
21
 
20
- # Loads the cached resultset from JSON and returns it as a Hash
22
+ # Loads the cached resultset from JSON and returns it as a Hash,
23
+ # caching it for subsequent accesses.
21
24
  def resultset
22
- if stored_data
23
- begin
24
- JSON.parse(stored_data)
25
- rescue
25
+ @resultset ||= begin
26
+ data = stored_data
27
+ if data
28
+ begin
29
+ JSON.parse(data) || {}
30
+ rescue
31
+ {}
32
+ end
33
+ else
26
34
  {}
27
35
  end
28
- else
29
- {}
30
36
  end
31
37
  end
32
38
 
33
39
  # Returns the contents of the resultset cache as a string or if the file is missing or empty nil
34
40
  def stored_data
35
- return unless File.exist?(resultset_path)
36
- data = File.read(resultset_path)
37
- return if data.nil? || data.length < 2
38
- data
41
+ synchronize_resultset do
42
+ return unless File.exist?(resultset_path)
43
+ data = File.read(resultset_path)
44
+ return if data.nil? || data.length < 2
45
+ data
46
+ end
39
47
  end
40
48
 
41
49
  # Gets the resultset hash and re-creates all included instances
@@ -54,26 +62,31 @@ module SimpleCov
54
62
  results
55
63
  end
56
64
 
65
+ # Merge two or more SimpleCov::Results into a new one with merged
66
+ # coverage data and the command_name for the result consisting of a join
67
+ # on all source result's names
68
+ def merge_results(*results)
69
+ merged = SimpleCov::RawCoverage.merge_results(*results.map(&:original_result))
70
+ result = SimpleCov::Result.new(merged)
71
+ # Specify the command name
72
+ result.command_name = results.map(&:command_name).sort.join(", ")
73
+ result
74
+ end
75
+
57
76
  #
58
77
  # Gets all SimpleCov::Results from cache, merges them and produces a new
59
78
  # SimpleCov::Result with merged coverage data and the command_name
60
79
  # for the result consisting of a join on all source result's names
61
80
  #
62
81
  def merged_result
63
- merged = {}
64
- results.each do |result|
65
- merged = result.original_result.merge_resultset(merged)
66
- end
67
- result = SimpleCov::Result.new(merged)
68
- # Specify the command name
69
- result.command_name = results.map(&:command_name).sort.join(", ")
70
- result
82
+ merge_results(*results)
71
83
  end
72
84
 
73
85
  # Saves the given SimpleCov::Result in the resultset cache
74
86
  def store_result(result)
75
- File.open(resultset_writelock, "w+") do |f|
76
- f.flock(File::LOCK_EX)
87
+ synchronize_resultset do
88
+ # Ensure we have the latest, in case it was already cached
89
+ clear_resultset
77
90
  new_set = resultset
78
91
  command_name, data = result.to_hash.first
79
92
  new_set[command_name] = data
@@ -83,6 +96,28 @@ module SimpleCov
83
96
  end
84
97
  true
85
98
  end
99
+
100
+ # Ensure only one process is reading or writing the resultset at any
101
+ # given time
102
+ def synchronize_resultset
103
+ # make it reentrant
104
+ return yield if defined?(@resultset_locked) && @resultset_locked
105
+
106
+ begin
107
+ @resultset_locked = true
108
+ File.open(resultset_writelock, "w+") do |f|
109
+ f.flock(File::LOCK_EX)
110
+ yield
111
+ end
112
+ ensure
113
+ @resultset_locked = false
114
+ end
115
+ end
116
+
117
+ # Clear out the previously cached .resultset
118
+ def clear_resultset
119
+ @resultset = nil
120
+ end
86
121
  end
87
122
  end
88
123
  end