activerecord-lazy 0.0.1
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/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/activerecord-lazy.gemspec +22 -0
- data/lib/activerecord-lazy.rb +35 -0
- metadata +86 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "activerecord-lazy"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = "Jonathan Tropper"
|
9
|
+
s.email = "tropperstyle@gmail.com"
|
10
|
+
s.homepage = "https://github.com/tropperstyle/activerecord-lazy"
|
11
|
+
s.summary = "Lazy create models"
|
12
|
+
s.description = "Lazy creation for active record one-to-one associations"
|
13
|
+
|
14
|
+
s.rubyforge_project = "activerecord-lazy"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency('activerecord', '>= 2.3.5')
|
22
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'activerecord'
|
2
|
+
|
3
|
+
module ActiveRecord
|
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
|
+
|
34
|
+
end
|
35
|
+
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-lazy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jonathan Tropper
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-18 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: activerecord
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 9
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 3
|
33
|
+
- 5
|
34
|
+
version: 2.3.5
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Lazy creation for active record one-to-one associations
|
38
|
+
email: tropperstyle@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- .gitignore
|
47
|
+
- Gemfile
|
48
|
+
- Rakefile
|
49
|
+
- activerecord-lazy.gemspec
|
50
|
+
- lib/activerecord-lazy.rb
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: https://github.com/tropperstyle/activerecord-lazy
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project: activerecord-lazy
|
81
|
+
rubygems_version: 1.4.1
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Lazy create models
|
85
|
+
test_files: []
|
86
|
+
|