activerecord-lazy 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/activerecord-lazy.gemspec +2 -2
- data/lib/activerecord-lazy.rb +29 -29
- metadata +6 -7
data/activerecord-lazy.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "activerecord-lazy"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.2"
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = "Jonathan Tropper"
|
9
9
|
s.email = "tropperstyle@gmail.com"
|
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_dependency('activerecord', '>= 2.3
|
21
|
+
s.add_dependency('activerecord', '>= 2.3')
|
22
22
|
end
|
data/lib/activerecord-lazy.rb
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
require 'activerecord'
|
2
2
|
|
3
3
|
module ActiveRecord
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
4
|
+
module LazyAssociations
|
5
|
+
def self.extended(base)
|
6
|
+
class << base
|
7
|
+
alias_method_chain :association_accessor_methods, :lazy
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def association_accessor_methods_with_lazy(reflection, association_proxy_class)
|
12
|
+
original = association_accessor_methods_without_lazy(reflection, association_proxy_class)
|
13
|
+
|
14
|
+
if reflection.options[:lazy]
|
15
|
+
constructor = reflection.options[:lazy].to_s
|
16
|
+
raise ActiveRecordError, 'has_one :lazy option must be :build or :create' unless %w[build create].include?(constructor)
|
17
|
+
|
18
|
+
define_method "#{reflection.name}_with_lazy" do
|
19
|
+
send("#{reflection.name}_without_lazy") || send("#{constructor}_#{reflection.name}")
|
20
|
+
end
|
21
|
+
|
22
|
+
alias_method_chain reflection.name, :lazy
|
23
|
+
end
|
24
|
+
|
25
|
+
original
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Base
|
30
|
+
valid_keys_for_has_one_association << :lazy
|
31
|
+
extend LazyAssociations
|
32
|
+
end
|
33
33
|
|
34
34
|
end
|
35
35
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-lazy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jonathan Tropper
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-29 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,12 +26,11 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 5
|
30
30
|
segments:
|
31
31
|
- 2
|
32
32
|
- 3
|
33
|
-
|
34
|
-
version: 2.3.5
|
33
|
+
version: "2.3"
|
35
34
|
type: :runtime
|
36
35
|
version_requirements: *id001
|
37
36
|
description: Lazy creation for active record one-to-one associations
|