lazy_methods 1.0.3 → 1.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/VERSION +1 -1
- data/lazy_methods.gemspec +2 -2
- data/lib/lazy_methods/lazy_methods.rb +5 -4
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.4
|
data/lazy_methods.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{lazy_methods}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.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 = ["Brian Durand"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-24}
|
13
13
|
s.description = %q{Gem that adds lazy method wrapping to every object. Preceding any method with lazy_ will defer the invocation until the result is actually needed. This pattern is useful when used with caching systems.}
|
14
14
|
s.email = %q{brian@embellishedvisions.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -11,9 +11,10 @@ module LazyMethods
|
|
11
11
|
|
12
12
|
# Override missing method to add the lazy method handling
|
13
13
|
def method_missing_with_lazy (method, *args, &block)
|
14
|
-
|
14
|
+
method = method.to_s
|
15
|
+
if method[0, 5] == 'lazy_'
|
15
16
|
method = method.to_s
|
16
|
-
return Proxy.new(self, method[5, method.length]
|
17
|
+
return Proxy.new(self, method[5, method.length], args, &block)
|
17
18
|
else
|
18
19
|
# Keep track of the current missing method calls to keep out of an infinite loop
|
19
20
|
stack = Thread.current[:lazy_method_missing_methods] ||= []
|
@@ -48,7 +49,7 @@ module LazyMethods
|
|
48
49
|
# The proxy object does all the heavy lifting.
|
49
50
|
class Proxy
|
50
51
|
# These methods we don't want to override. All other existing methods will be redefined.
|
51
|
-
PROTECTED_METHODS = %w(initialize __proxy_result__ __proxy_loaded__ method_missing)
|
52
|
+
PROTECTED_METHODS = %w(initialize __proxy_result__ __proxy_loaded__ method_missing __send__ object_id)
|
52
53
|
|
53
54
|
def initialize (obj, method, args = nil, &block)
|
54
55
|
@object = obj
|
@@ -58,7 +59,7 @@ module LazyMethods
|
|
58
59
|
|
59
60
|
# Override already defined methods on Object to proxy them to the result object
|
60
61
|
methods.each do |m|
|
61
|
-
eval "def self.#{m} (*args, &block); __proxy_result__.send(:#{m}, *args, &block); end" unless PROTECTED_METHODS.include?(m)
|
62
|
+
eval "def self.#{m} (*args, &block); __proxy_result__.send(:#{m}, *args, &block); end" unless PROTECTED_METHODS.include?(m.to_s)
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy_methods
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 4
|
10
|
+
version: 1.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian Durand
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-24 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|