sorted-mongoid 0.0.1
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +9 -0
- data/lib/sorted/mongoid.rb +10 -0
- data/lib/sorted/mongoid/railtie.rb +13 -0
- data/lib/sorted/mongoid/version.rb +5 -0
- data/lib/sorted/orms/mongoid.rb +19 -0
- data/sorted-mongoid.gemspec +27 -0
- data/spec/sorted/orms/mongoid_spec.rb +35 -0
- data/spec/spec_helper.rb +6 -0
- metadata +141 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Daniel Leavitt
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Sorted::Mongoid
|
2
|
+
|
3
|
+
Adds Mongoid support to [sorted](https://github.com/mynameisrufus/sorted). Allows you to sort large (Mongoid) datasets over many pages, without losing state.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'sorted-mongoid'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Just like sorted, hopefully! Include it in your Gemfile and all your Mongoid models should have the `sorted` method, eg:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
@users = User.sorted(params[:sort], "email ASC").page(params[:page])
|
21
|
+
```
|
22
|
+
|
23
|
+
Use SQL ordering keywords, even though we're not in SQLLand anymore.
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'sorted'
|
2
|
+
|
3
|
+
module Sorted
|
4
|
+
module Mongoid
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
initializer "sorted-mongoid.configure" do |app|
|
7
|
+
require 'sorted/orms/mongoid'
|
8
|
+
::Mongoid::Criteria.send :include, Sorted::Orms::Mongoid
|
9
|
+
::Mongoid::Document.send :include, Sorted::Orms::Mongoid
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'mongoid'
|
2
|
+
require 'sorted'
|
3
|
+
require 'active_support/concern'
|
4
|
+
|
5
|
+
module Sorted
|
6
|
+
module Orms
|
7
|
+
module Mongoid
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
SQL_TO_MONGO = { "asc" => 1, "desc" => -1 }
|
10
|
+
|
11
|
+
included do
|
12
|
+
def self.sorted(sort, default_order = nil)
|
13
|
+
sorter = ::Sorted::Parser.new(sort, default_order)
|
14
|
+
order_by sorter.to_hash.merge(sorter) { |key, val| SQL_TO_MONGO[val] }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sorted/mongoid/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sorted-mongoid"
|
8
|
+
spec.version = Sorted::Mongoid::VERSION
|
9
|
+
spec.authors = ["Daniel Leavitt"]
|
10
|
+
spec.email = ["daniel.leavitt@gmail.com"]
|
11
|
+
spec.summary = %q{Adds Mongoid support to sorted.}
|
12
|
+
spec.description = %q{Adds Mongoid support to [sorted](https://github.com/mynameisrufus/sorted). Allows you to sort large (Mongoid) datasets over many pages, without losing state.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rspec", ">= 2.0.0"
|
23
|
+
|
24
|
+
spec.add_dependency 'activesupport', '>= 3.0.0'
|
25
|
+
spec.add_dependency "sorted", "~> 0.4.3"
|
26
|
+
spec.add_dependency "mongoid", ">= 3.0"
|
27
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
Mongoid.configure do |config|
|
4
|
+
config.sessions = {:default => {:hosts => ['localhost:27017'], :database => 'kaminari_test'}}
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Sorted::Orms::Mongoid do
|
8
|
+
::Mongoid::Criteria.send :include, Sorted::Orms::Mongoid
|
9
|
+
::Mongoid::Document.send :include, Sorted::Orms::Mongoid
|
10
|
+
|
11
|
+
class SortedMongoidTest
|
12
|
+
include ::Mongoid::Document
|
13
|
+
|
14
|
+
field :name, :type => String
|
15
|
+
|
16
|
+
def self.page
|
17
|
+
limit(50)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should integrate with Mongoid::Document" do
|
22
|
+
SortedMongoidTest.should respond_to(:sorted)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should integrate with Mongoid::Criteria" do
|
26
|
+
SortedMongoidTest.page.should respond_to(:sorted)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should play nice with other scopes" do
|
30
|
+
query_options = {:limit=>50, :sort=>{"name"=>1}}
|
31
|
+
SortedMongoidTest.page.sorted(nil, 'name ASC').options.should == query_options
|
32
|
+
|
33
|
+
SortedMongoidTest.page.sorted(nil, 'name ASC').options.should == query_options
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sorted-mongoid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Daniel Leavitt
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.0.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.0.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: activesupport
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.0.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: sorted
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.4.3
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.4.3
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: mongoid
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '3.0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '3.0'
|
94
|
+
description: Adds Mongoid support to [sorted](https://github.com/mynameisrufus/sorted).
|
95
|
+
Allows you to sort large (Mongoid) datasets over many pages, without losing state.
|
96
|
+
email:
|
97
|
+
- daniel.leavitt@gmail.com
|
98
|
+
executables: []
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- lib/sorted/mongoid.rb
|
108
|
+
- lib/sorted/mongoid/railtie.rb
|
109
|
+
- lib/sorted/mongoid/version.rb
|
110
|
+
- lib/sorted/orms/mongoid.rb
|
111
|
+
- sorted-mongoid.gemspec
|
112
|
+
- spec/sorted/orms/mongoid_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
homepage: ''
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 1.8.23
|
136
|
+
signing_key:
|
137
|
+
specification_version: 3
|
138
|
+
summary: Adds Mongoid support to sorted.
|
139
|
+
test_files:
|
140
|
+
- spec/sorted/orms/mongoid_spec.rb
|
141
|
+
- spec/spec_helper.rb
|