method_annotation 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +47 -0
- data/lib/method_annotation.rb +1 -0
- data/lib/method_annotation/lazy.rb +31 -0
- data/lib/method_annotation/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abdc961579921259954a9b5aeaefc1e72810132d
|
4
|
+
data.tar.gz: e7382476833deae39de854bd635ceee458cec3a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aae9632a349d97d82bd0fd880db3a0e7d18b280713837b5b93296ec02608115f677a323bc84236b0ffe256986da74b451e66f871dee0240185a26f9818b55c8d
|
7
|
+
data.tar.gz: ee6c552f2673dbf3761a87e03595d3a2fc6f004af71f00d1a48aa0e9019aee7fc0c4e2559e5f24cc0827d1f3fbff0fd643c1f199e6305a6722b6b5e50ed4b10b
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -131,6 +131,31 @@ About MethodAnnotation
|
|
131
131
|
=> bar
|
132
132
|
=> after
|
133
133
|
|
134
|
+
- MethodAnnotation::Async
|
135
|
+
|
136
|
+
It will be performed asynchronously.
|
137
|
+
|
138
|
+
require 'method_annotation'
|
139
|
+
|
140
|
+
class Foo
|
141
|
+
include MethodAnnotation::Enable
|
142
|
+
|
143
|
+
def hoge
|
144
|
+
bar
|
145
|
+
puts 'hoge'
|
146
|
+
end
|
147
|
+
|
148
|
+
async
|
149
|
+
def bar
|
150
|
+
sleep 3
|
151
|
+
puts 'bar'
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
Foo.new.hoge
|
156
|
+
=> hoge
|
157
|
+
=> bar
|
158
|
+
|
134
159
|
- MethodAnnotation::Cache
|
135
160
|
|
136
161
|
It is cached after the second time the execution result of the method is returned from the cache.
|
@@ -156,6 +181,28 @@ About MethodAnnotation
|
|
156
181
|
foo.bar
|
157
182
|
=> "return value"
|
158
183
|
|
184
|
+
- MethodAnnotation::Lazy
|
185
|
+
|
186
|
+
This method is lazy.
|
187
|
+
It will be executed at the timing when trying to use the return value.
|
188
|
+
|
189
|
+
require 'method_annotation'
|
190
|
+
|
191
|
+
class Foo
|
192
|
+
include MethodAnnotation::Enable
|
193
|
+
|
194
|
+
lazy
|
195
|
+
def bar
|
196
|
+
puts 'bar'
|
197
|
+
'return value'
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
value = Foo.new.bar
|
202
|
+
# It is run by the return value is used timing
|
203
|
+
value == 'hogehoge'
|
204
|
+
=> bar
|
205
|
+
|
159
206
|
- MethodAnnotation::WillImplemented
|
160
207
|
|
161
208
|
It method is expected to be implemented.
|
data/lib/method_annotation.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
module MethodAnnotation
|
2
|
+
class Lazy < MethodAnnotation::Base
|
3
|
+
self.annotation_name = 'lazy'
|
4
|
+
self.describe = 'It method is lazy'
|
5
|
+
|
6
|
+
class LazyProxy < BasicObject
|
7
|
+
undef_method(*superclass.instance_methods.select { |method| !method.to_s.start_with?('__') })
|
8
|
+
|
9
|
+
def initialize(param)
|
10
|
+
@param = param
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(message, *args)
|
14
|
+
__target__.__send__(message, *args)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def __target__
|
20
|
+
unless @run
|
21
|
+
@target = @param.original.call(@param)
|
22
|
+
@run = true
|
23
|
+
end
|
24
|
+
@target
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
around { |param| LazyProxy.new(param) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: method_annotation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- masatoshi-watanuki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/method_annotation/base.rb
|
88
88
|
- lib/method_annotation/cache.rb
|
89
89
|
- lib/method_annotation/enable.rb
|
90
|
+
- lib/method_annotation/lazy.rb
|
90
91
|
- lib/method_annotation/parameter.rb
|
91
92
|
- lib/method_annotation/trace.rb
|
92
93
|
- lib/method_annotation/version.rb
|