Sha256: 8166b52b715bc224de5edd7f6a846f545b98d0ed56d3974d3fca0e3356f080ac

Contents?: true

Size: 1.47 KB

Versions: 8

Compression:

Stored size: 1.47 KB

Contents

require 'pacer/filter/where_filter/node_visitor'
require 'jruby' # for JRuby.parse

module Pacer
  module Routes
    module RouteOperations
      def where(str, values = {}, *more, &block)
        if str.is_a? String or str.is_a? Symbol
          if str !~ /\A\s*\Z/
            chain_route :filter => :where, :where_statement => str.to_s, :values => values
          else
            self
          end
        else
          filter(str, values, *more, &block)
        end
      end

      def unless(str, values = {})
        if str and str !~ /\A\s*\Z/
          where "not (#{str})", values
        else
          self
        end
      end
    end
  end

  module Filter
    module WhereFilter
      attr_reader :where_statement
      attr_accessor :values

      def where_statement=(str)
        @where_statement = str
        @built = @parsed = @intermediate = nil
      end

      def parsed
        @parsed ||= JRuby.parse @where_statement
      end

      def intermediate
        encoded_values = {}
        if values
          values.each { |k, v| encoded_values[k.to_sym] = graph.encode_property(v) }
        end
        @intermediate ||= parsed.accept(NodeVisitor.new(self, encoded_values))
      end

      def build!
        @built ||= intermediate.build
      end

      protected

      def attach_pipe(end_pipe)
        pipe = build!
        pipe.setStarts end_pipe if end_pipe
        pipe
      end

      def inspect_string
        "where(#@where_statement)"
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pacer-1.3.1-java lib/pacer/filter/where_filter.rb
pacer-1.2.0-java lib/pacer/filter/where_filter.rb
pacer-1.1.1-java lib/pacer/filter/where_filter.rb
pacer-1.1.0-java lib/pacer/filter/where_filter.rb
pacer-1.0.3-java lib/pacer/filter/where_filter.rb
pacer-1.0.2-java lib/pacer/filter/where_filter.rb
pacer-1.0.1-java lib/pacer/filter/where_filter.rb
pacer-1.0.0-java lib/pacer/filter/where_filter.rb