Sha256: 5f59127cb6d2c18f1218a942edc62f91c1d9992aaf7d25158fa5f57363b166cf

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

module RecordFilter
  module DSL
    class Conjunction

      attr_reader :type, :steps

      def initialize(model_class, type=:all_of)
        @model_class, @type, @steps = model_class, type, []
      end

      def add_restriction(column, value)
        @steps << (restriction = Restriction.new(column, value))
        restriction 
      end

      def add_conjunction(type, &block)
        dsl = ConjunctionDSL.new(@model_class, Conjunction.new(@model_class, type))
        dsl.instance_eval(&block) if block
        @steps << dsl.conjunction
      end

      def add_join(association, &block)
        dsl = ConjunctionDSL.new(@model_class, Conjunction.new(@model_class, :all_of))
        dsl.instance_eval(&block) if block
        @steps << Join.new(association, dsl.conjunction)
        dsl
      end

      def add_class_join(clazz, join_type, table_alias, &block)
        dsl = JoinDSL.new(@model_class, Conjunction.new(@model_class, :all_of))
        dsl.instance_eval(&block) if block
        @steps << ClassJoin.new(clazz, join_type, table_alias, dsl.conjunction, dsl.conditions)
        dsl
      end

      def add_limit(limit, offset)
        @steps << Limit.new(limit, offset)
      end

      def add_order(column, direction)
        @steps << Order.new(column, direction)
      end

      def add_group_by(column)
        @steps << GroupBy.new(column)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aub-record_filter-0.1.4 lib/record_filter/dsl/conjunction.rb