simple-annotations 0.9.0
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.
- checksums.yaml +7 -0
- data/AUTHORS +7 -0
- data/COPYRIGHT +23 -0
- data/Gemfile +5 -0
- data/Rakefile +58 -0
- data/coding_convention.yml +25 -0
- data/lib/simple-annotations.rb +129 -0
- data/simple-annotations.gemspec +24 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5d62a412404c8d41cb4230098c827cba940e6362353a20dd02da71a40acb15f7
|
4
|
+
data.tar.gz: 993681e8e609eec8994bc7d2083e0509d57d871ceb4ffa3692c458cded56cd75
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fedf3e96c67d342b2aab34c89ebe0aa7aa433420fd4cb9d74abc1115fc06ed36aaf6d22f72b1b103eb0f9db1e9bdb29ac6cbe7976e240a369897653ab2cddcd6
|
7
|
+
data.tar.gz: 51575e47217422cf4eb9aaa904a58ae3b80bcd8f4695d6fc12fdbb03c45e99b3874d68cc065f7e2a05070a9934bb7ff4b88a694db4ccb4a95c732841f4bffaef
|
data/AUTHORS
ADDED
data/COPYRIGHT
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
simple-annotations Copyright (c) 2021 Ultragreen Software, Romain GEORGES
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions
|
6
|
+
are met:
|
7
|
+
1. Redistributions of source code must retain the above copyright
|
8
|
+
notice, this list of conditions and the following disclaimer.
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer in the
|
11
|
+
documentation and/or other materials provided with the distribution.
|
12
|
+
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
14
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
15
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
16
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
17
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
18
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
19
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
20
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
21
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
22
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
23
|
+
SUCH DAMAGE.
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'rspec'
|
4
|
+
require 'rake'
|
5
|
+
require "rake/clean"
|
6
|
+
require "rubygems/package_task"
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
require 'yard'
|
9
|
+
require 'yard/rake/yardoc_task.rb'
|
10
|
+
require "rake/tasklib"
|
11
|
+
require "roodi"
|
12
|
+
require "roodi_task"
|
13
|
+
|
14
|
+
require "bundler/gem_tasks"
|
15
|
+
|
16
|
+
|
17
|
+
RoodiTask.new() do | t |
|
18
|
+
t.patterns = %w(lib/**/*.rb)
|
19
|
+
t.config = "coding_convention.yml"
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
CLEAN.include('*.tmp','*.old')
|
24
|
+
CLOBBER.include('*.tmp', 'build/*','#*#')
|
25
|
+
|
26
|
+
|
27
|
+
content = File::readlines(File.join(File.dirname(__FILE__), 'simple-annotations.gemspec')).join
|
28
|
+
spec = eval(content)
|
29
|
+
|
30
|
+
RSpec::Core::RakeTask.new('spec')
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
YARD::Rake::YardocTask.new do |t|
|
35
|
+
t.files = [ 'lib/**/*.rb', '-', 'doc/**/*','spec/**/*_spec.rb']
|
36
|
+
t.options += ['--title', "Gem Documentation"]
|
37
|
+
t.options += ['-o', "yardoc"]
|
38
|
+
t.options += ['-r', "doc/manual.rdoc"]
|
39
|
+
end
|
40
|
+
YARD::Config.load_plugin('yard-rspec')
|
41
|
+
|
42
|
+
namespace :yardoc do
|
43
|
+
task :clobber do
|
44
|
+
rm_r "yardoc" rescue nil
|
45
|
+
rm_r ".yardoc" rescue nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
task :clobber => "yardoc:clobber"
|
49
|
+
|
50
|
+
|
51
|
+
Gem::PackageTask.new(spec) do |pkg|
|
52
|
+
pkg.need_tar = true
|
53
|
+
pkg.need_zip = true
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
task :default => [:gem]
|
@@ -0,0 +1,25 @@
|
|
1
|
+
AssignmentInConditionalCheck:
|
2
|
+
CaseMissingElseCheck:
|
3
|
+
ClassLineCountCheck:
|
4
|
+
line_count: 300
|
5
|
+
ClassNameCheck:
|
6
|
+
pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
|
7
|
+
#ClassVariableCheck:
|
8
|
+
CyclomaticComplexityBlockCheck:
|
9
|
+
complexity: 4
|
10
|
+
CyclomaticComplexityMethodCheck:
|
11
|
+
complexity: 10
|
12
|
+
EmptyRescueBodyCheck:
|
13
|
+
ForLoopCheck:
|
14
|
+
MethodLineCountCheck:
|
15
|
+
line_count: 30
|
16
|
+
MethodNameCheck:
|
17
|
+
pattern: !ruby/regexp /^[_a-z<>=\[|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/
|
18
|
+
# MissingForeignKeyIndexCheck:
|
19
|
+
ModuleLineCountCheck:
|
20
|
+
line_count: 500
|
21
|
+
ModuleNameCheck:
|
22
|
+
pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
|
23
|
+
ParameterNumberCheck:
|
24
|
+
parameter_count: 5
|
25
|
+
|
@@ -0,0 +1,129 @@
|
|
1
|
+
module Annotations
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
RESERVED_ANNOTATIONS = [:after, :before]
|
6
|
+
|
7
|
+
def self.included(klass)
|
8
|
+
klass.extend(ClassMethods)
|
9
|
+
end
|
10
|
+
|
11
|
+
def annotations(meth=nil)
|
12
|
+
|
13
|
+
annotation = AnnotationMonitor::registered[self.class.to_s.to_sym]
|
14
|
+
return annotation[meth] if meth
|
15
|
+
annotation
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def hooks(meth=nil)
|
20
|
+
if meth then
|
21
|
+
return annotations(meth).select {|item,val| RESERVED_ANNOTATIONS.include? item }
|
22
|
+
else
|
23
|
+
res = Hash::new
|
24
|
+
annotations.keys.each {|val| res[val] = annotations[val].select{|item,val| RESERVED_ANNOTATIONS.include? item }}
|
25
|
+
return res
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def fields(meth=nil)
|
30
|
+
if meth then
|
31
|
+
return annotations(meth).select {|item,val| RESERVED_ANNOTATIONS.include? item }
|
32
|
+
else
|
33
|
+
res = Hash::new
|
34
|
+
annotations.keys.each {|val| res[val] = annotations[val].select{|item,val| not RESERVED_ANNOTATIONS.include? item }}
|
35
|
+
return res
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
module ClassMethods
|
41
|
+
def annotations(meth=nil)
|
42
|
+
|
43
|
+
return AnnotationMonitor::registered[self.class.to_s.to_sym][meth] if meth
|
44
|
+
AnnotationMonitor::registered[self.to_s.to_sym]
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def method_added(m)
|
50
|
+
AnnotationMonitor::registered[self.to_s.to_sym][m] = @last_annotations if @last_annotations
|
51
|
+
@last_annotations = nil
|
52
|
+
super
|
53
|
+
end
|
54
|
+
|
55
|
+
def method_missing(meth, *args)
|
56
|
+
return super unless /\A§/ =~ meth
|
57
|
+
@last_annotations ||= {}
|
58
|
+
if args.size == 0
|
59
|
+
@last_annotations[meth[1..-1].to_sym] = true
|
60
|
+
elsif args.size == 1
|
61
|
+
@last_annotations[meth[1..-1].to_sym] = args.first
|
62
|
+
else
|
63
|
+
@last_annotations[meth[1..-1].to_sym] = args
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
class AnnotationMonitor
|
72
|
+
@@annotated ={}
|
73
|
+
@@before = TracePoint.new(:call) do |tp|
|
74
|
+
|
75
|
+
selected_class = tp.defined_class.to_s.to_sym
|
76
|
+
called_method = tp.method_id
|
77
|
+
if AnnotationMonitor::registered.include? selected_class then
|
78
|
+
annotations = AnnotationMonitor::registered[selected_class][called_method]
|
79
|
+
if annotations.include? :before then
|
80
|
+
annotations[:before].call
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
@@after = TracePoint.new(:return) do |tp|
|
87
|
+
|
88
|
+
selected_class = tp.defined_class.to_s.to_sym
|
89
|
+
called_method = tp.method_id
|
90
|
+
if AnnotationMonitor::registered.include? selected_class then
|
91
|
+
annotations = AnnotationMonitor::registered[selected_class][called_method]
|
92
|
+
if annotations.include? :after then
|
93
|
+
annotations[:after].call
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
@@after.enable unless @@after.enabled?
|
100
|
+
@@before.enable unless @@before.enabled?
|
101
|
+
|
102
|
+
def AnnotationMonitor::register(aClass)
|
103
|
+
@@annotated[aClass] = {}
|
104
|
+
end
|
105
|
+
|
106
|
+
def AnnotationMonitor::registered
|
107
|
+
return @@annotated
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
module AnnotationRefinement
|
114
|
+
refine Module do
|
115
|
+
private
|
116
|
+
|
117
|
+
def annotate!
|
118
|
+
AnnotationMonitor::register(self.to_s.to_sym)
|
119
|
+
include Annotations
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{simple-annotations}
|
3
|
+
s.author = "Romain GEORGES"
|
4
|
+
s.version = "0.9.0"
|
5
|
+
s.date = "2021-12-27"
|
6
|
+
s.summary = "Simple method annotations like in java or Python methods decorators"
|
7
|
+
s.email = "romain@ultragreen.net"
|
8
|
+
s.homepage = "http://www.ultragreen.net"
|
9
|
+
s.description = "Simple method annotations like in java or Python methods decorators"
|
10
|
+
s.files = `git ls-files`.split($/)
|
11
|
+
s.required_ruby_version = '~> 2.7.0'
|
12
|
+
s.add_development_dependency "rspec", "~> 3.10"
|
13
|
+
s.add_development_dependency "roodi", "~> 5.0"
|
14
|
+
s.add_development_dependency "rake", "~> 12.3"
|
15
|
+
s.add_development_dependency "yard", "~> 0.9"
|
16
|
+
s.add_development_dependency "yard-rspec", "~> 0.1"
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.require_paths << 'bin'
|
19
|
+
s.bindir = 'bin'
|
20
|
+
s.executables = Dir["bin/*"].map!{|item| item.gsub("bin/","")}
|
21
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
22
|
+
s.license = "BSD-2-Clause"
|
23
|
+
end
|
24
|
+
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple-annotations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Romain GEORGES
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: roodi
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: yard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.1'
|
83
|
+
description: Simple method annotations like in java or Python methods decorators
|
84
|
+
email: romain@ultragreen.net
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- AUTHORS
|
90
|
+
- COPYRIGHT
|
91
|
+
- Gemfile
|
92
|
+
- Rakefile
|
93
|
+
- coding_convention.yml
|
94
|
+
- lib/simple-annotations.rb
|
95
|
+
- simple-annotations.gemspec
|
96
|
+
homepage: http://www.ultragreen.net
|
97
|
+
licenses:
|
98
|
+
- BSD-2-Clause
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
- bin
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 2.7.0
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubygems_version: 3.1.2
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Simple method annotations like in java or Python methods decorators
|
120
|
+
test_files: []
|