Class: ChewyQuery::Builder::Nodes::Regexp
- Defined in:
- lib/chewy_query/builder/nodes/regexp.rb
Constant Summary collapse
- FLAGS =
%w(all anystring automaton complement empty intersection interval none)
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 14 15 |
# File 'lib/chewy_query/builder/nodes/regexp.rb', line 7 def initialize(name, regexp, *args) @name = name.to_s @regexp = regexp.respond_to?(:source) ? regexp.source : regexp.to_s = args. if args.any? || [:flags].present? [:flags] = FLAGS & (args.any? ? args.flatten : [:flags]).map(&:to_s).map(&:downcase) end end |
Instance Method Details
#__render__ ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/chewy_query/builder/nodes/regexp.rb', line 17 def __render__ body = [:flags] ? { value: @regexp, flags: [:flags].map(&:to_s).map(&:upcase).uniq.join('|') } : @regexp filter = { @name => body } if .key?(:cache) filter[:_cache] = !![:cache] filter[:_cache_key] = [:cache].is_a?(TrueClass) || [:cache].is_a?(FalseClass) ? @regexp.underscore : [:cache] end { regexp: filter } end |