Sha256: c4f56fa1d08717f9dd28e1cf1df870a3e481dc1e0594e2eb0e1ec7392b92096e

Contents?: true

Size: 957 Bytes

Versions: 25

Compression:

Stored size: 957 Bytes

Contents

# frozen_string_literal: true

# This class keeps track of checks being turned on and off in ranges.
# We'll use the node position to figure out if the test is disabled or not.
module PlatformosCheck
  class DisabledCheck
    attr_reader :name, :app_file, :ranges
    attr_accessor :first_line

    def initialize(app_file, name)
      @app_file = app_file
      @name = name
      @ranges = []
      @first_line = false
    end

    def start_index=(index)
      return unless ranges.empty? || !last.end.nil?

      @ranges << (index..)
    end

    def end_index=(index)
      return if ranges.empty? || !last.end.nil?

      @ranges << (@ranges.pop.begin..index)
    end

    def disabled?(index)
      (index == 0 && first_line) ||
        ranges.any? { |range| range.cover?(index) }
    end

    def last
      ranges.last
    end

    def missing_end_index?
      return false if first_line && ranges.size == 1

      last&.end.nil?
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
platformos-check-0.2.0 lib/platformos_check/disabled_check.rb
platformos-check-0.1.0 lib/platformos_check/disabled_check.rb
platformos-check-0.0.3 lib/platformos_check/disabled_check.rb
platformos-check-0.0.2 lib/platformos_check/disabled_check.rb
platformos-check-0.0.1 lib/platformos_check/disabled_check.rb