1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

move Selector::Filter to its own file

This commit is contained in:
Thomas Walpole 2016-03-28 11:58:01 -07:00
parent 502bf11789
commit c44f50e68d
2 changed files with 50 additions and 37 deletions

View file

@ -1,43 +1,8 @@
# frozen_string_literal: true
require 'capybara/selector/filter'
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 @options.has_key?(:valid_values) && !Array(@options[:valid_values]).include?(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
end
attr_reader :name, :custom_filters, :format

View file

@ -0,0 +1,48 @@
# 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