Sha256: ba72d842cf270e31ca0c1a6bfe314ab79d39f3ea6ea181142db05af2fa276cd9

Contents?: true

Size: 814 Bytes

Versions: 1

Compression:

Stored size: 814 Bytes

Contents

module FilterParam
  class Operator
    class << self
      def type
        return :unary if method(:sql).arity == 1

        :binary
      end

      def operator_tag(operator_tag)
        @operator_tag ||= operator_tag
      end

      def register(operator_clazz)
        operator_tag = operator_clazz.tag
        registry[operator_tag] = operator_clazz
      end

      def tag
        @operator_tag
      end

      def for(operator_tag)
        registry[operator_tag]
      end

      def binaries
        with_type(:binary).map(&:tag)
      end

      def unaries
        with_type(:unary).map(&:tag)
      end

      private

      def with_type(type)
        registry.values.select { |op| op < self && op.type == type }
      end

      def registry
        @@registry ||= {}
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
filter_param-0.1.2 lib/filter_param/operator.rb