activerecord-lazy-attributes 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/activerecord-lazy-attributes.gemspec +7 -7
- data/lib/lazy_attributes.rb +10 -1
- data/spec/lazy_attributes_spec.rb +6 -0
- metadata +38 -15
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/DerGuteMoritz/activerecord-lazy-attributes"
|
12
12
|
gem.authors = ["Moritz Heidkamp"]
|
13
13
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
-
gem.add_dependency 'activerecord', '
|
14
|
+
gem.add_dependency 'activerecord', '~> 2.3'
|
15
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
16
|
end
|
17
17
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
@@ -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.
|
8
|
+
s.version = "0.0.4"
|
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-
|
12
|
+
s.date = %q{2010-10-01}
|
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 = [
|
@@ -36,7 +36,7 @@ Gem::Specification.new do |s|
|
|
36
36
|
s.homepage = %q{http://github.com/DerGuteMoritz/activerecord-lazy-attributes}
|
37
37
|
s.rdoc_options = ["--charset=UTF-8"]
|
38
38
|
s.require_paths = ["lib"]
|
39
|
-
s.rubygems_version = %q{1.3.
|
39
|
+
s.rubygems_version = %q{1.3.7}
|
40
40
|
s.summary = %q{An ActiveRecord extension which allows attributes to be lazy-loaded}
|
41
41
|
s.test_files = [
|
42
42
|
"spec/spec_helper.rb",
|
@@ -49,16 +49,16 @@ Gem::Specification.new do |s|
|
|
49
49
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
50
|
s.specification_version = 3
|
51
51
|
|
52
|
-
if Gem::Version.new(Gem::
|
52
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
53
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
54
|
-
s.add_runtime_dependency(%q<activerecord>, ["
|
54
|
+
s.add_runtime_dependency(%q<activerecord>, ["~> 2.3"])
|
55
55
|
else
|
56
56
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
57
|
-
s.add_dependency(%q<activerecord>, ["
|
57
|
+
s.add_dependency(%q<activerecord>, ["~> 2.3"])
|
58
58
|
end
|
59
59
|
else
|
60
60
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
61
|
-
s.add_dependency(%q<activerecord>, ["
|
61
|
+
s.add_dependency(%q<activerecord>, ["~> 2.3"])
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
data/lib/lazy_attributes.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
gem 'activerecord', '~> 2.3'
|
1
2
|
require 'active_record'
|
2
3
|
|
3
4
|
module DerGuteMoritz
|
@@ -11,7 +12,7 @@ module DerGuteMoritz
|
|
11
12
|
class_inheritable_accessor :eager_attributes_quoted
|
12
13
|
self.lazy_attributes = []
|
13
14
|
extend ClassMethods
|
14
|
-
metaclass.alias_method_chain :default_select, :lazy_attributes
|
15
|
+
send(respond_to?(:singleton_class) ? :singleton_class : :metaclass).alias_method_chain :default_select, :lazy_attributes
|
15
16
|
end
|
16
17
|
|
17
18
|
::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinBase.send :include, JoinBase
|
@@ -30,6 +31,14 @@ module DerGuteMoritz
|
|
30
31
|
write_attribute(attr, connection.select_value('SELECT %s FROM %s WHERE %s = %s' % [connection.quote_column_name(attr), self.class.quoted_table_name, self.class.primary_key, quoted_id])) unless has_attribute?(attr)
|
31
32
|
read_attribute(attr)
|
32
33
|
end
|
34
|
+
|
35
|
+
define_method "#{attr}?" do
|
36
|
+
if new_record? || has_attribute?(attr)
|
37
|
+
!!send(attr)
|
38
|
+
else
|
39
|
+
self.class.exists? ["#{self.class.primary_key} = ? AND #{connection.quote_column_name(attr)} IS NOT NULL", id]
|
40
|
+
end
|
41
|
+
end
|
33
42
|
end
|
34
43
|
|
35
44
|
end
|
@@ -23,4 +23,10 @@ describe DerGuteMoritz::ActiveRecord::LazyAttributes do
|
|
23
23
|
i.should have_attribute('data')
|
24
24
|
end
|
25
25
|
|
26
|
+
it 'should provide a predicate that checks agains the database if the lazy attribute has not been loaded yet' do
|
27
|
+
i = Image.find(@id)
|
28
|
+
i.data?.should be_true
|
29
|
+
i.should_not have_attribute('data')
|
30
|
+
end
|
31
|
+
|
26
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-lazy-attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Moritz Heidkamp
|
@@ -9,29 +15,40 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date: 2010-
|
18
|
+
date: 2010-10-01 00:00:00 +02:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: rspec
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
23
34
|
version: 1.2.9
|
24
|
-
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
25
37
|
- !ruby/object:Gem::Dependency
|
26
38
|
name: activerecord
|
27
|
-
|
28
|
-
|
29
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
30
42
|
requirements:
|
31
|
-
- -
|
43
|
+
- - ~>
|
32
44
|
- !ruby/object:Gem::Version
|
33
|
-
|
34
|
-
|
45
|
+
hash: 5
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 3
|
49
|
+
version: "2.3"
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
35
52
|
description: A useful ActiveRecord extension to handle columns containing large amounts of data
|
36
53
|
email: moritz@twoticketsplease.de
|
37
54
|
executables: []
|
@@ -67,21 +84,27 @@ rdoc_options:
|
|
67
84
|
require_paths:
|
68
85
|
- lib
|
69
86
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
70
88
|
requirements:
|
71
89
|
- - ">="
|
72
90
|
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
73
94
|
version: "0"
|
74
|
-
version:
|
75
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
76
97
|
requirements:
|
77
98
|
- - ">="
|
78
99
|
- !ruby/object:Gem::Version
|
100
|
+
hash: 3
|
101
|
+
segments:
|
102
|
+
- 0
|
79
103
|
version: "0"
|
80
|
-
version:
|
81
104
|
requirements: []
|
82
105
|
|
83
106
|
rubyforge_project:
|
84
|
-
rubygems_version: 1.3.
|
107
|
+
rubygems_version: 1.3.7
|
85
108
|
signing_key:
|
86
109
|
specification_version: 3
|
87
110
|
summary: An ActiveRecord extension which allows attributes to be lazy-loaded
|