method_annotation 0.1.0 → 0.1.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: 50ca39e5550c0558a052b033392152609b16fe44
4
- data.tar.gz: db0c10bf08d8359be47e4fd6d26ccf0319ae8ce6
3
+ metadata.gz: 0802696a0b56864210fca87400a1eed6cb3d2a55
4
+ data.tar.gz: 77796f9574b8e5960eaed6124b83d37ef40bd7b8
5
5
  SHA512:
6
- metadata.gz: 49df694fcde6fed0de4f1540bc519062abf73ae46a8028614fec7de36cb45437fc650a602f135446993ca85282335ad720ebc46eb150bf08a0f8f07c0d477c5b
7
- data.tar.gz: 7dd58f1e8398f54519b89b301883c4a7a0646cf7e28495f32f15d4a6ddae7f7dc42f5d6de95a44a27397ce1550bcde2da1a1007be87cc6215d77986787c27385
6
+ metadata.gz: e4a3cb331d6df26e4e388478f962c30f93e51b2cf7046b757e3f41b1d0d19c9eeb5e1d8bc44547f1bd2919824584476155fc0e2b02866d2f688bd0a0686de94a
7
+ data.tar.gz: f7416d92b49837291247be07fe0f5cd00df3c73c438a8728d914bfaaa9dd9a9b98567356b757d74e0bb07ab745a4a097c2d7f1cc6ee29b30c5c1be896b6ffe3c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- method_annotation (0.1.0)
4
+ method_annotation (0.1.1)
5
5
  activesupport (~> 4.2.3)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # MethodAnnotation
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/method_annotation`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ MethodAnnotation You can define the Chuwake function method.
4
+ Note translation function can also be added simply tagged to only cross-processing from applications.
6
5
 
7
6
  ## Installation
8
7
 
@@ -12,17 +11,222 @@ Add this line to your application's Gemfile:
12
11
  gem 'method_annotation'
13
12
  ```
14
13
 
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
14
+ install it yourself as:
20
15
 
21
16
  $ gem install method_annotation
22
17
 
23
18
  ## Usage
24
19
 
