zeal 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.md +19 -25
  2. data/lib/zeal.rb +1 -2
  3. data/lib/zeal/version.rb +1 -1
  4. data/zeal.gemspec +1 -1
  5. metadata +4 -4
data/README.md CHANGED
@@ -11,28 +11,24 @@ records.
11
11
 
12
12
  Let's say you want to do the equivalent of this:
13
13
 
14
- ``` ruby
15
- User.find(:all, :limit => 10, :include => {:posts => :comments})
16
- ```
14
+ User.find(:all, :limit => 10, :include => {:posts => :comments})
17
15
 
18
16
  If you're reducing code duplication by loading Users in a before filter
19
17
  that's shared between multiple actions, it may not make sense to eager
20
18
  load the same associations for all of those pages. Instead, you can do
21
19
  this:
22
20
 
23
- ``` ruby
24
- # before_filters.rb
25
- @users = User.find(:all, :limit => 10)
21
+ # before_filters.rb
22
+ @users = User.find(:all, :limit => 10)
26
23
 
27
- # users_controller.rb
28
- def users_and_posts_and_stuff
29
- @users.eager_load(:posts => :comments)
30
- end
24
+ # users_controller.rb
25
+ def users_and_posts_and_stuff
26
+ @users.eager_load(:posts => :comments)
27
+ end
31
28
 
32
- def users_and_friends_and_stuff
33
- @users.eager_load(:friends, :countrymen)
34
- end
35
- ```
29
+ def users_and_friends_and_stuff
30
+ @users.eager_load(:friends, :countrymen)
31
+ end
36
32
 
37
33
  You can now avoid both N+1 and unnecessary preloading, while keeping
38
34
  your code as DRY as possible.
@@ -42,19 +38,17 @@ your code as DRY as possible.
42
38
  There are two ways to use Zeal: the nicer, more intrusive way, and the
43
39
  more explicit, less intrusive way.
44
40
 
45
- ``` ruby
46
- # more_intrusive.rb
47
- class Array
48
- include Zeal
49
- end
41
+ # more_intrusive.rb
42
+ class Array
43
+ include Zeal
44
+ end
50
45
 
51
- @users.eager_load(:friends, :countrymen)
46
+ @users.eager_load(:friends, :countrymen)
52
47
 
53
- # less_intrusive.rb
54
- Zeal.eager_load(@users, :friends, :countrymen)
48
+ # less_intrusive.rb
49
+ Zeal.eager_load(@users, :friends, :countrymen)
55
50
 
56
- # or alternately
57
- @users.extend(Zeal).eager_load(:friends, :countrymen)
58
- ```
51
+ # or alternately
52
+ @users.extend(Zeal).eager_load(:friends, :countrymen)
59
53
 
60
54
  Your choice!
@@ -4,7 +4,7 @@ module Zeal
4
4
  class EagerLoadError < RuntimeError; end
5
5
 
6
6
  class << self
7
- if Rails.version.to_s =~ /^3/
7
+ if Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR >= 1
8
8
  def eager_load(collection, *args)
9
9
  if collection.length > 0
10
10
  ActiveRecord::Associations::Preloader.new(collection, args).run
@@ -38,6 +38,5 @@ module Zeal
38
38
 
39
39
  def eager_load(*args)
40
40
  Zeal.eager_load(self, *args)
41
- self
42
41
  end
43
42
  end
@@ -1,3 +1,3 @@
1
1
  module Zeal
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Zeal::VERSION
8
8
  s.authors = ["Ryan Fitzgerald"]
9
9
  s.email = ["rfitz@academia.edu"]
10
- s.homepage = ""
10
+ s.homepage = "https://github.com/academia-edu/zeal"
11
11
  s.summary = %q{eager loading (but not too eager) for ActiveRecord collections}
12
12
  s.description = %q{Zeal allows you to eager-load associations on ActiveRecord objects that have already been loaded from the database.}
13
13
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zeal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-30 00:00:00.000000000 Z
12
+ date: 2012-02-15 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Zeal allows you to eager-load associations on ActiveRecord objects that
15
15
  have already been loaded from the database.
@@ -27,7 +27,7 @@ files:
27
27
  - lib/zeal.rb
28
28
  - lib/zeal/version.rb
29
29
  - zeal.gemspec
30
- homepage: ''
30
+ homepage: https://github.com/academia-edu/zeal
31
31
  licenses: []
32
32
  post_install_message:
33
33
  rdoc_options: []
@@ -47,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  version: '0'
48
48
  requirements: []
49
49
  rubyforge_project: zeal
50
- rubygems_version: 1.8.10
50
+ rubygems_version: 1.8.11
51
51
  signing_key:
52
52
  specification_version: 3
53
53
  summary: eager loading (but not too eager) for ActiveRecord collections