ripple 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ripple.rb +17 -1
- data/lib/ripple/associations.rb +157 -0
- data/lib/ripple/associations/embedded.rb +42 -0
- data/lib/ripple/associations/instantiators.rb +39 -0
- data/lib/ripple/{document/associations → associations}/linked.rb +9 -11
- data/lib/ripple/{document/associations/one_embedded_proxy.rb → associations/many.rb} +30 -21
- data/lib/ripple/{document/associations/embedded.rb → associations/many_embedded_proxy.rb} +26 -23
- data/lib/ripple/{embedded_document/conversion.rb → associations/one.rb} +8 -13
- data/lib/ripple/{document/associations/instantiators.rb → associations/one_embedded_proxy.rb} +17 -19
- data/lib/ripple/associations/proxy.rb +123 -0
- data/lib/ripple/attribute_methods.rb +116 -0
- data/lib/ripple/{document/attribute_methods/write.rb → attribute_methods/dirty.rb} +26 -16
- data/lib/ripple/attribute_methods/query.rb +48 -0
- data/lib/ripple/{document/attribute_methods → attribute_methods}/read.rb +16 -18
- data/lib/ripple/attribute_methods/write.rb +38 -0
- data/lib/ripple/callbacks.rb +73 -0
- data/lib/ripple/{document/associations/one.rb → conversion.rb} +18 -13
- data/lib/ripple/document.rb +19 -9
- data/lib/ripple/embedded_document.rb +10 -10
- data/lib/ripple/embedded_document/persistence.rb +12 -53
- data/lib/ripple/properties.rb +83 -0
- data/lib/ripple/timestamps.rb +34 -0
- data/lib/ripple/{document/validations.rb → validations.rb} +31 -33
- data/lib/ripple/{document/validations → validations}/associated_validator.rb +9 -10
- data/spec/integration/ripple/associations_spec.rb +1 -2
- data/spec/integration/ripple/persistence_spec.rb +2 -3
- data/spec/ripple/associations/many_embedded_proxy_spec.rb +2 -2
- data/spec/ripple/associations/one_embedded_proxy_spec.rb +2 -2
- data/spec/ripple/associations/proxy_spec.rb +1 -1
- data/spec/ripple/associations_spec.rb +15 -20
- data/spec/ripple/attribute_methods_spec.rb +3 -6
- data/spec/ripple/callbacks_spec.rb +1 -1
- data/spec/ripple/{embedded_document/conversion_spec.rb → conversion_spec.rb} +4 -4
- data/spec/ripple/embedded_document/persistence_spec.rb +4 -16
- data/spec/ripple/properties_spec.rb +17 -18
- data/spec/ripple/timestamps_spec.rb +1 -1
- data/spec/ripple/validations_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/associations/proxies.rb +4 -4
- metadata +27 -29
- data/lib/ripple/document/associations.rb +0 -154
- data/lib/ripple/document/associations/many.rb +0 -52
- data/lib/ripple/document/associations/many_embedded_proxy.rb +0 -49
- data/lib/ripple/document/associations/proxy.rb +0 -125
- data/lib/ripple/document/attribute_methods.rb +0 -118
- data/lib/ripple/document/attribute_methods/dirty.rb +0 -52
- data/lib/ripple/document/attribute_methods/query.rb +0 -49
- data/lib/ripple/document/callbacks.rb +0 -75
- data/lib/ripple/document/properties.rb +0 -85
- data/lib/ripple/document/timestamps.rb +0 -22
- data/spec/support/integration.rb +0 -4
data/spec/spec_helper.rb
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
15
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'riak','lib'))
|
16
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'riak-client','lib'))
|
17
17
|
|
18
18
|
require 'rubygems' # Use the gems path only for the spec suite
|
19
19
|
require 'ripple'
|
@@ -1,16 +1,16 @@
|
|
1
1
|
# yet another filch from mongo mapper
|
2
|
-
class FakeNilProxy < Ripple::
|
2
|
+
class FakeNilProxy < Ripple::Associations::Proxy
|
3
3
|
def find_target; nil end
|
4
4
|
end
|
5
5
|
|
6
|
-
class FakeBlankProxy < Ripple::
|
6
|
+
class FakeBlankProxy < Ripple::Associations::Proxy
|
7
7
|
def find_target; '' end
|
8
8
|
end
|
9
9
|
|
10
|
-
class FakeNumberProxy < Ripple::
|
10
|
+
class FakeNumberProxy < Ripple::Associations::Proxy
|
11
11
|
def find_target; 17 end
|
12
12
|
end
|
13
13
|
|
14
|
-
class FakeProxy < Ripple::
|
14
|
+
class FakeProxy < Ripple::Associations::Proxy
|
15
15
|
def find_target; [1, 2] end
|
16
16
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 7
|
8
|
-
-
|
9
|
-
version: 0.7.
|
8
|
+
- 1
|
9
|
+
version: 0.7.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sean Cribbs
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-06-08 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -43,8 +43,8 @@ dependencies:
|
|
43
43
|
segments:
|
44
44
|
- 0
|
45
45
|
- 7
|
46
|
-
-
|
47
|
-
version: 0.7.
|
46
|
+
- 1
|
47
|
+
version: 0.7.1
|
48
48
|
type: :runtime
|
49
49
|
version_requirements: *id002
|
50
50
|
- !ruby/object:Gem::Dependency
|
@@ -86,39 +86,39 @@ extensions: []
|
|
86
86
|
extra_rdoc_files: []
|
87
87
|
|
88
88
|
files:
|
89
|
+
- lib/ripple/associations/embedded.rb
|
90
|
+
- lib/ripple/associations/instantiators.rb
|
91
|
+
- lib/ripple/associations/linked.rb
|
92
|
+
- lib/ripple/associations/many.rb
|
93
|
+
- lib/ripple/associations/many_embedded_proxy.rb
|
94
|
+
- lib/ripple/associations/one.rb
|
95
|
+
- lib/ripple/associations/one_embedded_proxy.rb
|
96
|
+
- lib/ripple/associations/proxy.rb
|
97
|
+
- lib/ripple/associations.rb
|
98
|
+
- lib/ripple/attribute_methods/dirty.rb
|
99
|
+
- lib/ripple/attribute_methods/query.rb
|
100
|
+
- lib/ripple/attribute_methods/read.rb
|
101
|
+
- lib/ripple/attribute_methods/write.rb
|
102
|
+
- lib/ripple/attribute_methods.rb
|
103
|
+
- lib/ripple/callbacks.rb
|
104
|
+
- lib/ripple/conversion.rb
|
89
105
|
- lib/ripple/core_ext/casting.rb
|
90
|
-
- lib/ripple/document/associations/embedded.rb
|
91
|
-
- lib/ripple/document/associations/instantiators.rb
|
92
|
-
- lib/ripple/document/associations/linked.rb
|
93
|
-
- lib/ripple/document/associations/many.rb
|
94
|
-
- lib/ripple/document/associations/many_embedded_proxy.rb
|
95
|
-
- lib/ripple/document/associations/one.rb
|
96
|
-
- lib/ripple/document/associations/one_embedded_proxy.rb
|
97
|
-
- lib/ripple/document/associations/proxy.rb
|
98
|
-
- lib/ripple/document/associations.rb
|
99
|
-
- lib/ripple/document/attribute_methods/dirty.rb
|
100
|
-
- lib/ripple/document/attribute_methods/query.rb
|
101
|
-
- lib/ripple/document/attribute_methods/read.rb
|
102
|
-
- lib/ripple/document/attribute_methods/write.rb
|
103
|
-
- lib/ripple/document/attribute_methods.rb
|
104
106
|
- lib/ripple/document/bucket_access.rb
|
105
|
-
- lib/ripple/document/callbacks.rb
|
106
107
|
- lib/ripple/document/finders.rb
|
107
108
|
- lib/ripple/document/persistence.rb
|
108
|
-
- lib/ripple/document/properties.rb
|
109
|
-
- lib/ripple/document/timestamps.rb
|
110
|
-
- lib/ripple/document/validations/associated_validator.rb
|
111
|
-
- lib/ripple/document/validations.rb
|
112
109
|
- lib/ripple/document.rb
|
113
|
-
- lib/ripple/embedded_document/conversion.rb
|
114
110
|
- lib/ripple/embedded_document/finders.rb
|
115
111
|
- lib/ripple/embedded_document/persistence.rb
|
116
112
|
- lib/ripple/embedded_document.rb
|
117
113
|
- lib/ripple/i18n.rb
|
118
114
|
- lib/ripple/locale/en.yml
|
115
|
+
- lib/ripple/properties.rb
|
119
116
|
- lib/ripple/property_type_mismatch.rb
|
120
117
|
- lib/ripple/railtie.rb
|
118
|
+
- lib/ripple/timestamps.rb
|
121
119
|
- lib/ripple/translation.rb
|
120
|
+
- lib/ripple/validations/associated_validator.rb
|
121
|
+
- lib/ripple/validations.rb
|
122
122
|
- lib/ripple.rb
|
123
123
|
- Rakefile
|
124
124
|
- spec/fixtures/config.yml
|
@@ -131,9 +131,9 @@ files:
|
|
131
131
|
- spec/ripple/attribute_methods_spec.rb
|
132
132
|
- spec/ripple/bucket_access_spec.rb
|
133
133
|
- spec/ripple/callbacks_spec.rb
|
134
|
+
- spec/ripple/conversion_spec.rb
|
134
135
|
- spec/ripple/core_ext_spec.rb
|
135
136
|
- spec/ripple/document_spec.rb
|
136
|
-
- spec/ripple/embedded_document/conversion_spec.rb
|
137
137
|
- spec/ripple/embedded_document/finders_spec.rb
|
138
138
|
- spec/ripple/embedded_document/persistence_spec.rb
|
139
139
|
- spec/ripple/embedded_document_spec.rb
|
@@ -145,7 +145,6 @@ files:
|
|
145
145
|
- spec/ripple/validations_spec.rb
|
146
146
|
- spec/spec_helper.rb
|
147
147
|
- spec/support/associations/proxies.rb
|
148
|
-
- spec/support/integration.rb
|
149
148
|
- spec/support/mocks.rb
|
150
149
|
- spec/support/models/address.rb
|
151
150
|
- spec/support/models/box.rb
|
@@ -203,9 +202,9 @@ test_files:
|
|
203
202
|
- spec/ripple/attribute_methods_spec.rb
|
204
203
|
- spec/ripple/bucket_access_spec.rb
|
205
204
|
- spec/ripple/callbacks_spec.rb
|
205
|
+
- spec/ripple/conversion_spec.rb
|
206
206
|
- spec/ripple/core_ext_spec.rb
|
207
207
|
- spec/ripple/document_spec.rb
|
208
|
-
- spec/ripple/embedded_document/conversion_spec.rb
|
209
208
|
- spec/ripple/embedded_document/finders_spec.rb
|
210
209
|
- spec/ripple/embedded_document/persistence_spec.rb
|
211
210
|
- spec/ripple/embedded_document_spec.rb
|
@@ -217,7 +216,6 @@ test_files:
|
|
217
216
|
- spec/ripple/validations_spec.rb
|
218
217
|
- spec/spec_helper.rb
|
219
218
|
- spec/support/associations/proxies.rb
|
220
|
-
- spec/support/integration.rb
|
221
219
|
- spec/support/mocks.rb
|
222
220
|
- spec/support/models/address.rb
|
223
221
|
- spec/support/models/box.rb
|
@@ -1,154 +0,0 @@
|
|
1
|
-
# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
require 'ripple'
|
15
|
-
|
16
|
-
module Ripple
|
17
|
-
module Document
|
18
|
-
module Associations
|
19
|
-
extend ActiveSupport::Concern
|
20
|
-
extend ActiveSupport::Autoload
|
21
|
-
|
22
|
-
autoload :Proxy
|
23
|
-
autoload :One
|
24
|
-
autoload :Many
|
25
|
-
autoload :Embedded
|
26
|
-
autoload :Instantiators
|
27
|
-
autoload :OneEmbeddedProxy
|
28
|
-
autoload :ManyEmbeddedProxy
|
29
|
-
|
30
|
-
module ClassMethods
|
31
|
-
# @private
|
32
|
-
def inherited(subclass)
|
33
|
-
super
|
34
|
-
subclass.associations.merge!(associations)
|
35
|
-
end
|
36
|
-
|
37
|
-
# Associations defined on the document
|
38
|
-
def associations
|
39
|
-
@associations ||= {}.with_indifferent_access
|
40
|
-
end
|
41
|
-
|
42
|
-
# Creates a singular association
|
43
|
-
def one(name, options={})
|
44
|
-
create_association(:one, name, options)
|
45
|
-
end
|
46
|
-
|
47
|
-
# Creates a plural association
|
48
|
-
def many(name, options={})
|
49
|
-
create_association(:many, name, options)
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
def create_association(type, name, options={})
|
54
|
-
association = associations[name] = Association.new(type, name, options)
|
55
|
-
|
56
|
-
define_method(name) do
|
57
|
-
get_proxy(association)
|
58
|
-
end
|
59
|
-
|
60
|
-
define_method("#{name}=") do |value|
|
61
|
-
get_proxy(association).replace(value)
|
62
|
-
value
|
63
|
-
end
|
64
|
-
|
65
|
-
if association.one?
|
66
|
-
define_method("#{name}?") do
|
67
|
-
get_proxy(association).present?
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
module InstanceMethods
|
74
|
-
def associations
|
75
|
-
self.class.associations
|
76
|
-
end
|
77
|
-
|
78
|
-
def embedded_associations
|
79
|
-
associations.map do |name, association|
|
80
|
-
association if association.embeddable?
|
81
|
-
end.compact
|
82
|
-
end
|
83
|
-
|
84
|
-
# @private
|
85
|
-
def get_proxy(association)
|
86
|
-
unless proxy = instance_variable_get(association.ivar)
|
87
|
-
proxy = association.proxy_class.new(self, association)
|
88
|
-
instance_variable_set(association.ivar, proxy)
|
89
|
-
end
|
90
|
-
proxy
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
class Association
|
96
|
-
attr_reader :type, :name, :options
|
97
|
-
|
98
|
-
# association options :using, :class_name, :class, :extend,
|
99
|
-
# options that may be added :validate
|
100
|
-
|
101
|
-
def initialize(type, name, options={})
|
102
|
-
@type, @name, @options = type, name, options.to_options
|
103
|
-
end
|
104
|
-
|
105
|
-
def class_name
|
106
|
-
@class_name ||= case
|
107
|
-
when @options[:class_name]
|
108
|
-
@options[:class_name]
|
109
|
-
when @options[:class]
|
110
|
-
@options[:class].to_s
|
111
|
-
when many?
|
112
|
-
@name.to_s.classify
|
113
|
-
else
|
114
|
-
@name.to_s.camelize
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def klass
|
119
|
-
@klass ||= options[:class] || class_name.constantize
|
120
|
-
end
|
121
|
-
|
122
|
-
def many?
|
123
|
-
@type == :many
|
124
|
-
end
|
125
|
-
|
126
|
-
def one?
|
127
|
-
@type == :one
|
128
|
-
end
|
129
|
-
|
130
|
-
def embeddable?
|
131
|
-
klass.embeddable?
|
132
|
-
end
|
133
|
-
|
134
|
-
def polymorphic?
|
135
|
-
false
|
136
|
-
end
|
137
|
-
|
138
|
-
def ivar
|
139
|
-
"@_#{name}"
|
140
|
-
end
|
141
|
-
|
142
|
-
def proxy_class
|
143
|
-
return @proxy_class if defined?(@proxy_class)
|
144
|
-
proxy_class_name.constantize
|
145
|
-
end
|
146
|
-
|
147
|
-
def proxy_class_name
|
148
|
-
@using ||= options[:using] || (embeddable? ? :embedded : :link)
|
149
|
-
klass_name = (many? ? 'Many' : 'One') + @using.to_s.camelize + ('Polymorphic' if polymorphic?).to_s + 'Proxy'
|
150
|
-
"Ripple::Document::Associations::#{klass_name}"
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
require 'ripple'
|
15
|
-
|
16
|
-
module Ripple
|
17
|
-
module Document
|
18
|
-
module Associations
|
19
|
-
module Many
|
20
|
-
include Instantiators
|
21
|
-
|
22
|
-
def to_ary
|
23
|
-
load_target
|
24
|
-
Array === target ? target.to_ary : Array(target)
|
25
|
-
end
|
26
|
-
|
27
|
-
def count
|
28
|
-
load_target
|
29
|
-
target.size
|
30
|
-
end
|
31
|
-
|
32
|
-
def reset
|
33
|
-
super
|
34
|
-
@target = []
|
35
|
-
end
|
36
|
-
|
37
|
-
def <<
|
38
|
-
raise NotImplementedError
|
39
|
-
end
|
40
|
-
alias_method :push, :<<
|
41
|
-
alias_method :concat, :<<
|
42
|
-
|
43
|
-
protected
|
44
|
-
def instantiate_target(instantiator, attrs={})
|
45
|
-
doc = klass.send(instantiator, attrs)
|
46
|
-
self << doc
|
47
|
-
doc
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
require 'ripple'
|
15
|
-
|
16
|
-
module Ripple
|
17
|
-
module Document
|
18
|
-
module Associations
|
19
|
-
class ManyEmbeddedProxy < Proxy
|
20
|
-
include Many
|
21
|
-
include Embedded
|
22
|
-
|
23
|
-
def <<(docs)
|
24
|
-
load_target
|
25
|
-
assign_references(docs)
|
26
|
-
@target += Array(docs)
|
27
|
-
self
|
28
|
-
end
|
29
|
-
|
30
|
-
def replace(docs)
|
31
|
-
@_docs = docs.map { |doc| attrs = doc.respond_to?(:attributes_for_persistence) ? doc.attributes_for_persistence : doc }
|
32
|
-
assign_references(docs)
|
33
|
-
reset
|
34
|
-
@_docs
|
35
|
-
end
|
36
|
-
|
37
|
-
protected
|
38
|
-
def find_target
|
39
|
-
(@_docs || []).map do |attrs|
|
40
|
-
klass.instantiate(attrs).tap do |doc|
|
41
|
-
assign_references(doc)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,125 +0,0 @@
|
|
1
|
-
# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
require 'ripple'
|
15
|
-
|
16
|
-
module Ripple
|
17
|
-
module Document
|
18
|
-
module Associations
|
19
|
-
class Proxy
|
20
|
-
alias :proxy_respond_to? :respond_to?
|
21
|
-
alias :proxy_extend :extend
|
22
|
-
|
23
|
-
instance_methods.each { |m| undef_method m unless m =~ /(^__|^nil\?$|^send$|proxy_|^object_id$)/ }
|
24
|
-
|
25
|
-
attr_reader :owner, :reflection, :target
|
26
|
-
|
27
|
-
alias :proxy_owner :owner
|
28
|
-
alias :proxy_target :target
|
29
|
-
alias :proxy_reflection :reflection
|
30
|
-
|
31
|
-
delegate :klass, :to => :proxy_reflection
|
32
|
-
delegate :options, :to => :proxy_reflection
|
33
|
-
delegate :collection, :to => :klass
|
34
|
-
|
35
|
-
def initialize(owner, reflection)
|
36
|
-
@owner, @reflection = owner, reflection
|
37
|
-
Array(reflection.options[:extend]).each { |ext| proxy_extend(ext) }
|
38
|
-
reset
|
39
|
-
end
|
40
|
-
|
41
|
-
def inspect
|
42
|
-
load_target
|
43
|
-
target.inspect
|
44
|
-
end
|
45
|
-
|
46
|
-
def loaded?
|
47
|
-
@loaded
|
48
|
-
end
|
49
|
-
|
50
|
-
def loaded
|
51
|
-
@loaded = true
|
52
|
-
end
|
53
|
-
|
54
|
-
def nil?
|
55
|
-
load_target
|
56
|
-
target.nil?
|
57
|
-
end
|
58
|
-
|
59
|
-
def blank?
|
60
|
-
load_target
|
61
|
-
target.blank?
|
62
|
-
end
|
63
|
-
|
64
|
-
def present?
|
65
|
-
load_target
|
66
|
-
target.present?
|
67
|
-
end
|
68
|
-
|
69
|
-
def reload
|
70
|
-
reset
|
71
|
-
load_target
|
72
|
-
self unless target.nil?
|
73
|
-
end
|
74
|
-
|
75
|
-
def replace(v)
|
76
|
-
raise NotImplementedError
|
77
|
-
end
|
78
|
-
|
79
|
-
def reset
|
80
|
-
@loaded = false
|
81
|
-
@target = nil
|
82
|
-
end
|
83
|
-
|
84
|
-
def respond_to?(*args)
|
85
|
-
proxy_respond_to?(*args) || (load_target && target.respond_to?(*args))
|
86
|
-
end
|
87
|
-
|
88
|
-
def send(method, *args, &block)
|
89
|
-
if proxy_respond_to?(method)
|
90
|
-
super
|
91
|
-
else
|
92
|
-
load_target
|
93
|
-
target.send(method, *args, &block)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def ===(other)
|
98
|
-
load_target
|
99
|
-
other === target
|
100
|
-
end
|
101
|
-
|
102
|
-
protected
|
103
|
-
def method_missing(method, *args, &block)
|
104
|
-
if load_target
|
105
|
-
if block_given?
|
106
|
-
target.send(method, *args) { |*block_args| block.call(*block_args) }
|
107
|
-
else
|
108
|
-
target.send(method, *args)
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def load_target
|
114
|
-
@target = find_target unless loaded?
|
115
|
-
loaded
|
116
|
-
@target
|
117
|
-
end
|
118
|
-
|
119
|
-
def find_target
|
120
|
-
raise NotImplementedError
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|