any 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/Rakefile +4 -0
  2. data/Readme.markdown +11 -0
  3. data/init.rb +1 -0
  4. data/lib/any.rb +15 -0
  5. metadata +72 -0
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/Readme.markdown ADDED
@@ -0,0 +1,11 @@
1
+ # Any
2
+
3
+ Any provides a super easy way to get any model instance from an Active Record model. This is really handy when testing or populating your database with dummy data.
4
+
5
+ ## Useage
6
+
7
+ Say you have a model named `Post`. All you have to do is:
8
+
9
+ Post.any
10
+
11
+ If you have no posts, it will return `nil` instead.
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require "any"
data/lib/any.rb ADDED
@@ -0,0 +1,15 @@
1
+ module Any
2
+ def self.included(base)
3
+ base.extend ClassMethods
4
+ end
5
+
6
+ module ClassMethods
7
+ def any
8
+ limit(1).offset((count * rand).to_i).first
9
+ end
10
+ end
11
+ end
12
+
13
+ class ActiveRecord::Base
14
+ include Any
15
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: any
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Sam Soffes
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-15 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Super easy way to get any model instance from an Active Record model.
23
+ email: sam@samsoff.es
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/any.rb
32
+ - Rakefile
33
+ - Readme.markdown
34
+ - init.rb
35
+ has_rdoc: true
36
+ homepage: http://github.com/samsoffes/any
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 19
59
+ segments:
60
+ - 1
61
+ - 3
62
+ - 4
63
+ version: 1.3.4
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.7
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Super easy way to get any model instance.
71
+ test_files: []
72
+