activerecord-lazy-attributes 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,6 +4,21 @@ This ActiveRecord extension allows to define attributes to be
4
4
  lazy-loaded. It's main purpose is to avoid loading large columns (such
5
5
  as BLOBs) with every SELECT.
6
6
 
7
+ == Installation
8
+
9
+ gem install activerecord-lazy-attributes
10
+
11
+ == Loading
12
+
13
+ To use it in a Rails application, add this line to your environment.rb (or similar):
14
+
15
+ config.gem 'activerecord-lazy-attributes', :lib => 'lazy_attributes'
16
+
17
+ Otherwise:
18
+
19
+ gem 'activerecord-lazy-attributes'
20
+ require 'lazy_attributes'
21
+
7
22
  == Example
8
23
 
9
24
  class Image < ActiveRecord::Base
@@ -15,8 +30,7 @@ as BLOBs) with every SELECT.
15
30
 
16
31
  == Credit
17
32
 
18
- This is based on
19
- http://refactormycode.com/codes/219-activerecord-lazy-attribute-loading-plugin-for-rails
33
+ This is based on {this refactoring request}[http://refactormycode.com/codes/219-activerecord-lazy-attribute-loading-plugin-for-rails]
20
34
  (the code here is the last contribution to this refactoring).
21
35
 
22
36
  == Note on Patches/Pull Requests
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{activerecord-lazy-attributes}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Moritz Heidkamp"]
12
- s.date = %q{2010-02-18}
12
+ s.date = %q{2010-03-28}
13
13
  s.description = %q{A useful ActiveRecord extension to handle columns containing large amounts of data}
14
14
  s.email = %q{moritz@twoticketsplease.de}
15
15
  s.extra_rdoc_files = [
@@ -8,10 +8,13 @@ module DerGuteMoritz
8
8
  base.class_eval do
9
9
  class_inheritable_accessor :lazy_attributes
10
10
  class_inheritable_accessor :eager_attributes
11
+ class_inheritable_accessor :eager_attributes_quoted
11
12
  self.lazy_attributes = []
12
13
  extend ClassMethods
13
14
  metaclass.alias_method_chain :default_select, :lazy_attributes
14
15
  end
16
+
17
+ ::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinBase.send :include, JoinBase
15
18
  end
16
19
 
17
20
  module ClassMethods
@@ -19,7 +22,8 @@ module DerGuteMoritz
19
22
  def attr_lazy(*attrs)
20
23
  normalized_attrs = attrs.map { |a| a.to_s }
21
24
  self.lazy_attributes += normalized_attrs
22
- self.eager_attributes = (column_names - lazy_attributes).map { |a| connection.quote_column_name(a) }
25
+ self.eager_attributes = (column_names - lazy_attributes)
26
+ self.eager_attributes_quoted = eager_attributes.map { |a| connection.quote_column_name(a) }
23
27
 
24
28
  normalized_attrs.each do |attr|
25
29
  define_method attr do
@@ -37,14 +41,30 @@ module DerGuteMoritz
37
41
  default_select_without_lazy_attributes(qualified)
38
42
  else
39
43
  if qualified
40
- eager_attributes.map { |a| "#{quoted_table_name}.#{a}" }
44
+ eager_attributes_quoted.map { |a| "#{quoted_table_name}.#{a}" }
41
45
  else
42
- eager_attributes
46
+ eager_attributes_quoted
43
47
  end.join(', ')
44
48
  end
45
49
  end
46
50
 
47
51
  end
52
+
53
+ module JoinBase
54
+
55
+ def self.included(base)
56
+ base.send :alias_method_chain, :column_names, :lazy_attributes
57
+ end
58
+
59
+ def column_names_with_lazy_attributes
60
+ if active_record.lazy_attributes.empty?
61
+ column_names_without_lazy_attributes
62
+ else
63
+ active_record.eager_attributes
64
+ end
65
+ end
66
+
67
+ end
48
68
 
49
69
  end
50
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-lazy-attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moritz Heidkamp
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-18 00:00:00 +01:00
12
+ date: 2010-03-28 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency