Sha256: 17aebb246be77c84890ae37e96398c96a6b448cf2a46613dc51dbfaf4942e0e0

Contents?: true

Size: 778 Bytes

Versions: 1

Compression:

Stored size: 778 Bytes

Contents

module ActiveHouse
  module Querying
    module Limit
      extend ActiveSupport::Concern

      included do
        private :build_limit_query_part
      end

      def build_limit_query_part
        return if values[:limit].nil?
        if values[:offset]
          "LIMIT #{values[:limit]}, #{values[:offset]}"
        else
          "LIMIT #{values[:limit]}"
        end
      end

      def initial_values
        super.merge offset: nil, limit: nil
        super
      end

      def limit!(limit_value, offset_value = nil)
        values[:limit] = limit_value
        values[:offset] = offset_value unless offset_value.nil?
        self
      end

      def limit(limit_value, offset_value = nil)
        dup.limit!(limit_value, offset_value)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_house-0.5.0 lib/active_house/querying/limit.rb