method_annotation 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +45 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/method_annotation.rb +95 -0
- data/lib/method_annotation/version.rb +3 -0
- data/method_annotation.gemspec +31 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 50ca39e5550c0558a052b033392152609b16fe44
|
4
|
+
data.tar.gz: db0c10bf08d8359be47e4fd6d26ccf0319ae8ce6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 49df694fcde6fed0de4f1540bc519062abf73ae46a8028614fec7de36cb45437fc650a602f135446993ca85282335ad720ebc46eb150bf08a0f8f07c0d477c5b
|
7
|
+
data.tar.gz: 7dd58f1e8398f54519b89b301883c4a7a0646cf7e28495f32f15d4a6ddae7f7dc42f5d6de95a44a27397ce1550bcde2da1a1007be87cc6215d77986787c27385
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
method_annotation (0.1.0)
|
5
|
+
activesupport (~> 4.2.3)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (4.2.5)
|
11
|
+
i18n (~> 0.7)
|
12
|
+
json (~> 1.7, >= 1.7.7)
|
13
|
+
minitest (~> 5.1)
|
14
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
diff-lcs (1.2.5)
|
17
|
+
i18n (0.7.0)
|
18
|
+
json (1.8.3)
|
19
|
+
minitest (5.8.3)
|
20
|
+
rake (10.4.2)
|
21
|
+
rspec (3.4.0)
|
22
|
+
rspec-core (~> 3.4.0)
|
23
|
+
rspec-expectations (~> 3.4.0)
|
24
|
+
rspec-mocks (~> 3.4.0)
|
25
|
+
rspec-core (3.4.1)
|
26
|
+
rspec-support (~> 3.4.0)
|
27
|
+
rspec-expectations (3.4.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.4.0)
|
30
|
+
rspec-mocks (3.4.0)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.4.0)
|
33
|
+
rspec-support (3.4.1)
|
34
|
+
thread_safe (0.3.5)
|
35
|
+
tzinfo (1.2.2)
|
36
|
+
thread_safe (~> 0.1)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
bundler (~> 1.9)
|
43
|
+
method_annotation!
|
44
|
+
rake (~> 10.0)
|
45
|
+
rspec
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# MethodAnnotation
|
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
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'method_annotation'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install method_annotation
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/method_annotation/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "method_annotation"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require "method_annotation/version"
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_support/core_ext'
|
4
|
+
|
5
|
+
module MethodAnnotation
|
6
|
+
class Base
|
7
|
+
class << self
|
8
|
+
attr_accessor :before_procs, :after_procs, :around_procs, :list
|
9
|
+
|
10
|
+
def describe(desc)
|
11
|
+
@desc = desc
|
12
|
+
end
|
13
|
+
|
14
|
+
def description
|
15
|
+
@desc
|
16
|
+
end
|
17
|
+
|
18
|
+
def before(&block)
|
19
|
+
(@before_procs ||= []) << block
|
20
|
+
end
|
21
|
+
|
22
|
+
def after(&block)
|
23
|
+
(@after_procs ||= []) << block
|
24
|
+
end
|
25
|
+
|
26
|
+
def around(&block)
|
27
|
+
(@around_procs ||= []) << block
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
concern :Enable do
|
33
|
+
def self.included(klass)
|
34
|
+
Module.new.tap do |mod|
|
35
|
+
klass.prepend(mod)
|
36
|
+
klass._prepended_module = mod
|
37
|
+
end
|
38
|
+
|
39
|
+
# includeしたクラスが継承された場合もMethodAnnotaionを有効にする
|
40
|
+
klass.class_eval do
|
41
|
+
def self.inherited(subclass)
|
42
|
+
Module.new.tap do |mod|
|
43
|
+
subclass.prepend(mod)
|
44
|
+
subclass._prepended_module = mod
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class_methods do
|
51
|
+
attr_accessor :_prepended_module, :_annotations
|
52
|
+
|
53
|
+
def method_added(name)
|
54
|
+
if @_annotations.present?
|
55
|
+
annotations = @_annotations
|
56
|
+
_prepended_module.module_eval do
|
57
|
+
|
58
|
+
define_method(name) do |*args, &block|
|
59
|
+
annotation_map = annotations.each_with_object({}) do |annotation, hash|
|
60
|
+
# 宣言した[class, method_name]をリストに追加する
|
61
|
+
(annotation.list ||= []) << [self.class, name.to_sym]
|
62
|
+
%i(before_procs around_procs after_procs).each do |proc_name|
|
63
|
+
(hash[proc_name] ||= []).push(*annotation.send(proc_name))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
annotation_map[:before_procs].try(:each) { |blk| instance_exec(*args, &blk) }
|
68
|
+
original = ->(*params) { instance_eval { super(*params, &block) } }
|
69
|
+
if annotation_map[:around_procs].present?
|
70
|
+
chain = annotation_map[:around_procs].reverse.inject(original) do |block_chain, blk|
|
71
|
+
->(*params) { instance_exec(block_chain, *params, &blk) }
|
72
|
+
end
|
73
|
+
instance_exec(*args, &chain)
|
74
|
+
else
|
75
|
+
original.call(*args)
|
76
|
+
end
|
77
|
+
annotation_map[:after_procs].try(:each) { |blk| instance_exec(*args, &blk) }
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
@_annotations = nil
|
83
|
+
end
|
84
|
+
|
85
|
+
def method_missing(method, *args)
|
86
|
+
annotation = MethodAnnotation::Base.subclasses.find { |c| c.name == method.to_s.classify }
|
87
|
+
if annotation
|
88
|
+
(@_annotations ||= []) << annotation
|
89
|
+
else
|
90
|
+
super
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'method_annotation/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "method_annotation"
|
8
|
+
spec.version = MethodAnnotation::VERSION
|
9
|
+
spec.authors = ["masatoshi-watanuki"]
|
10
|
+
spec.email = ["masatoshi.watanuki@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = 'method annotation'
|
13
|
+
spec.description = 'method annotation'
|
14
|
+
spec.homepage = "https://github.com/masatoshi-watanuki/gems/tree/master/method_annotation"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
#if spec.respond_to?(:metadata)
|
22
|
+
# 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
|
+
#end
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
|
29
|
+
# add
|
30
|
+
spec.add_dependency "activesupport", "~> 4.2.3"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: method_annotation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- masatoshi-watanuki
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 4.2.3
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.2.3
|
69
|
+
description: method annotation
|
70
|
+
email:
|
71
|
+
- masatoshi.watanuki@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- Gemfile
|
77
|
+
- Gemfile.lock
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- bin/console
|
81
|
+
- bin/setup
|
82
|
+
- lib/method_annotation.rb
|
83
|
+
- lib/method_annotation/version.rb
|
84
|
+
- method_annotation.gemspec
|
85
|
+
homepage: https://github.com/masatoshi-watanuki/gems/tree/master/method_annotation
|
86
|
+
licenses: []
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.4.5
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: method annotation
|
108
|
+
test_files: []
|