randumb 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/lib/randumb/relation.rb +18 -6
- data/lib/randumb/version.rb +1 -1
- data/test/models/artist.rb +1 -1
- metadata +105 -92
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OTI0OTBlMWNhNTc3MWQxYzU5MDM0YzAwNmM5NWI3OTFmNzhlYzA0Nw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YzNlMmUzYTA3ZDRmZDI4ZmE5YTIyMzFiMGNlMTA2ZDNiMjRjZDFjNQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OTkzMmIzZmQ1ZDg0YjhjYmFiODhhNDRhZWFkN2RkNzdjYTQ4NTE5ZDgzOTIx
|
10
|
+
NTY4NTk4YjVhOTZmMTFhNWJlZjM5Zjg0OGE3YzMyNmFmM2QwZDA1ZDRjYTY3
|
11
|
+
YTRmYzVkNjExY2UwMTc4MDBhZWFmZjFjNzkzYTgwMzI2MjQzYjM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OWJjZjUzODMzOWY2MWYwZWU1YWQzZDAxMWNkOWYyM2E3ZTQyZTNmMmE4ODI4
|
14
|
+
ZjY4NjE5ZjBjMzkyNDFmZTFhZWJlMGQ4YWNlOTg2YjdiNzA3M2NmNzhhNGZj
|
15
|
+
ZDUzMTZjNjgwYTI3ZWYzNjE0MDdkMWNmNjNlOWY4MGQ0ZWU2ZWY=
|
data/lib/randumb/relation.rb
CHANGED
@@ -19,17 +19,26 @@ module Randumb
|
|
19
19
|
relation = clone
|
20
20
|
return random_by_id_shuffle(max_items) if is_randumb_postges_case?(relation, ranking_column)
|
21
21
|
raise_unless_valid_ranking_column(ranking_column)
|
22
|
-
|
22
|
+
# get clause for current db type
|
23
23
|
order_clause = random_order_clause(ranking_column)
|
24
|
-
the_scope = relation.order(order_clause)
|
25
24
|
|
25
|
+
the_scope = if ::ActiveRecord::VERSION::MAJOR == 3 && ::ActiveRecord::VERSION::MINOR < 2
|
26
|
+
# AR 3.0.0 support
|
27
|
+
relation.order(order_clause)
|
28
|
+
else
|
29
|
+
# keep prior orders and append random
|
30
|
+
all_orders = (relation.orders + [order_clause]).join(", ")
|
31
|
+
# override all previous orders
|
32
|
+
relation.reorder(all_orders)
|
33
|
+
end
|
34
|
+
|
26
35
|
# override the limit if they are requesting multiple records
|
27
36
|
if max_items && (!relation.limit_value || relation.limit_value > max_items)
|
28
37
|
the_scope = the_scope.limit(max_items)
|
29
38
|
end
|
30
39
|
|
31
40
|
# return first record if method was called without parameters
|
32
|
-
max_items ? the_scope.
|
41
|
+
max_items ? the_scope.to_a : the_scope.first
|
33
42
|
end
|
34
43
|
|
35
44
|
|
@@ -115,12 +124,15 @@ module Randumb
|
|
115
124
|
|
116
125
|
# do original query but only for id field
|
117
126
|
id_only_relation = relation.select("#{table_name}.id")
|
127
|
+
|
118
128
|
id_results = connection.select_all(id_only_relation.to_sql)
|
119
129
|
|
120
|
-
if max_ids == 1 && id_results.
|
121
|
-
|
130
|
+
if max_ids == 1 && id_results.count > 0
|
131
|
+
[ id_results[ rand(id_results.count) ]['id'] ]
|
122
132
|
else
|
123
|
-
|
133
|
+
# ActiveRecord 4 requires .to_ary
|
134
|
+
arr = id_results.respond_to?(:to_ary) ? id_results.to_ary : id_results
|
135
|
+
arr.shuffle![0,max_ids].collect!{ |h| h['id'] }
|
124
136
|
end
|
125
137
|
end
|
126
138
|
|
data/lib/randumb/version.rb
CHANGED
data/test/models/artist.rb
CHANGED
metadata
CHANGED
@@ -1,103 +1,119 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: randumb
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.3.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- Zachary Kloepping
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2013-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
16
14
|
name: rake
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: "0"
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
24
20
|
type: :runtime
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: activesupport
|
28
21
|
prerelease: false
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
34
33
|
version: 3.0.0
|
35
34
|
type: :runtime
|
36
|
-
version_requirements: *id002
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: activerecord
|
39
35
|
prerelease: false
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activerecord
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
45
47
|
version: 3.0.0
|
46
48
|
type: :runtime
|
47
|
-
version_requirements: *id003
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: sqlite3
|
50
49
|
prerelease: false
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.7
|
57
62
|
type: :development
|
58
|
-
version_requirements: *id004
|
59
|
-
- !ruby/object:Gem::Dependency
|
60
|
-
name: shoulda
|
61
63
|
prerelease: false
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.3.7
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: shoulda
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
68
76
|
type: :development
|
69
|
-
version_requirements: *id005
|
70
|
-
- !ruby/object:Gem::Dependency
|
71
|
-
name: factory_girl
|
72
77
|
prerelease: false
|
73
|
-
|
74
|
-
|
75
|
-
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: factory_girl
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
76
87
|
- - ~>
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version:
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
79
90
|
type: :development
|
80
|
-
version_requirements: *id006
|
81
|
-
- !ruby/object:Gem::Dependency
|
82
|
-
name: faker
|
83
91
|
prerelease: false
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: faker
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
90
104
|
type: :development
|
91
|
-
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
92
111
|
description:
|
93
112
|
email:
|
94
113
|
executables: []
|
95
|
-
|
96
114
|
extensions: []
|
97
|
-
|
98
115
|
extra_rdoc_files: []
|
99
|
-
|
100
|
-
files:
|
116
|
+
files:
|
101
117
|
- lib/randumb/relation.rb
|
102
118
|
- lib/randumb/version.rb
|
103
119
|
- lib/randumb.rb
|
@@ -108,33 +124,30 @@ files:
|
|
108
124
|
- test/test_helper.rb
|
109
125
|
- test/weighted_test.rb
|
110
126
|
homepage: https://github.com/spilliton/randumb
|
111
|
-
licenses:
|
112
|
-
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata: {}
|
113
130
|
post_install_message:
|
114
131
|
rdoc_options: []
|
115
|
-
|
116
|
-
require_paths:
|
132
|
+
require_paths:
|
117
133
|
- lib
|
118
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
version: "0"
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
130
144
|
requirements: []
|
131
|
-
|
132
145
|
rubyforge_project:
|
133
|
-
rubygems_version:
|
146
|
+
rubygems_version: 2.0.5
|
134
147
|
signing_key:
|
135
|
-
specification_version:
|
148
|
+
specification_version: 4
|
136
149
|
summary: Adds the ability to pull random records from ActiveRecord
|
137
|
-
test_files:
|
150
|
+
test_files:
|
138
151
|
- test/models/album.rb
|
139
152
|
- test/models/artist.rb
|
140
153
|
- test/models/factories.rb
|