dm-sorting 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/dm-sorting/sorting.rb +20 -0
- data/lib/dm-sorting/version.rb +15 -0
- data/lib/dm-sorting.rb +17 -0
- data/test/sorting_spec.rb +50 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 18499210662b546efa79f8f67d8ccc3cf37456d3
|
4
|
+
data.tar.gz: f052380d74ab3832b771ebf1f9df497569196f19
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e5b373faee2da07a97e3e35ad7a6e9b5b2c23bd932a28f522364f2c275ca235af98deb200f1347783b1741644beb1509f9296840f6e608d7dbad8278e7abb96
|
7
|
+
data.tar.gz: 7ac6a1d1f506ae407fd69c9910882731e4a714286aa4dfd822b6883ed7b6f6661b98ee3634061138abfcd5bd11837cc50dbc8b8abff5416e48476a7e11608d78
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
module DataMapper
|
12
|
+
module Sorting
|
13
|
+
def default_order(*fields)
|
14
|
+
default_scope(:default).update order: fields
|
15
|
+
end
|
16
|
+
|
17
|
+
alias_method :order_by, :default_order
|
18
|
+
alias_method :sort_by, :default_order
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
|
11
|
+
module DataMapper
|
12
|
+
module Sorting
|
13
|
+
VERSION = '0.1.1'
|
14
|
+
end
|
15
|
+
end
|
data/lib/dm-sorting.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
require 'dm-core'
|
11
|
+
require 'dm-sorting/sorting.rb'
|
12
|
+
|
13
|
+
module DataMapper
|
14
|
+
module Model
|
15
|
+
include DataMapper::Sorting
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
4
|
+
# Version 2, December 2004
|
5
|
+
#
|
6
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
7
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
8
|
+
#
|
9
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
10
|
+
#++
|
11
|
+
require './spec_helper'
|
12
|
+
|
13
|
+
describe DataMapper::Sorting do
|
14
|
+
supported_by :all do
|
15
|
+
before do
|
16
|
+
class Pokemon
|
17
|
+
include DataMapper::Resource
|
18
|
+
|
19
|
+
property :id, Serial
|
20
|
+
property :name, String
|
21
|
+
property :type, String
|
22
|
+
|
23
|
+
sort_by :name.asc, :type.desc
|
24
|
+
|
25
|
+
auto_migrate!
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'sorts items by the given field in the expected order' do
|
30
|
+
pokemanz = [
|
31
|
+
{ name: 'Bulbasaur', type: 'Grass' },
|
32
|
+
{ name: 'Bulbasaur', type: 'Poison' },
|
33
|
+
{ name: 'Torchic', type: 'Fire' },
|
34
|
+
{ name: 'Mudkip', type: 'Water' },
|
35
|
+
]
|
36
|
+
|
37
|
+
pokemanz.shuffle.each do |pokemon|
|
38
|
+
Pokemon.create pokemon
|
39
|
+
end
|
40
|
+
|
41
|
+
pokemanz = pokemanz.sort do |p1, p2|
|
42
|
+
[ p1[:name], p2[:type] ] <=> [ p2[:name], p1[:type] ]
|
43
|
+
end
|
44
|
+
|
45
|
+
Pokemon.all.each do |pokemon|
|
46
|
+
pokemon.name.should eql(pokemanz.shift[:name])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dm-sorting
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Giovanni Capuano
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dm-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: DataMapper plugin providing your models a default sorting method
|
56
|
+
email: webmaster@giovannicapuano.net
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- lib/dm-sorting/sorting.rb
|
62
|
+
- lib/dm-sorting/version.rb
|
63
|
+
- lib/dm-sorting.rb
|
64
|
+
- test/sorting_spec.rb
|
65
|
+
homepage: http://www.giovannicapuano.net
|
66
|
+
licenses:
|
67
|
+
- WTFPL
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.0.3
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Sorting method for DataMapper models
|
89
|
+
test_files:
|
90
|
+
- test/sorting_spec.rb
|