Sha256: 8e6870bd57636fe7978ed1491c9287da0f9c4c8ab05137957d8ec96473493100

Contents?: true

Size: 573 Bytes

Versions: 8

Compression:

Stored size: 573 Bytes

Contents

# encoding: UTF-8

require 'forwardable'
require 'enumerator'

module ArelHelpers
  class QueryBuilder
    extend Forwardable
    include Enumerable

    attr_reader :query
    def_delegators :@query, :to_a, :to_sql, :each

    TERMINAL_METHODS = [:count, :first, :last]
    TERMINAL_METHODS << :pluck if ActiveRecord::VERSION::MAJOR >= 4

    def_delegators :@query, *TERMINAL_METHODS

    def initialize(query)
      @query = query
    end

    protected

    def reflect(query)
      dup.tap { |obj| obj.instance_variable_set('@query'.freeze, query) }
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
arel-helpers-2.10.0 lib/arel-helpers/query_builder.rb
arel-helpers-2.9.1 lib/arel-helpers/query_builder.rb
arel-helpers-2.9.0 lib/arel-helpers/query_builder.rb
arel-helpers-2.8.0 lib/arel-helpers/query_builder.rb
arel-helpers-2.7.0 lib/arel-helpers/query_builder.rb
arel-helpers-2.6.1 lib/arel-helpers/query_builder.rb
arel-helpers-2.6.0 lib/arel-helpers/query_builder.rb
arel-helpers-2.5.0 lib/arel-helpers/query_builder.rb