Sha256: e14730d2b9658ba76cecf244dc92c15ebfac208d8dc138f684df0bcadff32b53

Contents?: true

Size: 1.05 KB

Versions: 18

Compression:

Stored size: 1.05 KB

Contents

module Chewy
  class Query
    module Nodes
      class Regexp < Expr
        FLAGS = %w(all anystring automaton complement empty intersection interval none)

        def initialize name, regexp, *args
          @name = name.to_s
          @regexp = regexp.respond_to?(:source) ? regexp.source : regexp.to_s
          @options = args.extract_options!
          if args.any? || @options[:flags].present?
            @options[:flags] = FLAGS & (args.any? ? args.flatten : @options[:flags]).map(&:to_s).map(&:downcase)
          end
        end

        def __render__
          body = @options[:flags] ?
            {value: @regexp, flags: @options[:flags].map(&:to_s).map(&:upcase).uniq.join('|')} :
            @regexp
          filter = {@name => body}
          if @options.key?(:cache)
            filter[:_cache] = !!@options[:cache]
            filter[:_cache_key] = @options[:cache].is_a?(TrueClass) || @options[:cache].is_a?(FalseClass) ?
              @regexp.underscore : @options[:cache]
          end
          {regexp: filter}
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
chewy-0.8.3 lib/chewy/query/nodes/regexp.rb
chewy-0.8.2 lib/chewy/query/nodes/regexp.rb
chewy-0.8.1 lib/chewy/query/nodes/regexp.rb
chewy-0.8.0 lib/chewy/query/nodes/regexp.rb
chewy-0.7.0 lib/chewy/query/nodes/regexp.rb
chewy-0.6.2 lib/chewy/query/nodes/regexp.rb
chewy-0.6.1 lib/chewy/query/nodes/regexp.rb
chewy-0.6.0 lib/chewy/query/nodes/regexp.rb
chewy-0.5.2 lib/chewy/query/nodes/regexp.rb
chewy-0.5.1 lib/chewy/query/nodes/regexp.rb
chewy-0.5.0 lib/chewy/query/nodes/regexp.rb
chewy-0.4.1 lib/chewy/query/nodes/regexp.rb
chewy-0.4.0 lib/chewy/query/nodes/regexp.rb
chewy-0.3.0 lib/chewy/query/nodes/regexp.rb
chewy-0.2.4 lib/chewy/query/nodes/regexp.rb
chewy-0.2.2 lib/chewy/query/nodes/regexp.rb
chewy-0.2.0 lib/chewy/query/nodes/regexp.rb
chewy-0.1.0 lib/chewy/query/nodes/regexp.rb