Class: Chewy::Query::Nodes::Regexp
- Defined in:
- lib/chewy/query/nodes/regexp.rb
Constant Summary collapse
- FLAGS =
%w[all anystring automaton complement empty intersection interval none].freeze
Instance Method Summary collapse
- #__render__ ⇒ Object
-
#initialize(name, regexp, *args) ⇒ Regexp
constructor
A new instance of Regexp.
Methods inherited from Expr
Methods inherited from Base
Constructor Details
#initialize(name, regexp, *args) ⇒ Regexp
Returns a new instance of Regexp.
7 8 9 10 11 12 13 |
# File 'lib/chewy/query/nodes/regexp.rb', line 7 def initialize(name, regexp, *args) @name = name.to_s @regexp = regexp.respond_to?(:source) ? regexp.source : regexp.to_s @options = args. return if args.blank? && @options[:flags].blank? @options[:flags] = FLAGS & (args.present? ? args.flatten : @options[:flags]).map(&:to_s).map(&:downcase) end |
Instance Method Details
#__render__ ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/chewy/query/nodes/regexp.rb', line 15 def __render__ body = if @options[:flags] {value: @regexp, flags: @options[:flags].map(&:to_s).map(&:upcase).uniq.join('|')} else @regexp end filter = {@name => body} if @options.key?(:cache) filter[:_cache] = !!@options[:cache] filter[:_cache_key] = if @options[:cache].is_a?(TrueClass) || @options[:cache].is_a?(FalseClass) @regexp.underscore else @options[:cache] end end {regexp: filter} end |