active_sample 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +9 -0
- data/README.md +6 -1
- data/lib/active_sample/version.rb +1 -1
- data/lib/active_sample.rb +9 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1513c164798f757b3fc73c5e68c2f35d05af054
|
4
|
+
data.tar.gz: a6a0d345d62422af604a2e343c1976e56cd2e5c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: beea2ea92ce72d877f58e0ce30f0a4219970d216fc4e8c539756e99d0f16e01aebe2380d7bc6478097e4bc10d0fe52ec8161bc5a2ed53376152b283a8027ddd9
|
7
|
+
data.tar.gz: 6e11efeb2582aa9b16771b39822f95b0f9e767d36055effd9a6acc74d1551c7b08931a67795b50e9f581c93697ce70c05d51feed37841bccc70dc0d4843675da
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
-
#
|
1
|
+
# Active Sample
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/active_sample.svg)](https://badge.fury.io/rb/active_sample)
|
4
|
+
[![Build Status](https://travis-ci.org/JuanitoFatas/active_sample.svg?branch=master)](https://travis-ci.org/JuanitoFatas/active_sample)
|
2
5
|
|
3
6
|
Sample functionality for Active Record.
|
4
7
|
|
5
8
|
## Usage
|
6
9
|
|
10
|
+
**Don't use this for large set of data for now (See [#1](https://github.com/JuanitoFatas/active_sample/issues/1)).**
|
11
|
+
|
7
12
|
```ruby
|
8
13
|
User.count # => 0
|
9
14
|
User.sample => nil
|
data/lib/active_sample.rb
CHANGED
@@ -10,16 +10,18 @@ module ActiveSample
|
|
10
10
|
raise NegativeSampleError.new("negative sample number".freeze)
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
max_id = maximum(:id)
|
14
14
|
|
15
|
-
if
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
return nil if max_id == nil
|
16
|
+
|
17
|
+
if n == 1
|
18
|
+
while !(found = find_by(id: 1 + rand(max_id))); end
|
19
|
+
|
20
|
+
found
|
19
21
|
elsif n == 0
|
20
|
-
|
22
|
+
none
|
21
23
|
else
|
22
|
-
|
24
|
+
where(id: ids.sample(n))
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_sample
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JuanitoFatas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- ".gitignore"
|
35
35
|
- ".rspec"
|
36
36
|
- ".travis.yml"
|
37
|
+
- CHANGELOG.md
|
37
38
|
- Gemfile
|
38
39
|
- LICENSE.txt
|
39
40
|
- README.md
|