Sha256: 0c4abbfd704430fe4ce78ec38ad50eeda36569a1c2b59088d9e6763039552ffc

Contents?: true

Size: 1.21 KB

Versions: 13

Compression:

Stored size: 1.21 KB

Contents

class Card
  module Query
    class AbstractQuery
      # shared methods for queries
      module QueryHelper
        def direct_subqueries
          subqueries_with_fasten :direct
        end

        def subqueries_with_fasten fasten
          list = []
          subqueries.each do |s|
            next unless Array.wrap(fasten).include? s.fasten
            list << s
            list += s.subqueries_with_fasten s.fasten
          end
          list
        end

        def table_alias
          @table_alias ||= begin
            if fasten == :direct
              @superquery.table_alias
            else
              "#{table_prefix}#{next_table_suffix}"
            end
          end
        end

        def next_table_suffix
          return root.next_table_suffix unless root?
          @table_suffix = (@table_suffix || -1) + 1
        end

        def fld field_name
          "#{table_alias}.#{field_name}"
        end

        def add_condition *args
          @conditions <<
            if args.size > 1
              [args.shift, Query::Value.new(args.shift, self)]
            else
              args[0]
            end
        end

        def current_conjunction
          "AND"
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
card-1.96.8 lib/card/query/abstract_query/query_helper.rb
card-1.96.7 lib/card/query/abstract_query/query_helper.rb
card-1.96.6 lib/card/query/abstract_query/query_helper.rb
card-1.96.5 lib/card/query/abstract_query/query_helper.rb
card-1.96.4 lib/card/query/abstract_query/query_helper.rb
card-1.96.3 lib/card/query/abstract_query/query_helper.rb
card-1.96.2 lib/card/query/abstract_query/query_helper.rb
card-1.96.1 lib/card/query/abstract_query/query_helper.rb
card-1.96.0 lib/card/query/abstract_query/query_helper.rb
card-1.95.3 lib/card/query/abstract_query/query_helper.rb
card-1.95.2 lib/card/query/abstract_query/query_helper.rb
card-1.95.1 lib/card/query/abstract_query/query_helper.rb
card-1.95.0 lib/card/query/abstract_query/query_helper.rb