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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43ef2e1477e6beffbec678f4c31acc3241a794ad
4
- data.tar.gz: 788921033b3c8382f2cde430cb88615ed5c8f635
3
+ metadata.gz: abdc961579921259954a9b5aeaefc1e72810132d
4
+ data.tar.gz: e7382476833deae39de854bd635ceee458cec3a1
5
5
  SHA512:
6
- metadata.gz: 017568ff0ce6ae5a466355456dc204f30de207a80d4d84c4138fa8b64de9073d36cb6216736b29ca23777c46d1206bcb3befe4caca1d16e95915c120495317f0
7
- data.tar.gz: 3f3dddc10a340f2491d9f8dd912decfbb91271b3d91869afd9e77536e5414f13d5732f485629020b8a6a8b8228b56732505392ed04ef4c3f8d5513a546f0e7e2
6
+ metadata.gz: aae9632a349d97d82bd0fd880db3a0e7d18b280713837b5b93296ec02608115f677a323bc84236b0ffe256986da74b451e66f871dee0240185a26f9818b55c8d
7
+ data.tar.gz: ee6c552f2673dbf3761a87e03595d3a2fc6f004af71f00d1a48aa0e9019aee7fc0c4e2559e5f24cc0827d1f3fbff0fd643c1f199e6305a6722b6b5e50ed4b10b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- method_annotation (0.4.0)
4
+ method_annotation (0.4.1)
5
5
  activesupport (~> 4.2.3)
6
6
 
7
7
  GEM
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.
@@ -11,6 +11,7 @@ module MethodAnnotation
11
11
  eager_autoload do
12
12
  autoload :Async
13
13
  autoload :Cache
14
+ autoload :Lazy
14
15
  autoload :Trace
15
16
  autoload :WillImplemented
16
17
  end
@@ -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
+
@@ -1,3 +1,3 @@
1
1
  module MethodAnnotation
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
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.0
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-06 00:00:00.000000000 Z
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