hash_all 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +25 -0
- data/lib/hash_all/version.rb +1 -1
- metadata +5 -14
data/README
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Wrapper/helper for ActiveRecord <tt>find(:all, *args)</tt>. Returns a collection of
|
2
|
+
objects injected into a Hash. The attribute used as a key for the Hash should be
|
3
|
+
specified as first argument. if :fetch is not specified in the arguments the whole
|
4
|
+
object will be assigned as value, otherwise only the attribute spefified.
|
5
|
+
You can pass in all the same arguments to this method as you can to <tt>find(:all)</tt>.
|
6
|
+
|
7
|
+
==== Example
|
8
|
+
|
9
|
+
Given the models:
|
10
|
+
|
11
|
+
Feed(id: integer, state: string, name: string)
|
12
|
+
Post(id: integer, feed_name: string, title: string, url: string)
|
13
|
+
|
14
|
+
count the number of posts of every state. Row count is too high to use SQL JOIN.
|
15
|
+
|
16
|
+
@post_per_state = {}
|
17
|
+
feeds = Feed.hash_all('feed_name', :fetch => 'state')
|
18
|
+
posts = Post.all(:select => 'COUNT(id), feed_name',
|
19
|
+
:group => 'feed_name')
|
20
|
+
posts.each do |p|
|
21
|
+
@post_per_state[feeds[p.feed_name]] ||= 0
|
22
|
+
@post_per_state[feeds[p.feed_name]] += p.attributes['COUNT(id)'].to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
=> {"new york"=>6, "georgia"=>11, "new mexico"=>2, ... }
|
data/lib/hash_all/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_all
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 2
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
version: 2.0.1
|
4
|
+
prerelease:
|
5
|
+
version: 2.0.2
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Emanuele Tozzato
|
@@ -14,8 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
18
|
-
default_executable:
|
13
|
+
date: 2012-02-24 00:00:00 Z
|
19
14
|
dependencies: []
|
20
15
|
|
21
16
|
description: " Wrapper/helper for ActiveRecord find(:all, *args).\n\n Returns a collection of objects injected into a Hash. \n"
|
@@ -29,11 +24,11 @@ extra_rdoc_files: []
|
|
29
24
|
files:
|
30
25
|
- .gitignore
|
31
26
|
- Gemfile
|
27
|
+
- README
|
32
28
|
- Rakefile
|
33
29
|
- hash_all.gemspec
|
34
30
|
- lib/hash_all.rb
|
35
31
|
- lib/hash_all/version.rb
|
36
|
-
has_rdoc: true
|
37
32
|
homepage: http://blog.mekdigital.com
|
38
33
|
licenses: []
|
39
34
|
|
@@ -47,21 +42,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
42
|
requirements:
|
48
43
|
- - ">="
|
49
44
|
- !ruby/object:Gem::Version
|
50
|
-
segments:
|
51
|
-
- 0
|
52
45
|
version: "0"
|
53
46
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
47
|
none: false
|
55
48
|
requirements:
|
56
49
|
- - ">="
|
57
50
|
- !ruby/object:Gem::Version
|
58
|
-
segments:
|
59
|
-
- 0
|
60
51
|
version: "0"
|
61
52
|
requirements: []
|
62
53
|
|
63
54
|
rubyforge_project: hash_all
|
64
|
-
rubygems_version: 1.
|
55
|
+
rubygems_version: 1.8.5
|
65
56
|
signing_key:
|
66
57
|
specification_version: 3
|
67
58
|
summary: Wrapper for find(:all) that returns Hash
|