Sha256: 1f92fd3334af03d167ec6d14885cc63511d55788589414ff1784903e3a4594c1

Contents?: true

Size: 1.17 KB

Versions: 14

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module Grumlin
  module Expressions
    module P
      class << self
        class Predicate < TypedValue
          def initialize(name, args:, arg_type: nil)
            super(type: "P")
            @name = name
            @args = args
            @arg_type = arg_type
          end

          def value
            @value ||= {
              predicate: @name,
              value: TypedValue.new(type: @arg_type, value: @args).to_bytecode
            }
          end
        end

        # TODO: support more predicates
        %i[eq neq].each do |predicate|
          define_method predicate do |*args|
            Predicate.new(predicate, args: args[0])
          end
        end

        %i[within without].each do |predicate|
          define_method predicate do |*args|
            args = if args.count == 1 && args[0].is_a?(Array)
                     args[0]
                   elsif args.count == 1 && args[0].is_a?(Set)
                     args[0].to_a
                   else
                     args.to_a
                   end
            Predicate.new(predicate, args: args, arg_type: "List")
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
grumlin-0.15.6 lib/grumlin/expressions/p.rb
grumlin-0.15.4 lib/grumlin/expressions/p.rb
grumlin-0.15.3 lib/grumlin/expressions/p.rb
grumlin-0.15.2 lib/grumlin/expressions/p.rb
grumlin-0.15.1 lib/grumlin/expressions/p.rb
grumlin-0.15.0 lib/grumlin/expressions/p.rb
grumlin-0.14.5 lib/grumlin/expressions/p.rb
grumlin-0.14.4 lib/grumlin/expressions/p.rb
grumlin-0.14.3 lib/grumlin/expressions/p.rb
grumlin-0.14.2 lib/grumlin/expressions/p.rb
grumlin-0.14.1 lib/grumlin/expressions/p.rb
grumlin-0.14.0 lib/grumlin/expressions/p.rb
grumlin-0.13.1 lib/grumlin/expressions/p.rb
grumlin-0.13.0 lib/grumlin/expressions/p.rb