Sha256: aa7b9109ec387199678cbff1db508b953e683c5be7ac5a46dc6ea024106de468

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

# encoding: utf-8

module QueryBuilder

  module CQL

    # The collection of statement modifiers
    #
    # Every modifier contains two methods:
    # * public method to add clause(s) to the statement
    # * private method to collect statement clause(s)
    #
    module Modifiers

      # Base class for modifier-provided clauses
      #
      class Base < Core::Clause

        include Operators

      end # class Base

      # The base class for clauses, describing conditions (like "foo = 'foo'")
      #
      # @api private
      #
      class BaseCondition < Base

        attribute :column, required: true
        attribute :value,  required: true

        # @private
        def to_s
          return operator  if value.respond_to?(:call)
          return inclusion if value.instance_of? Array
          equality
        end

        private

        def equality
          "#{column} = #{cql_literal[value]}"
        end

        def inclusion
          cql_in[column, *value]
        end

        def operator
          value[column]
        end

      end # class BaseCondition

      Dir[File.expand_path("../modifiers/*.rb", __FILE__)].each(&method(:load))

    end # module Modifiers

  end # module CQL

end # module QueryBuilder

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
query_builder-0.0.4 lib/query_builder/cql/modifiers.rb
query_builder-0.0.3 lib/query_builder/cql/modifiers.rb
query_builder-0.0.2 lib/query_builder/cql/modifiers.rb
query_builder-0.0.1 lib/query_builder/cql/modifiers.rb