order_query 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -19
- data/README.md +21 -17
- data/Rakefile +29 -0
- data/lib/order_query.rb +11 -16
- data/lib/order_query/column.rb +1 -1
- data/lib/order_query/direction.rb +3 -7
- data/lib/order_query/point.rb +2 -6
- data/lib/order_query/space.rb +1 -2
- data/lib/order_query/version.rb +1 -1
- data/spec/gemfiles/rails_4.gemfile +9 -0
- data/spec/gemfiles/rails_4.gemfile.lock +73 -0
- data/spec/gemfiles/rails_5.gemfile +8 -0
- data/spec/gemfiles/rails_5.gemfile.lock +76 -0
- data/spec/order_query_spec.rb +39 -10
- metadata +29 -9
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2139f5b59c57d0163c85a86b23b79a3e6fd00a28
         | 
| 4 | 
            +
              data.tar.gz: e879b1b335c61133b122c014e49b01acb83c907d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: a8c33923361af77ea70eaf89eed9486122ff82e70ebcb8dae13d8ee273155e0075a0207e59a7dc276a9d335548830b6a768db1575cc657e2d64c3ad58cbade63
         | 
| 7 | 
            +
              data.tar.gz: a42483806ef779802cf97467ebd53fa95e2e97639ce709e51564320ae184e09274a6aaa001f5c7a4414897e4c6918816d5b680466fd6b784c2384bc288167272
         | 
    
        data/Gemfile
    CHANGED
    
    | @@ -2,22 +2,4 @@ source 'https://rubygems.org' | |
| 2 2 |  | 
| 3 3 | 
             
            gemspec
         | 
| 4 4 |  | 
| 5 | 
            -
             | 
| 6 | 
            -
              gem 'codeclimate-test-reporter', group: :test, require: nil
         | 
| 7 | 
            -
              gem 'byebug', platform: :mri_21, require: false
         | 
| 8 | 
            -
            end
         | 
| 9 | 
            -
             | 
| 10 | 
            -
            platform :mri, :rbx do
         | 
| 11 | 
            -
              # version locked because of rbx issue, see https://github.com/travis-ci/travis-ci/issues/2006#issuecomment-36275141
         | 
| 12 | 
            -
              gem 'sqlite3', '=1.3.8'
         | 
| 13 | 
            -
            end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
            platform :jruby do
         | 
| 16 | 
            -
              gem 'activerecord-jdbcsqlite3-adapter'
         | 
| 17 | 
            -
            end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
            platform :rbx do
         | 
| 20 | 
            -
              gem 'rubysl-singleton', '~> 2.0'
         | 
| 21 | 
            -
              gem 'rubysl-optparse', '~> 2.0'
         | 
| 22 | 
            -
              gem 'rubysl-ostruct', '~> 2.0'
         | 
| 23 | 
            -
            end
         | 
| 5 | 
            +
            eval_gemfile './shared.gemfile'
         | 
    
        data/README.md
    CHANGED
    
    | @@ -4,44 +4,42 @@ | |
| 4 4 | 
             
              <img src="http://use-the-index-luke.com/img/no-offset.q200.png" alt="100% offset-free" align="right" width="106" height="106">
         | 
| 5 5 | 
             
            </a>
         | 
| 6 6 |  | 
| 7 | 
            -
            This gem finds the next or previous record(s) relative to the current one efficiently | 
