Sha256: bcc294a222f34807657b1d6d2d50e2b30ad94251ee3e24cd685fcc407abdd26e
Contents?: true
Size: 1.79 KB
Versions: 1
Compression:
Stored size: 1.79 KB
Contents
# frozen_string_literal: true require 'capybara/selector/filter' module Capybara class Selector class FilterSet attr_reader :descriptions def initialize(name, &block) @name = name @descriptions = [] instance_eval(&block) end def filter(name, *types_and_options, &block) add_filter(name, Filters::NodeFilter, *types_and_options, &block) end def expression_filter(name, *types_and_options, &block) add_filter(name, Filters::ExpressionFilter, *types_and_options, &block) end def describe(&block) descriptions.push block end def description(**options) opts = options_with_defaults(options) @descriptions.map do |desc| desc.call(opts).to_s end.join end def filters @filters ||= {} end def node_filters filters.reject { |_n, f| f.nil? || f.is_a?(Filters::ExpressionFilter) }.freeze end def expression_filters filters.select { |_n, f| f.nil? || f.is_a?(Filters::ExpressionFilter) }.freeze end class << self def all @filter_sets ||= {} end def add(name, &block) all[name.to_sym] = FilterSet.new(name.to_sym, &block) end def remove(name) all.delete(name.to_sym) end end private def options_with_defaults(options) options = options.dup filters.each do |name, filter| options[name] = filter.default if filter.default? && !options.key?(name) end options end def add_filter(name, filter_class, *types, **options, &block) types.each { |k| options[k] = true } filters[name] = filter_class.new(name, block, options) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
capybara-3.0.0.rc1 | lib/capybara/selector/filter_set.rb |