Add FilterSet::[]
This commit is contained in:
parent
5c8d8141af
commit
8354eef965
|
@ -194,7 +194,7 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_set(name)
|
def filter_set(name)
|
||||||
::Capybara::Selector::FilterSet.all[name]
|
::Capybara::Selector::FilterSet[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
def node_filters
|
def node_filters
|
||||||
|
|
|
@ -52,15 +52,16 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def import(name, filters = nil)
|
def import(name, filters = nil)
|
||||||
f_set = self.class.all[name]
|
|
||||||
filter_selector = filters.nil? ? ->(*) { true } : ->(filter_name, _) { filters.include? filter_name }
|
filter_selector = filters.nil? ? ->(*) { true } : ->(filter_name, _) { filters.include? filter_name }
|
||||||
|
|
||||||
expression_filters.merge!(f_set.expression_filters.select(&filter_selector))
|
self.class[name].tap do |f_set|
|
||||||
node_filters.merge!(f_set.node_filters.select(&filter_selector))
|
expression_filters.merge!(f_set.expression_filters.select(&filter_selector))
|
||||||
|
node_filters.merge!(f_set.node_filters.select(&filter_selector))
|
||||||
f_set.undeclared_descriptions.each { |desc| describe(&desc) }
|
f_set.undeclared_descriptions.each { |desc| describe(&desc) }
|
||||||
f_set.expression_filter_descriptions.each { |desc| describe(:expression_filters, &desc) }
|
f_set.expression_filter_descriptions.each { |desc| describe(:expression_filters, &desc) }
|
||||||
f_set.node_filter_descriptions.each { |desc| describe(:node_filters, &desc) }
|
f_set.node_filter_descriptions.each { |desc| describe(:node_filters, &desc) }
|
||||||
|
end
|
||||||
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
@ -68,6 +69,10 @@ module Capybara
|
||||||
@filter_sets ||= {} # rubocop:disable Naming/MemoizedInstanceVariableName
|
@filter_sets ||= {} # rubocop:disable Naming/MemoizedInstanceVariableName
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def [](name)
|
||||||
|
all.fetch(name.to_sym) { |set_name| raise ArgumentError, "Unknown filter set (:#{set_name})" }
|
||||||
|
end
|
||||||
|
|
||||||
def add(name, &block)
|
def add(name, &block)
|
||||||
all[name.to_sym] = FilterSet.new(name.to_sym, &block)
|
all[name.to_sym] = FilterSet.new(name.to_sym, &block)
|
||||||
end
|
end
|
||||||
|
@ -107,11 +112,8 @@ module Capybara
|
||||||
types.each { |type| options[type] = true }
|
types.each { |type| options[type] = true }
|
||||||
raise 'ArgumentError', ':default option is not supported for filters with a :matcher option' if matcher && options[:default]
|
raise 'ArgumentError', ':default option is not supported for filters with a :matcher option' if matcher && options[:default]
|
||||||
|
|
||||||
if filter_class <= Filters::ExpressionFilter
|
filter = filter_class.new(name, matcher, block, options)
|
||||||
@expression_filters[name] = filter_class.new(name, matcher, block, options)
|
(filter_class <= Filters::ExpressionFilter ? @expression_filters : @node_filters)[name] = filter
|
||||||
else
|
|
||||||
@node_filters[name] = filter_class.new(name, matcher, block, options)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue