Class: Capybara::Selector::FilterSet
- Inherits:
-
Object
- Object
- Capybara::Selector::FilterSet
- Defined in:
- lib/capybara/selector/filter_set.rb
Instance Attribute Summary collapse
-
#expression_filters ⇒ Object
readonly
Returns the value of attribute expression_filters.
-
#node_filters ⇒ Object
readonly
Returns the value of attribute node_filters.
Class Method Summary collapse
Instance Method Summary collapse
- #describe(what = nil, &block) ⇒ Object
- #description(node_filters: true, expression_filters: true, **options) ⇒ Object
- #descriptions ⇒ Object
- #expression_filter(name, *types_and_options, &block) ⇒ Object
- #import(name, filters = nil) ⇒ Object
-
#initialize(name, &block) ⇒ FilterSet
constructor
A new instance of FilterSet.
- #node_filter(name, *types_and_options, &block) ⇒ Object (also: #filter)
Constructor Details
#initialize(name, &block) ⇒ FilterSet
Returns a new instance of FilterSet.
10 11 12 13 14 15 16 |
# File 'lib/capybara/selector/filter_set.rb', line 10 def initialize(name, &block) @name = name @node_filters = {} @expression_filters = {} @descriptions = Hash.new { |hsh, key| hsh[key] = [] } instance_eval(&block) end |
Instance Attribute Details
#expression_filters ⇒ Object (readonly)
Returns the value of attribute expression_filters.
8 9 10 |
# File 'lib/capybara/selector/filter_set.rb', line 8 def expression_filters @expression_filters end |
#node_filters ⇒ Object (readonly)
Returns the value of attribute node_filters.
8 9 10 |
# File 'lib/capybara/selector/filter_set.rb', line 8 def node_filters @node_filters end |
Class Method Details
.[](name) ⇒ Object
72 73 74 |
# File 'lib/capybara/selector/filter_set.rb', line 72 def [](name) all.fetch(name.to_sym) { |set_name| raise ArgumentError, "Unknown filter set (:#{set_name})" } end |
.add(name, &block) ⇒ Object
76 77 78 |
# File 'lib/capybara/selector/filter_set.rb', line 76 def add(name, &block) all[name.to_sym] = FilterSet.new(name.to_sym, &block) end |
.all ⇒ Object
68 69 70 |
# File 'lib/capybara/selector/filter_set.rb', line 68 def all @filter_sets ||= {} # rubocop:disable Naming/MemoizedInstanceVariableName end |
.remove(name) ⇒ Object
80 81 82 |
# File 'lib/capybara/selector/filter_set.rb', line 80 def remove(name) all.delete(name.to_sym) end |
Instance Method Details
#describe(what = nil, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/capybara/selector/filter_set.rb', line 27 def describe(what = nil, &block) case what when nil undeclared_descriptions.push block when :node_filters node_filter_descriptions.push block when :expression_filters expression_filter_descriptions.push block else raise ArgumentError, 'Unknown description type' end end |
#description(node_filters: true, expression_filters: true, **options) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/capybara/selector/filter_set.rb', line 40 def description(node_filters: true, expression_filters: true, **) opts = () description = +'' description << undeclared_descriptions.map { |desc| desc.call(opts).to_s }.join description << expression_filter_descriptions.map { |desc| desc.call(opts).to_s }.join if expression_filters description << node_filter_descriptions.map { |desc| desc.call(opts).to_s }.join if node_filters description end |
#descriptions ⇒ Object
49 50 51 52 |
# File 'lib/capybara/selector/filter_set.rb', line 49 def descriptions warn 'DEPRECATED: FilterSet#descriptions is deprecated without replacement' [undeclared_descriptions, node_filter_descriptions, expression_filter_descriptions].flatten end |
#expression_filter(name, *types_and_options, &block) ⇒ Object
23 24 25 |
# File 'lib/capybara/selector/filter_set.rb', line 23 def expression_filter(name, *, &block) add_filter(name, Filters::ExpressionFilter, *, &block) end |
#import(name, filters = nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/capybara/selector/filter_set.rb', line 54 def import(name, filters = nil) filter_selector = filters.nil? ? ->(*) { true } : ->(filter_name, _) { filters.include? filter_name } self.class[name].tap do |f_set| 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.expression_filter_descriptions.each { |desc| describe(:expression_filters, &desc) } f_set.node_filter_descriptions.each { |desc| describe(:node_filters, &desc) } end self end |
#node_filter(name, *types_and_options, &block) ⇒ Object Also known as: filter
18 19 20 |
# File 'lib/capybara/selector/filter_set.rb', line 18 def node_filter(name, *, &block) add_filter(name, Filters::NodeFilter, *, &block) end |