randomizr 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,29 @@
1
+ = Randomizr
2
+
3
+ Returns one random Active Record object using cross-platform ANSI compliant SQL.
4
+
5
+ We have all used <tt>order by rand()</tt> to select a random record from time to time.
6
+ We know we shouldn't, but it was just too easy. Well no more. NO MORE. It's
7
+ now +easier+ to do it properly by just using this gem. That's right. It will
8
+ solve all your ansi-sql troubles and put that smile back on your face.
9
+
10
+ == Prerequisites
11
+
12
+ Active Record, of course. Any version 2 or 3 will do.
13
+
14
+ == Installation
15
+
16
+ config.gem 'randomizr'
17
+
18
+ or in your Gemfile:
19
+
20
+ gem 'randomizr'
21
+
22
+ I told you installation would be easy.
23
+
24
+
25
+ == Examples
26
+
27
+ Comment.randomizr # => look ma, a random comment!
28
+
29
+ Copyright (c) 2011 Joost Baaij, released under the MIT license
@@ -1,5 +1,11 @@
1
1
  require "randomizr/version"
2
+ require "activerecord"
2
3
 
3
- module Randomizr
4
- # Your code goes here...
5
- end
4
+ # http://paulbarry.com/articles/2009/08/30/active-record-random
5
+ class ActiveRecord::Base
6
+ def self.randomizr
7
+ if (c = count) > 0
8
+ first(:offset => rand(c))
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Randomizr
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -12,6 +12,8 @@ Gem::Specification.new do |s|
12
12
  s.description = %q{Returns one random Active Record object using cross-platform ANSI compliant SQL}
13
13
 
14
14
  s.rubyforge_project = "randomizr"
15
+
16
+ s.add_dependency('activerecord', '>= 2.1', '< 4')
15
17
 
16
18
  s.files = `git ls-files`.split("\n")
17
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: randomizr
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 1.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Joost Baaij
@@ -12,8 +12,21 @@ cert_chain: []
12
12
 
13
13
  date: 2011-08-03 00:00:00 +02:00
14
14
  default_executable:
15
- dependencies: []
16
-
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: activerecord
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "2.1"
25
+ - - <
26
+ - !ruby/object:Gem::Version
27
+ version: "4"
28
+ type: :runtime
29
+ version_requirements: *id001
17
30
  description: Returns one random Active Record object using cross-platform ANSI compliant SQL
18
31
  email:
19
32
  - joost@spacebabies.nl
@@ -26,6 +39,7 @@ extra_rdoc_files: []
26
39
  files:
27
40
  - .gitignore
28
41
  - Gemfile
42
+ - README.rdoc
29
43
  - Rakefile
30
44
  - lib/randomizr.rb
31
45
  - lib/randomizr/version.rb