Sha256: 3a43fc7475aa3a7623fe2fd7615a0ef93a5e0a84dcddb170f20f8ab69bfe9f40

Contents?: true

Size: 1.06 KB

Versions: 27

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true
module Capybara
  class Selector
    class Filter
      def initialize(name, block, options={})
        @name = name
        @block = block
        @options = options
        @options[:valid_values] = [true,false] if options[:boolean]
      end

      def default?
        @options.has_key?(:default)
      end

      def default
        @options[:default]
      end

      def matches?(node, value)
        return true if skip?(value)

        if !valid_value?(value)
          msg = "Invalid value #{value.inspect} passed to filter #{@name} - "
          if default?
            warn msg + "defaulting to #{default}"
            value = default
          else
            warn msg + "skipping"
            return true
          end
        end

        @block.call(node, value)
      end

      def skip?(value)
        @options.has_key?(:skip_if) && value == @options[:skip_if]
      end

      private

      def valid_value?(value)
        !@options.has_key?(:valid_values) || Array(@options[:valid_values]).include?(value)
      end
    end
  end
end

Version data entries

27 entries across 25 versions & 4 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/capybara-2.14.3/lib/capybara/selector/filter.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/capybara-2.13.0/lib/capybara/selector/filter.rb
tdiary-5.0.5 vendor/bundle/gems/capybara-2.13.0/lib/capybara/selector/filter.rb
capybara-2.14.4 lib/capybara/selector/filter.rb
capybara-2.14.3 lib/capybara/selector/filter.rb
capybara-2.14.2 lib/capybara/selector/filter.rb
capybara-2.14.1 lib/capybara/selector/filter.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/capybara-2.14.0/lib/capybara/selector/filter.rb
capybara-2.14.0 lib/capybara/selector/filter.rb
tdiary-5.0.4 vendor/bundle/gems/capybara-2.13.0/lib/capybara/selector/filter.rb
capybara-2.13.0 lib/capybara/selector/filter.rb
capybara-2.12.1 lib/capybara/selector/filter.rb
capybara-2.12.0 lib/capybara/selector/filter.rb
capybara-2.11.0 lib/capybara/selector/filter.rb
capybara-2.10.2 lib/capybara/selector/filter.rb
capybara-2.10.1 lib/capybara/selector/filter.rb
capybara-2.10.0 lib/capybara/selector/filter.rb
capybara-2.9.2 lib/capybara/selector/filter.rb
tdiary-5.0.2 vendor/bundle/gems/capybara-2.8.0/lib/capybara/selector/filter.rb
capybara-2.9.1 lib/capybara/selector/filter.rb