| 8 | 
            -
            It uses [keyset pagination](http://use-the-index-luke.com/no-offset) to achieve this.
         | 
| 7 | 
            +
            This gem finds the next or previous record(s) relative to the current one efficiently using [keyset pagination](http://use-the-index-luke.com/no-offset), e.g. for navigation or infinite scroll.
         | 
| 9 8 |  | 
| 10 9 | 
             
            ## Installation
         | 
| 11 10 |  | 
| 12 11 | 
             
            Add to Gemfile:
         | 
| 13 12 |  | 
| 14 13 | 
             
            ```ruby
         | 
| 15 | 
            -
            gem 'order_query', '~> 0.3. | 
| 14 | 
            +
            gem 'order_query', '~> 0.3.3'
         | 
| 16 15 | 
             
            ```
         | 
| 17 16 |  | 
| 18 17 | 
             
            ## Usage
         | 
| 19 18 |  | 
| 20 | 
            -
            Define named order  | 
| 19 | 
            +
            Define a named list of attributes to order by with `order_query(name, *order)`:
         | 
| 21 20 |  | 
| 22 21 | 
             
            ```ruby
         | 
| 23 22 | 
             
            class Post < ActiveRecord::Base
         | 
| 24 23 | 
             
              include OrderQuery
         | 
| 25 24 | 
             
              order_query :order_home,
         | 
| 26 25 | 
             
                [:pinned, [true, false]],
         | 
| 27 | 
            -
                [:published_at, :desc] | 
| 28 | 
            -
                [:id, :desc]
         | 
| 26 | 
            +
                [:published_at, :desc]
         | 
| 29 27 | 
             
            end
         | 
| 30 28 | 
             
            ```
         | 
| 31 29 |  | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
            ```ruby
         | 
| 35 | 
            -
            [<attribute name>, (attribute values in order), (:asc or :desc), (options hash)]
         | 
| 36 | 
            -
            ```
         | 
| 30 | 
            +
            Each attributes is specified as:
         | 
| 37 31 |  | 
| 38 | 
            -
             | 
| 32 | 
            +
            1. Attribute name.
         | 
| 33 | 
            +
            2. Optionally, values to order by, such as `%w(high medium low)` or `[true, false]`.
         | 
| 34 | 
            +
            3. Sort direction, `:asc` or `:desc`. Default: `:asc`; `:desc` when values to order by are specified.
         | 
| 35 | 
            +
            4. Options:
         | 
| 39 36 |  | 
| 40 37 | 
             
            | option     | description                                                                |
         | 
| 41 38 | 
             
            |------------|----------------------------------------------------------------------------|
         | 
| 42 39 | 
             
            | unique     | Unique attribute. Default: `true` for primary key, `false` otherwise.      |
         | 
| 43 | 
            -
            | sql        | Customize  | 
| 40 | 
            +
            | sql        | Customize column SQL.                                                      |
         | 
| 44 41 |  | 
| 42 | 
            +
            If no unique column is specified, `[primary_key, :asc]` is used. Unique column must be last.
         | 
| 45 43 |  | 
| 46 44 | 
             
            ### Scopes for `ORDER BY`
         | 
| 47 45 |  | 
| @@ -68,7 +66,7 @@ p.next     #=> #<Post> | |
| 68 66 | 
             
            p.position #=> 5
         | 
| 69 67 | 
             
            ```
         | 
| 70 68 |  | 
| 71 | 
            -
            Looping to the first / last record is enabled by default. Pass `false` to disable:
         | 
| 69 | 
            +
            Looping to the first / last record is enabled for `next` / `previous` by default. Pass `false` to disable:
         | 
| 72 70 |  | 
| 73 71 | 
             
            ```ruby
         | 
| 74 72 | 
             
            p = Post.order_home_at(Post.order_home.first)
         | 
| @@ -88,7 +86,7 @@ post.order_home(posts) #=> #<OrderQuery::Point> | |
| 88 86 |  | 
| 89 87 | 
             
            ### Dynamic columns
         | 
| 90 88 |  | 
| 91 | 
            -
            Query with dynamic order columns using the `seek(* | 
| 89 | 
            +
            Query with dynamic order columns using the `seek(*order)` class method:
         | 
| 92 90 |  | 
| 93 91 | 
             
            ```ruby
         | 
| 94 92 | 
             
            space = Post.visible.seek([:id, :desc]) #=> #<OrderQuery::Space>
         | 
| @@ -104,7 +102,13 @@ space.last            #=> scope_reverse.first | |
| 104 102 | 
             
            space.at(Post.first)  #=> #<OrderQuery::Point>
         | 
| 105 103 | 
             
            ```
         | 
| 106 104 |  | 
| 107 | 
            -
             | 
| 105 | 
            +
            `OrderQuery::Space` is also available for defined order_queries:
         | 
| 106 | 
            +
             | 
| 107 | 
            +
            ```ruby
         | 
| 108 | 
            +
            Post.visible.order_home_space #=> #<OrderQuery::Space>
         | 
| 109 | 
            +
            ```
         | 
| 110 | 
            +
             | 
| 111 | 
            +
            Alternatively, get an `OrderQuery::Point` using the `seek(scope, *order)` instance method:
         | 
| 108 112 |  | 
| 109 113 | 
             
            ```ruby
         | 
| 110 114 | 
             
            Post.find(42).seek(Post.visible, [:id, :desc]) #=> #<OrderQuery::Point>
         | 
| @@ -112,7 +116,7 @@ Post.find(42).seek(Post.visible, [:id, :desc]) #=> #<OrderQuery::Point> | |
| 112 116 | 
             
            Post.find(42).seek([:id, :desc]) #=> #<OrderQuery::Point>
         | 
| 113 117 | 
             
            ```
         | 
| 114 118 |  | 
| 115 | 
            -
             | 
| 119 | 
            +
            ### Advanced example
         | 
| 116 120 |  | 
| 117 121 | 
             
            ```ruby
         | 
| 118 122 | 
             
            class Post < ActiveRecord::Base
         | 
    
        data/Rakefile
    CHANGED
    
    | @@ -8,3 +8,32 @@ require 'rspec/core/rake_task' | |
| 8 8 | 
             
            RSpec::Core::RakeTask.new(:spec)
         | 
| 9 9 |  | 
| 10 10 | 
             
            task default: :spec
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            desc 'Test all Gemfiles from spec/*.gemfile'
         | 
| 13 | 
            +
            task :test_all_gemfiles do
         | 
| 14 | 
            +
              require 'pty'
         | 
| 15 | 
            +
              require 'shellwords'
         | 
| 16 | 
            +
              cmd      = 'bundle --quiet && bundle exec rake --trace'
         | 
| 17 | 
            +
              statuses = Dir.glob('./spec/gemfiles/*{[!.lock]}').map do |gemfile|
         | 
| 18 | 
            +
                env = {'BUNDLE_GEMFILE' => gemfile}
         | 
| 19 | 
            +
                cmd_with_env = "  (#{env.map { |k, v| "export #{k}=#{Shellwords.escape v}" } * ' '}; #{cmd})"
         | 
| 20 | 
            +
                $stderr.puts "Testing\n#{cmd_with_env}"
         | 
| 21 | 
            +
                PTY.spawn(env, cmd) do |r, _w, pid|
         | 
| 22 | 
            +
                  begin
         | 
| 23 | 
            +
                    r.each_line { |l| puts l }
         | 
| 24 | 
            +
                  rescue Errno::EIO
         | 
| 25 | 
            +
                    # Errno:EIO error means that the process has finished giving output.
         | 
| 26 | 
            +
                  ensure
         | 
| 27 | 
            +
                    ::Process.wait pid
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
                [$? && $?.exitstatus == 0, cmd_with_env]
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
              failed_cmds = statuses.reject(&:first).map { |(_status, cmd_with_env)| cmd_with_env }
         | 
| 33 | 
            +
              if failed_cmds.empty?
         | 
| 34 | 
            +
                $stderr.puts '✓ Tests pass with all gemfiles'
         | 
| 35 | 
            +
              else
         | 
| 36 | 
            +
                $stderr.puts "❌ FAILING (#{failed_cmds.size} / #{statuses.size})\n#{failed_cmds * "\n"}"
         | 
| 37 | 
            +
                exit 1
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
            end
         | 
    
        data/lib/order_query.rb
    CHANGED
    
    | @@ -59,22 +59,17 @@ module OrderQuery | |
| 59 59 | 
             
                #   .order_home(scope)
         | 
| 60 60 | 
             
                #     #<OrderQuery::Point...>
         | 
| 61 61 | 
             
                def order_query(name, *spec)
         | 
| 62 | 
            -
                   | 
| 63 | 
            -
                   | 
| 64 | 
            -
                     | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
                   | 
| 73 | 
            -
                    send(space_method).at(record)
         | 
| 74 | 
            -
                  }
         | 
| 75 | 
            -
                  define_method(name) { |scope = nil|
         | 
| 76 | 
            -
                    (scope || self.class).send(space_method).at(self)
         | 
| 77 | 
            -
                  }
         | 
| 62 | 
            +
                  define_singleton_method(:"#{name}_space") { seek(*spec) }
         | 
| 63 | 
            +
                  class_eval <<-RUBY, __FILE__, __LINE__
         | 
| 64 | 
            +
                    scope :#{name}, -> { #{name}_space.scope }
         | 
| 65 | 
            +
                    scope :#{name}_reverse, -> { #{name}_space.scope_reverse }
         | 
| 66 | 
            +
                    def self.#{name}_at(record)
         | 
| 67 | 
            +
                      #{name}_space.at(record)
         | 
| 68 | 
            +
                    end
         | 
| 69 | 
            +
                    def #{name}(scope = self.class)
         | 
| 70 | 
            +
                      scope.#{name}_space.at(self)
         | 
| 71 | 
            +
                    end
         | 
| 72 | 
            +
                  RUBY
         | 
| 78 73 | 
             
                end
         | 
| 79 74 | 
             
              end
         | 
| 80 75 |  | 
    
        data/lib/order_query/column.rb
    CHANGED
    
    
| @@ -3,8 +3,7 @@ module OrderQuery | |
| 3 3 | 
             
              module Direction
         | 
| 4 4 | 
             
                extend self
         | 
| 5 5 |  | 
| 6 | 
            -
                DIRECTIONS | 
| 7 | 
            -
                DIRECTIONS_S = DIRECTIONS.map { |d| d.to_s.freeze }.freeze
         | 
| 6 | 
            +
                DIRECTIONS = [:asc, :desc].freeze
         | 
| 8 7 |  | 
| 9 8 | 
             
                def all
         | 
| 10 9 | 
             
                  DIRECTIONS
         | 
| @@ -20,11 +19,8 @@ module OrderQuery | |
| 20 19 | 
             
                # @raise [ArgumentError]
         | 
| 21 20 | 
             
                # @return [:asc, :desc]
         | 
| 22 21 | 
             
                def parse!(direction)
         | 
| 23 | 
            -
                  if  | 
| 24 | 
            -
                    direction | 
| 25 | 
            -
                  else
         | 
| 26 | 
            -
                    direction = direction.to_s.downcase
         | 
| 27 | 
            -
                    direction.to_sym if DIRECTIONS_S.include?(direction)
         | 
| 22 | 
            +
                  if all.include?(direction)
         | 
| 23 | 
            +
                    direction
         | 
| 28 24 | 
             
                  end or
         | 
| 29 25 | 
             
                      raise ArgumentError.new("sort direction must be in #{all.map(&:inspect).join(', ')}, is #{direction.inspect}")
         | 
| 30 26 | 
             
                end
         | 
    
        data/lib/order_query/point.rb
    CHANGED
    
    | @@ -26,7 +26,7 @@ module OrderQuery | |
| 26 26 | 
             
                  unless_record_eq before.first || (last if loop)
         | 
| 27 27 | 
             
                end
         | 
| 28 28 |  | 
| 29 | 
            -
                # @return [Integer]
         | 
| 29 | 
            +
                # @return [Integer] counting from 1
         | 
| 30 30 | 
             
                def position
         | 
| 31 31 | 
             
                  space.count - after.count
         | 
| 32 32 | 
             
                end
         | 
| @@ -50,11 +50,7 @@ module OrderQuery | |
| 50 50 | 
             
                          else
         | 
| 51 51 | 
             
                            space.scope_reverse
         | 
| 52 52 | 
             
                          end
         | 
| 53 | 
            -
                   | 
| 54 | 
            -
                    scope.where(query, *query_args)
         | 
| 55 | 
            -
                  else
         | 
| 56 | 
            -
                    scope
         | 
| 57 | 
            -
                  end
         | 
| 53 | 
            +
                  scope.where(query, *query_args)
         | 
| 58 54 | 
             
                end
         | 
| 59 55 |  | 
| 60 56 | 
             
                def value(cond)
         | 
    
        data/lib/order_query/space.rb
    CHANGED
    
    | @@ -5,6 +5,7 @@ module OrderQuery | |
| 5 5 | 
             
              class Space
         | 
| 6 6 | 
             
                # @return [Array<OrderQuery::Column>]
         | 
| 7 7 | 
             
                attr_reader :columns
         | 
| 8 | 
            +
                delegate :count, :empty?, to: :@base_scope
         | 
| 8 9 |  | 
| 9 10 | 
             
                # @param [ActiveRecord::Relation] base_scope
         | 
| 10 11 | 
             
                # @param [Array<Array<Symbol,String>>, OrderQuery::Spec] order_spec
         | 
| @@ -44,8 +45,6 @@ module OrderQuery | |
| 44 45 | 
             
                  scope_reverse.first
         | 
| 45 46 | 
             
                end
         | 
| 46 47 |  | 
| 47 | 
            -
                delegate :count, :empty?, to: :@base_scope
         | 
| 48 | 
            -
             | 
| 49 48 | 
             
                def inspect
         | 
| 50 49 | 
             
                  "#<OrderQuery::Space @columns=#{@columns.inspect} @base_scope=#{@base_scope.inspect}>"
         | 
| 51 50 | 
             
                end
         | 
    
        data/lib/order_query/version.rb
    CHANGED
    
    
| @@ -0,0 +1,73 @@ | |
| 1 | 
            +
            PATH
         | 
| 2 | 
            +
              remote: ../../
         | 
| 3 | 
            +
              specs:
         | 
| 4 | 
            +
                order_query (0.3.2)
         | 
| 5 | 
            +
                  activerecord (>= 4.0, < 6.0)
         | 
| 6 | 
            +
                  activesupport (>= 4.0, < 6.0)
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            GEM
         | 
| 9 | 
            +
              remote: https://rubygems.org/
         | 
| 10 | 
            +
              specs:
         | 
| 11 | 
            +
                activemodel (4.2.5)
         | 
| 12 | 
            +
                  activesupport (= 4.2.5)
         | 
| 13 | 
            +
                  builder (~> 3.1)
         | 
| 14 | 
            +
                activerecord (4.2.5)
         | 
| 15 | 
            +
                  activemodel (= 4.2.5)
         | 
| 16 | 
            +
                  activesupport (= 4.2.5)
         | 
| 17 | 
            +
                  arel (~> 6.0)
         | 
| 18 | 
            +
                activesupport (4.2.5)
         | 
| 19 | 
            +
                  i18n (~> 0.7)
         | 
| 20 | 
            +
                  json (~> 1.7, >= 1.7.7)
         | 
| 21 | 
            +
                  minitest (~> 5.1)
         | 
| 22 | 
            +
                  thread_safe (~> 0.3, >= 0.3.4)
         | 
| 23 | 
            +
                  tzinfo (~> 1.1)
         | 
| 24 | 
            +
                arel (6.0.3)
         | 
| 25 | 
            +
                builder (3.2.2)
         | 
| 26 | 
            +
                byebug (8.2.1)
         | 
| 27 | 
            +
                codeclimate-test-reporter (0.4.8)
         | 
| 28 | 
            +
                  simplecov (>= 0.7.1, < 1.0.0)
         | 
| 29 | 
            +
                diff-lcs (1.2.5)
         | 
| 30 | 
            +
                docile (1.1.5)
         | 
| 31 | 
            +
                i18n (0.7.0)
         | 
| 32 | 
            +
                json (1.8.3)
         | 
| 33 | 
            +
                minitest (5.8.3)
         | 
| 34 | 
            +
                rake (10.4.2)
         | 
| 35 | 
            +
                rspec (3.4.0)
         | 
| 36 | 
            +
                  rspec-core (~> 3.4.0)
         | 
| 37 | 
            +
                  rspec-expectations (~> 3.4.0)
         | 
| 38 | 
            +
                  rspec-mocks (~> 3.4.0)
         | 
| 39 | 
            +
                rspec-core (3.4.1)
         | 
| 40 | 
            +
                  rspec-support (~> 3.4.0)
         | 
| 41 | 
            +
                rspec-expectations (3.4.0)
         | 
| 42 | 
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 43 | 
            +
                  rspec-support (~> 3.4.0)
         | 
| 44 | 
            +
                rspec-mocks (3.4.0)
         | 
| 45 | 
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 46 | 
            +
                  rspec-support (~> 3.4.0)
         | 
| 47 | 
            +
                rspec-support (3.4.1)
         | 
| 48 | 
            +
                simplecov (0.11.1)
         | 
| 49 | 
            +
                  docile (~> 1.1.0)
         | 
| 50 | 
            +
                  json (~> 1.8)
         | 
| 51 | 
            +
                  simplecov-html (~> 0.10.0)
         | 
| 52 | 
            +
                simplecov-html (0.10.0)
         | 
| 53 | 
            +
                sqlite3 (1.3.11)
         | 
| 54 | 
            +
                thread_safe (0.3.5)
         | 
| 55 | 
            +
                tzinfo (1.2.2)
         | 
| 56 | 
            +
                  thread_safe (~> 0.1)
         | 
| 57 | 
            +
             | 
| 58 | 
            +
            PLATFORMS
         | 
| 59 | 
            +
              ruby
         | 
| 60 | 
            +
             | 
| 61 | 
            +
            DEPENDENCIES
         | 
| 62 | 
            +
              activerecord (~> 4.0)
         | 
| 63 | 
            +
              activerecord-jdbcsqlite3-adapter
         | 
| 64 | 
            +
              activesupport (~> 4.0)
         | 
| 65 | 
            +
              byebug
         | 
| 66 | 
            +
              codeclimate-test-reporter
         | 
| 67 | 
            +
              order_query!
         | 
| 68 | 
            +
              rake (~> 10.2)
         | 
| 69 | 
            +
              rspec (~> 3.4)
         | 
| 70 | 
            +
              sqlite3 (>= 1.3.11)
         | 
| 71 | 
            +
             | 
| 72 | 
            +
            BUNDLED WITH
         | 
| 73 | 
            +
               1.11.2
         | 
| @@ -0,0 +1,76 @@ | |
| 1 | 
            +
            PATH
         | 
| 2 | 
            +
              remote: ../../
         | 
| 3 | 
            +
              specs:
         | 
| 4 | 
            +
                order_query (0.3.2)
         | 
| 5 | 
            +
                  activerecord (>= 4.0, < 6.0)
         | 
| 6 | 
            +
                  activesupport (>= 4.0, < 6.0)
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            GEM
         | 
| 9 | 
            +
              remote: https://rubygems.org/
         | 
| 10 | 
            +
              specs:
         | 
| 11 | 
            +
                activemodel (5.0.0.beta1)
         | 
| 12 | 
            +
                  activesupport (= 5.0.0.beta1)
         | 
| 13 | 
            +
                  builder (~> 3.1)
         | 
| 14 | 
            +
                activerecord (5.0.0.beta1)
         | 
| 15 | 
            +
                  activemodel (= 5.0.0.beta1)
         | 
| 16 | 
            +
                  activesupport (= 5.0.0.beta1)
         | 
| 17 | 
            +
                  arel (~> 7.0)
         | 
| 18 | 
            +
                activesupport (5.0.0.beta1)
         | 
| 19 | 
            +
                  concurrent-ruby (~> 1.0)
         | 
| 20 | 
            +
                  i18n (~> 0.7)
         | 
| 21 | 
            +
                  json (~> 1.7, >= 1.7.7)
         | 
| 22 | 
            +
                  method_source
         | 
| 23 | 
            +
                  minitest (~> 5.1)
         | 
| 24 | 
            +
                  tzinfo (~> 1.1)
         | 
| 25 | 
            +
                arel (7.0.0)
         | 
| 26 | 
            +
                builder (3.2.2)
         | 
| 27 | 
            +
                byebug (8.2.1)
         | 
| 28 | 
            +
                codeclimate-test-reporter (0.4.8)
         | 
| 29 | 
            +
                  simplecov (>= 0.7.1, < 1.0.0)
         | 
| 30 | 
            +
                concurrent-ruby (1.0.0)
         | 
| 31 | 
            +
                diff-lcs (1.2.5)
         | 
| 32 | 
            +
                docile (1.1.5)
         | 
| 33 | 
            +
                i18n (0.7.0)
         | 
| 34 | 
            +
                json (1.8.3)
         | 
| 35 | 
            +
                method_source (0.8.2)
         | 
| 36 | 
            +
                minitest (5.8.3)
         | 
| 37 | 
            +
                rake (10.4.2)
         | 
| 38 | 
            +
                rspec (3.4.0)
         | 
| 39 | 
            +
                  rspec-core (~> 3.4.0)
         | 
| 40 | 
            +
                  rspec-expectations (~> 3.4.0)
         | 
| 41 | 
            +
                  rspec-mocks (~> 3.4.0)
         | 
| 42 | 
            +
                rspec-core (3.4.1)
         | 
| 43 | 
            +
                  rspec-support (~> 3.4.0)
         | 
| 44 | 
            +
                rspec-expectations (3.4.0)
         | 
| 45 | 
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 46 | 
            +
                  rspec-support (~> 3.4.0)
         | 
| 47 | 
            +
                rspec-mocks (3.4.0)
         | 
| 48 | 
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 49 | 
            +
                  rspec-support (~> 3.4.0)
         | 
| 50 | 
            +
                rspec-support (3.4.1)
         | 
| 51 | 
            +
                simplecov (0.11.1)
         | 
| 52 | 
            +
                  docile (~> 1.1.0)
         | 
| 53 | 
            +
                  json (~> 1.8)
         | 
| 54 | 
            +
                  simplecov-html (~> 0.10.0)
         | 
| 55 | 
            +
                simplecov-html (0.10.0)
         | 
| 56 | 
            +
                sqlite3 (1.3.11)
         | 
| 57 | 
            +
                thread_safe (0.3.5)
         | 
| 58 | 
            +
                tzinfo (1.2.2)
         | 
| 59 | 
            +
                  thread_safe (~> 0.1)
         | 
| 60 | 
            +
             | 
| 61 | 
            +
            PLATFORMS
         | 
| 62 | 
            +
              ruby
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            DEPENDENCIES
         | 
| 65 | 
            +
              activerecord (= 5.0.0.beta1)
         | 
| 66 | 
            +
              activerecord-jdbcsqlite3-adapter
         | 
| 67 | 
            +
              activesupport (= 5.0.0.beta1)
         | 
| 68 | 
            +
              byebug
         | 
| 69 | 
            +
              codeclimate-test-reporter
         | 
| 70 | 
            +
              order_query!
         | 
| 71 | 
            +
              rake (~> 10.2)
         | 
| 72 | 
            +
              rspec (~> 3.4)
         | 
| 73 | 
            +
              sqlite3 (>= 1.3.11)
         | 
| 74 | 
            +
             | 
| 75 | 
            +
            BUNDLED WITH
         | 
| 76 | 
            +
               1.11.2
         | 
    
        data/spec/order_query_spec.rb
    CHANGED
    
    | @@ -92,14 +92,15 @@ describe 'OrderQuery' do | |
| 92 92 | 
             
                        end
         | 
| 93 93 | 
             
                        issues.shuffle.reverse_each(&:save!)
         | 
| 94 94 | 
             
                        expect(Issue.display_order.to_a).to eq(issues)
         | 
| 95 | 
            -
                        issues. | 
| 96 | 
            -
             | 
| 97 | 
            -
                          expect( | 
| 98 | 
            -
                          expect(cur.display_order. | 
| 95 | 
            +
                        expect(Issue.display_order_reverse.to_a).to eq(issues.reverse)
         | 
| 96 | 
            +
                        issues.zip(issues.rotate).each_with_index do |(cur, nxt), i|
         | 
| 97 | 
            +
                          expect(cur.display_order.position).to eq(i + 1)
         | 
| 98 | 
            +
                          expect(cur.display_order.next).to eq(nxt)
         | 
| 99 | 
            +
                          expect(Issue.display_order_at(cur).next).to eq nxt
         | 
| 99 100 | 
             
                          expect(cur.display_order.space.count).to eq(Issue.count)
         | 
| 100 | 
            -
                          expect(cur.display_order.before.count + 1 + cur.display_order.after.count).to eq( | 
| 101 | 
            -
             | 
| 102 | 
            -
                          expect( | 
| 101 | 
            +
                          expect(cur.display_order.before.count + 1 + cur.display_order.after.count).to eq(nxt.display_order.count)
         | 
| 102 | 
            +
                          expect(nxt.display_order.previous).to eq(cur)
         | 
| 103 | 
            +
                          expect(nxt.display_order.before.to_a.reverse + [nxt] + nxt.display_order.after.to_a).to eq(Issue.display_order.to_a)
         | 
| 103 104 | 
             
                        end
         | 
| 104 105 | 
             
                      end
         | 
| 105 106 | 
             
                    end
         | 
| @@ -122,8 +123,10 @@ describe 'OrderQuery' do | |
| 122 123 |  | 
| 123 124 | 
             
                    it '.seek works on a list of ids' do
         | 
| 124 125 | 
             
                      ids = 3.times.map { create_issue.id }
         | 
| 125 | 
            -
                      expect(Issue.seek([[:id, ids]]). | 
| 126 | 
            -
                      expect(Issue.seek([:id, ids]). | 
| 126 | 
            +
                      expect(Issue.seek([[:id, ids]]).count).to eq ids.length
         | 
| 127 | 
            +
                      expect(Issue.seek([:id, ids]).count).to eq ids.length
         | 
| 128 | 
            +
                      expect(Issue.seek([:id, ids]).scope.pluck(:id)).to eq ids
         | 
| 129 | 
            +
                      expect(Issue.seek([:id, ids]).scope_reverse.pluck(:id)).to eq ids.reverse
         | 
| 127 130 | 
             
                    end
         | 
| 128 131 |  | 
| 129 132 | 
             
                    context 'partitioned on a boolean flag' do
         | 
| @@ -138,10 +141,12 @@ describe 'OrderQuery' do | |
| 138 141 | 
             
                      let!(:inactive) { Issue.where(active: false).seek(order) }
         | 
| 139 142 |  | 
| 140 143 | 
             
                      it '.seek preserves scope' do
         | 
| 141 | 
            -
                        expect(inactive.scope.count).to eq 1
         | 
| 142 144 | 
             
                        expect(inactive.count).to eq 1
         | 
| 145 | 
            +
                        expect(inactive.scope.count).to eq 1
         | 
| 146 | 
            +
                        expect(inactive.scope_reverse.count).to eq 1
         | 
| 143 147 | 
             
                        expect(active.count).to eq 2
         | 
| 144 148 | 
             
                        expect(active.scope.count).to eq 2
         | 
| 149 | 
            +
                        expect(active.scope_reverse.count).to eq 2
         | 
| 145 150 | 
             
                      end
         | 
| 146 151 |  | 
| 147 152 | 
             
                      it 'gives a valid result if at argument is outside of the space' do
         | 
| @@ -210,6 +215,30 @@ describe 'OrderQuery' do | |
| 210 215 | 
             
                      expect(o2.next(true)).to eq(p1)
         | 
| 211 216 | 
             
                    end
         | 
| 212 217 |  | 
| 218 | 
            +
                    context '#inspect' do
         | 
| 219 | 
            +
                      it 'Column' do
         | 
| 220 | 
            +
                        expect(OrderQuery::Column.new([:id, :desc], Post).inspect).to eq '(id unique desc)'
         | 
| 221 | 
            +
                        expect(OrderQuery::Column.new([:virtual, :desc, sql: 'SIN(id)'], Post).inspect).to eq '(virtual SIN(id) desc)'
         | 
| 222 | 
            +
                      end
         | 
| 223 | 
            +
             | 
| 224 | 
            +
                      let(:space) {
         | 
| 225 | 
            +
                        OrderQuery::Space.new(Post, [[:pinned, [true, false]]])
         | 
| 226 | 
            +
                      }
         | 
| 227 | 
            +
             | 
| 228 | 
            +
                      it 'Point' do
         | 
| 229 | 
            +
                        post  = create_post
         | 
| 230 | 
            +
                        point = OrderQuery::Point.new(post, space)
         | 
| 231 | 
            +
                        expect(point.inspect).to(
         | 
| 232 | 
            +
                            eq %Q(#<OrderQuery::Point @record=#<Post id: #{post.id}, pinned: false, published_at: #{post.attribute_for_inspect(:published_at)}> @space=#<OrderQuery::Space @columns=[(pinned [true, false] desc), (id unique asc)] @base_scope=Post(id: integer, pinned: boolean, published_at: datetime)>>)
         | 
| 233 | 
            +
                        )
         | 
| 234 | 
            +
                      end
         | 
| 235 | 
            +
             | 
| 236 | 
            +
                      it 'Space' do
         | 
| 237 | 
            +
                        expect(space.inspect).to eq '#<OrderQuery::Space @columns=[(pinned [true, false] desc), (id unique asc)] @base_scope=Post(id: integer, pinned: boolean, published_at: datetime)>'
         | 
| 238 | 
            +
                      end
         | 
| 239 | 
            +
                    end
         | 
| 240 | 
            +
             | 
| 241 | 
            +
             | 
| 213 242 | 
             
                    context 'boolean enum order' do
         | 
| 214 243 | 
             
                      before do
         | 
| 215 244 | 
             
                        create_post pinned: true
         | 
    
        metadata
    CHANGED
    
    | @@ -1,57 +1,69 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: order_query
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.3. | 
| 4 | 
            +
              version: 0.3.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Gleb Mazovetskiy
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2016-01-05 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activerecord
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 | 
            -
                - - " | 
| 17 | 
            +
                - - ">="
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 19 | 
             
                    version: '4.0'
         | 
| 20 | 
            +
                - - "<"
         | 
| 21 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 22 | 
            +
                    version: '6.0'
         | 
| 20 23 | 
             
              type: :runtime
         | 
| 21 24 | 
             
              prerelease: false
         | 
| 22 25 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 26 | 
             
                requirements:
         | 
| 24 | 
            -
                - - " | 
| 27 | 
            +
                - - ">="
         | 
| 25 28 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 29 | 
             
                    version: '4.0'
         | 
| 30 | 
            +
                - - "<"
         | 
| 31 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            +
                    version: '6.0'
         | 
| 27 33 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 34 | 
             
              name: activesupport
         | 
| 29 35 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 36 | 
             
                requirements:
         | 
| 31 | 
            -
                - - " | 
| 37 | 
            +
                - - ">="
         | 
| 32 38 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 39 | 
             
                    version: '4.0'
         | 
| 40 | 
            +
                - - "<"
         | 
| 41 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 42 | 
            +
                    version: '6.0'
         | 
| 34 43 | 
             
              type: :runtime
         | 
| 35 44 | 
             
              prerelease: false
         | 
| 36 45 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 46 | 
             
                requirements:
         | 
| 38 | 
            -
                - - " | 
| 47 | 
            +
                - - ">="
         | 
| 39 48 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 49 | 
             
                    version: '4.0'
         | 
| 50 | 
            +
                - - "<"
         | 
| 51 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 52 | 
            +
                    version: '6.0'
         | 
| 41 53 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 54 | 
             
              name: rspec
         | 
| 43 55 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 56 | 
             
                requirements:
         | 
| 45 57 | 
             
                - - "~>"
         | 
| 46 58 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            -
                    version: '3. | 
| 59 | 
            +
                    version: '3.4'
         | 
| 48 60 | 
             
              type: :development
         | 
| 49 61 | 
             
              prerelease: false
         | 
| 50 62 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 63 | 
             
                requirements:
         | 
| 52 64 | 
             
                - - "~>"
         | 
| 53 65 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            -
                    version: '3. | 
| 66 | 
            +
                    version: '3.4'
         | 
| 55 67 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 68 | 
             
              name: rake
         | 
| 57 69 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -86,6 +98,10 @@ files: | |
| 86 98 | 
             
            - lib/order_query/sql/order_by.rb
         | 
| 87 99 | 
             
            - lib/order_query/sql/where.rb
         | 
| 88 100 | 
             
            - lib/order_query/version.rb
         | 
| 101 | 
            +
            - spec/gemfiles/rails_4.gemfile
         | 
| 102 | 
            +
            - spec/gemfiles/rails_4.gemfile.lock
         | 
| 103 | 
            +
            - spec/gemfiles/rails_5.gemfile
         | 
| 104 | 
            +
            - spec/gemfiles/rails_5.gemfile.lock
         | 
| 89 105 | 
             
            - spec/order_query_spec.rb
         | 
| 90 106 | 
             
            - spec/spec_helper.rb
         | 
| 91 107 | 
             
            homepage: https://github.com/glebm/order_query
         | 
| @@ -109,10 +125,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 109 125 | 
             
                  version: '0'
         | 
| 110 126 | 
             
            requirements: []
         | 
| 111 127 | 
             
            rubyforge_project: 
         | 
| 112 | 
            -
            rubygems_version: 2. | 
| 128 | 
            +
            rubygems_version: 2.5.1
         | 
| 113 129 | 
             
            signing_key: 
         | 
| 114 130 | 
             
            specification_version: 4
         | 
| 115 131 | 
             
            summary: Find next / previous Active Record(s) in one query
         | 
| 116 132 | 
             
            test_files:
         | 
| 133 | 
            +
            - spec/gemfiles/rails_4.gemfile
         | 
| 134 | 
            +
            - spec/gemfiles/rails_4.gemfile.lock
         | 
| 135 | 
            +
            - spec/gemfiles/rails_5.gemfile
         | 
| 136 | 
            +
            - spec/gemfiles/rails_5.gemfile.lock
         | 
| 117 137 | 
             
            - spec/order_query_spec.rb
         | 
| 118 138 | 
             
            - spec/spec_helper.rb
         |