25
- TODO: Write usage instructions here
20
+ First, let's create your MethodAnnotation class
21
+
22
+ require 'method_annotation'
23
+
24
+ class MyMethodAnnotation < MethodAnnotation::Base
25
+ end
26
+
27
+ Next, let's add your class to the method
28
+
29
+ class Foo
30
+ # To include a MethodAnnotation::Enable to enable MethodAnnotation
31
+ include MethodAnnotation::Enable
32
+
33
+ # write "#{your annotation class}.name.underscore"
34
+ # ex) MyMethodAnnotation => my_method_annotation
35
+ my_method_annotation
36
+ def bar
37
+ end
38
+ end
39
+
40
+ You can define an annotation in this way
41
+
42
+
43
+ About MethodAnnotation
44
+ - .describe .description
45
+
46
+ You can set forth a description
47
+
48
+ class MyMethodAnnotation < MethodAnnotation::Base
49
+ describe 'sample annotation'
50
+ end
51
+
52
+ MyMethodAnnotation.description
53
+ => "sample annotation"
54
+
55
+ - .list
56
+
57
+ Your class that defines your class, you get a list of methods
58
+
59
+ MyMethodAnnotation.list
60
+ => [[Foo, :bar]]
61
+
62
+ - .before
63
+
64
+ You can define the processing to be performed in method execution before the target
65
+
66
+ class MyMethodAnnotation < MethodAnnotation::Base
67
+ # args is the argument of the method of target
68
+ before do |*args|
69
+ puts 'before'
70
+ end
71
+ end
72
+
73
+ class Foo
74
+ include MethodAnnotation::Enable
75
+
76
+ my_method_annotation
77
+ def bar
78
+ puts 'bar'
79
+ end
80
+ end
81
+
82
+ Foo.new.bar
83
+ => before
84
+ => bar
85
+
86
+ - .after
87
+
88
+ You can define the processing to be performed in method execution after the target
89
+
90
+ class MyMethodAnnotation < MethodAnnotation::Base
91
+ # args is the argument of the method of target
92
+ after do |*args|
93
+ puts 'after'
94
+ end
95
+ end
96
+
97
+ class Foo
98
+ include MethodAnnotation::Enable
99
+
100
+ my_method_annotation
101
+ def bar
102
+ puts 'bar'
103
+ end
104
+ end
105
+
106
+ Foo.new.bar
107
+ => bar
108
+ => after
109
+
110
+ - .around
111
+
112
+ It is possible to define a process that encompasses the method of the target
113
+
114
+ class MyMethodAnnotation < MethodAnnotation::Base
115
+ # original is proc methods of target
116
+ around do |original, *args|
117
+ puts 'before'
118
+ original.call(*args)
119
+ puts 'after'
120
+ end
121
+ end
122
+
123
+ class Foo
124
+ include MethodAnnotation::Enable
125
+
126
+ my_method_annotation
127
+ def bar
128
+ puts 'bar'
129
+ end
130
+ end
131
+
132
+ Foo.new.bar
133
+ => before
134
+ => bar
135
+ => after
136
+
137
+ Example1
138
+
139
+ class PutsArg < MethodAnnotation::Base
140
+ describe 'output the arguments of the method'
141
+
142
+ before do |*args|
143
+ puts '-------args-------'
144
+ puts args
145
+ puts '------------------'
146
+ end
147
+ end
148
+
149
+ PutsArg.description
150
+ => "output the arguments of the method"
151
+
152
+ class Foo
153
+ include MethodAnnotation::Enable
154
+
155
+ # write "#{your annotation class}.name.underscore"
156
+ puts_arg
157
+ def hoge(arg1, arg2)
158
+ puts 'hoge'
159
+ end
160
+
161
+ puts_arg
162
+ def hogehoge(a: nil, b: nil)
163
+ puts 'hogehoge'
164
+ end
165
+ end
166
+
167
+ Foo.new.hoge('abc', 123)
168
+ => -------args-------
169
+ => abc
170
+ => 123
171
+ => ------------------
172
+ => hoge
173
+
174
+ Foo.new.hogehoge(a: 'xyz')
175
+ => -------args-------
176
+ => {:a=>"xyz"}
177
+ => ------------------
178
+ => hogehoge
179
+
180
+ Example2
181
+
182
+ class TimeMeasurement < MethodAnnotation::Base
183
+ describe 'measure the processing time of the method'
184
+
185
+ around do |original, *args|
186
+ start = Time.now
187
+ original.call(*args)
188
+ puts "#{Time.now - start} sec"
189
+ end
190
+ end
191
+
192
+ class Bar
193
+ include MethodAnnotation::Enable
194
+
195
+ time_measurement
196
+ def hoge(sleep_sec)
197
+ sleep sleep_sec
198
+ end
199
+ end
200
+
201
+ Bar.new.hoge(5)
202
+ => 5.001199044 sec
203
+
204
+ Example3
205
+
206
+ class ArgsToString < MethodAnnotation::Base
207
+ describe 'convert the arguments to string'
208
+
209
+ around do |original, *args|
210
+ original.call(*args.map(&:to_s))
211
+ end
212
+ end
213
+
214
+ class Baz
215
+ include MethodAnnotation::Enable
216
+
217
+ args_to_string
218
+ time_measurement
219
+ def hoge(arg1, arg2)
220
+ puts "arg1.class: #{arg1.class}"
221
+ puts "arg2.class: #{arg2.class}"
222
+ sleep 3
223
+ end
224
+ end
225
+
226
+ Baz.new.hoge(123, { a: 'A' })
227
+ => arg1.class: String
228
+ => arg2.class: String
229
+ => 3.000860474 sec
26
230
 
27
231
  ## Development
28
232
 
@@ -1,3 +1,3 @@
1
1
  module MethodAnnotation
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.required_ruby_version = Gem::Requirement.create('2.2.1')
22
+
21
23
  #if spec.respond_to?(:metadata)
22
24
  # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
23
25
  #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.1.0
4
+ version: 0.1.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: 2015-12-10 00:00:00.000000000 Z
11
+ date: 2015-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,9 +91,9 @@ require_paths:
91
91
  - lib
92
92
  required_ruby_version: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 2.2.1
97
97
  required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  requirements:
99
99
  - - ">="