Class: Capybara::Selector::Filters::Base
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Inherits: | Object |
Defined in: | lib/capybara/selector/filters/base.rb |
Class Method Summary
- .new(name, matcher, block, **options) ⇒ Base constructor
Instance Attribute Summary
- #boolean? ⇒ Boolean readonly
- #default? ⇒ Boolean readonly
- #matcher? ⇒ Boolean readonly
Instance Method Summary
Constructor Details
.new(name, matcher, block, **options) ⇒ Base
# File 'lib/capybara/selector/filters/base.rb', line 7
def initialize(name, matcher, block, ** ) @name = name @matcher = matcher @block = block @options = @options[:valid_values] = [true, false] if [:boolean] end
Instance Attribute Details
#boolean? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/capybara/selector/filters/base.rb', line 35
def boolean? !!@options[:boolean] end
#default? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/capybara/selector/filters/base.rb', line 15
def default? @options.key?(:default) end
#matcher? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/capybara/selector/filters/base.rb', line 31
def matcher? !@matcher.nil? end
Instance Method Details
#apply(subject, name, value, skip_value, ctx) (private)
[ GitHub ]# File 'lib/capybara/selector/filters/base.rb', line 49
def apply(subject, name, value, skip_value, ctx) return skip_value if skip?(value) unless valid_value?(value) raise ArgumentError, "Invalid value #{value.inspect} passed to #{self.class.name.split('::').last} #{name}" \ "#{" : #{name}" if @name.is_a?(Regexp)}" end if @block.arity == 2 filter_context(ctx).instance_exec(subject, value, &@block) else filter_context(ctx).instance_exec(subject, name, value, &@block) end end
#default (readonly)
[ GitHub ]# File 'lib/capybara/selector/filters/base.rb', line 19
def default @options[:default] end
#filter_context(context) (private)
[ GitHub ]# File 'lib/capybara/selector/filters/base.rb', line 65
def filter_context(context) context || @block.binding.receiver end
#format
[ GitHub ]# File 'lib/capybara/selector/filters/base.rb', line 27
def format @options[:format] end
#handles_option?(option_name) ⇒ Boolean
# File 'lib/capybara/selector/filters/base.rb', line 39
def handles_option?(option_name) if matcher? @matcher.match? option_name else @name == option_name end end
#skip?(value) ⇒ Boolean
# File 'lib/capybara/selector/filters/base.rb', line 23
def skip?(value) @options.key?(:skip_if) && value == @options[:skip_if] end
#valid_value?(value) ⇒ Boolean
(private)
# File 'lib/capybara/selector/filters/base.rb', line 69
def valid_value?(value) return true unless @options.key?(:valid_values) Array(@options[:valid_values]).any? { |valid| valid === value } # rubocop:disable Style/CaseEquality end