metannotation 1.0.0rc2 → 2.0.0Beta2
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 +4 -4
- data/.gitignore +11 -11
- data/Gemfile +1 -1
- data/LICENSE.txt +21 -21
- data/README.md +43 -43
- data/Rakefile +10 -10
- data/lib/metannotation.rb +21 -23
- data/lib/metannotation/core_ext/module.rb +10 -18
- data/lib/metannotation/core_ext/string.rb +1 -175
- data/lib/metannotation/define.rb +27 -8
- data/lib/metannotation/version.rb +3 -3
- data/metannotation.gemspec +37 -37
- metadata +2 -3
- data/lib/metannotation/core.rb +0 -50
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 241fb3a4968fc2e7f0214bde05f3d89f6da5f7601e3ae0a0afe21493420c1b2a
|
|
4
|
+
data.tar.gz: d69d4a83d51176fd7f95539f5709fb708db1ebcbcd4c941a098f47308dfe1daf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '09aad7bdf0d99dae987ddcab9b211a24b59f8693ead4fa2b4fe4009bfbf056b443625f08987dccc9ec55133bd883306c101068808c6fcc291f2c8742bb097a56'
|
|
7
|
+
data.tar.gz: 70ef5ad2966133246a4144d712f09c8269a77b47725dddede4527a83c0950b95d6500ba176c968ecf9a98defb2a24ccba3042d9eadc23dc2beec0c59f4a01490
|
data/.gitignore
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/.bundle/
|
|
2
|
-
/.yardoc
|
|
3
|
-
/_yardoc/
|
|
4
|
-
/coverage/
|
|
5
|
-
/doc/
|
|
6
|
-
/pkg/
|
|
7
|
-
/spec/reports/
|
|
8
|
-
/tmp/
|
|
9
|
-
/Gemfile.lock
|
|
10
|
-
/.idea
|
|
11
|
-
/metannotation.iml
|
|
1
|
+
/.bundle/
|
|
2
|
+
/.yardoc
|
|
3
|
+
/_yardoc/
|
|
4
|
+
/coverage/
|
|
5
|
+
/doc/
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/tmp/
|
|
9
|
+
/Gemfile.lock
|
|
10
|
+
/.idea
|
|
11
|
+
/metannotation.iml
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2018 Hdzi
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Hdzi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
# Metannotation
|
|
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/metannotation`. 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 'metannotation'
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
And then execute:
|
|
16
|
-
|
|
17
|
-
$ bundle
|
|
18
|
-
|
|
19
|
-
Or install it yourself as:
|
|
20
|
-
|
|
21
|
-
$ gem install metannotation
|
|
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 `rake test` to run the tests. You can also 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`, which will 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
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/metannotation. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
36
|
-
|
|
37
|
-
## License
|
|
38
|
-
|
|
39
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
40
|
-
|
|
41
|
-
## Code of Conduct
|
|
42
|
-
|
|
43
|
-
Everyone interacting in the Metannotation project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/metannotation/blob/master/CODE_OF_CONDUCT.md).
|
|
1
|
+
# Metannotation
|
|
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/metannotation`. 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 'metannotation'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install metannotation
|
|
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 `rake test` to run the tests. You can also 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`, which will 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
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/metannotation. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
40
|
+
|
|
41
|
+
## Code of Conduct
|
|
42
|
+
|
|
43
|
+
Everyone interacting in the Metannotation project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/metannotation/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
require "bundler/gem_tasks"
|
|
2
|
-
require "rake/testtask"
|
|
3
|
-
|
|
4
|
-
Rake::TestTask.new(:test) do |t|
|
|
5
|
-
t.libs << "test"
|
|
6
|
-
t.libs << "lib"
|
|
7
|
-
t.test_files = FileList["test/**/*_test.rb"]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
task :default => :test
|
|
1
|
+
require "bundler/gem_tasks"
|
|
2
|
+
require "rake/testtask"
|
|
3
|
+
|
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
|
5
|
+
t.libs << "test"
|
|
6
|
+
t.libs << "lib"
|
|
7
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
task :default => :test
|
data/lib/metannotation.rb
CHANGED
|
@@ -12,7 +12,7 @@ require 'metannotation/define'
|
|
|
12
12
|
#
|
|
13
13
|
# class MyClass
|
|
14
14
|
# label MyAnnotation
|
|
15
|
-
#
|
|
15
|
+
# atMyAnnotation def my_method;end
|
|
16
16
|
# end
|
|
17
17
|
#
|
|
18
18
|
# Define and use class-annotation
|
|
@@ -22,39 +22,37 @@ require 'metannotation/define'
|
|
|
22
22
|
# end
|
|
23
23
|
#
|
|
24
24
|
# class YourClass
|
|
25
|
-
#
|
|
25
|
+
# label_self YourAnnotation
|
|
26
26
|
# end
|
|
27
27
|
#
|
|
28
28
|
module Metannotation
|
|
29
|
+
def included(annotation)
|
|
30
|
+
Define.define_annotation(annotation, self)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def check(&block)
|
|
34
|
+
instance_variable_set :@__annotation_check, block
|
|
35
|
+
end
|
|
36
|
+
|
|
29
37
|
# method-annotation
|
|
30
38
|
module Method
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
extend Metannotation
|
|
40
|
+
|
|
41
|
+
check do |fun_sym|
|
|
42
|
+
# check it a method
|
|
43
|
+
raise "Annotation's last parameter must be a method symbol!" unless public_method_defined?(fun_sym) ||
|
|
44
|
+
protected_method_defined?(fun_sym) ||
|
|
45
|
+
private_method_defined?(fun_sym)
|
|
33
46
|
end
|
|
34
47
|
end
|
|
35
48
|
|
|
36
49
|
# class-annotation
|
|
37
50
|
module Class
|
|
38
|
-
|
|
39
|
-
Metannotation.define_annotation(annotation, self)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
class << self
|
|
44
|
-
# Define annotation
|
|
45
|
-
def define_annotation(annotation, type)
|
|
46
|
-
Define.do check_annotation(annotation, type)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
private
|
|
50
|
-
|
|
51
|
-
using StringExt # :nodoc:
|
|
51
|
+
extend Metannotation
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
annotation.define_singleton_method(:annotation_name) {simple_name}
|
|
57
|
-
annotation
|
|
53
|
+
check do |cls|
|
|
54
|
+
# check it a class
|
|
55
|
+
raise "Annotation's last parameter must be a class constant!" unless cls.class.is_a? Module
|
|
58
56
|
end
|
|
59
57
|
end
|
|
60
58
|
end
|
|
@@ -1,30 +1,22 @@
|
|
|
1
1
|
require 'metannotation/core_ext/string'
|
|
2
2
|
|
|
3
3
|
class Module # :nodoc:
|
|
4
|
-
using Metannotation::StringExt # :nodoc:
|
|
5
|
-
|
|
6
4
|
# +label+ an annotation
|
|
7
5
|
# class MyClass
|
|
8
|
-
# label
|
|
6
|
+
# label Annotation1, Annotation2
|
|
9
7
|
# end
|
|
10
|
-
def label(
|
|
11
|
-
|
|
12
|
-
extend annotation
|
|
13
|
-
send(annotation.simple_name, *parm, self) if annotation.annotation_type == Metannotation::Class
|
|
14
|
-
end
|
|
8
|
+
def label(*annotations)
|
|
9
|
+
annotations.each {|annotation| extend annotation}
|
|
15
10
|
end
|
|
16
11
|
|
|
17
|
-
# +
|
|
18
|
-
# use [] if having parameters
|
|
12
|
+
# +label_self+ annotations
|
|
19
13
|
# class MyClass
|
|
20
|
-
#
|
|
14
|
+
# label_self Annotation1, [Annotation2, param]
|
|
21
15
|
# end
|
|
22
|
-
def
|
|
23
|
-
annotations.each
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def simple_name
|
|
28
|
-
@__simple_name ||= to_s.demodulize.underscore.to_sym
|
|
16
|
+
def label_self(*annotations)
|
|
17
|
+
annotations.each do |annotation, *parm|
|
|
18
|
+
extend annotation
|
|
19
|
+
send(annotation.annotation_name, *parm, self)
|
|
20
|
+
end
|
|
29
21
|
end
|
|
30
22
|
end
|
|
@@ -11,186 +11,12 @@ module Metannotation # :nodoc:
|
|
|
11
11
|
#
|
|
12
12
|
# See active_support gem
|
|
13
13
|
def demodulize
|
|
14
|
-
if i = self.rindex('::')
|
|
14
|
+
if (i = self.rindex('::'))
|
|
15
15
|
self[(i + 2)..-1]
|
|
16
16
|
else
|
|
17
17
|
self
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
|
-
|
|
21
|
-
# Makes an underscored, lowercase form from the expression in the string.
|
|
22
|
-
# Changes '::' to '/' to convert namespaces to paths.
|
|
23
|
-
#
|
|
24
|
-
# underscore('ActiveModel') # => "active_model"
|
|
25
|
-
# underscore('ActiveModel::Errors') # => "active_model/errors"
|
|
26
|
-
#
|
|
27
|
-
# See active_support gem
|
|
28
|
-
def underscore
|
|
29
|
-
return self unless self =~ /[A-Z-]|::/
|
|
30
|
-
word = self.gsub('::'.freeze, '/'.freeze)
|
|
31
|
-
word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)((?-mix:(?=a)b))(?=\b|[^a-z])/) {"#{$1 && '_'.freeze }#{$2.downcase}"}
|
|
32
|
-
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2'.freeze)
|
|
33
|
-
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2'.freeze)
|
|
34
|
-
word.tr!("-".freeze, "_".freeze)
|
|
35
|
-
word.downcase!
|
|
36
|
-
word
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
# Converts strings to UpperCamelCase.
|
|
41
|
-
# If the +uppercase_first_letter+ parameter is set to false, then produces
|
|
42
|
-
# lowerCamelCase.
|
|
43
|
-
#
|
|
44
|
-
# Also converts '/' to '::' which is useful for converting
|
|
45
|
-
# paths to namespaces.
|
|
46
|
-
#
|
|
47
|
-
# camelize('active_model') # => "ActiveModel"
|
|
48
|
-
# camelize('active_model', false) # => "activeModel"
|
|
49
|
-
# camelize('active_model/errors') # => "ActiveModel::Errors"
|
|
50
|
-
# camelize('active_model/errors', false) # => "activeModel::Errors"
|
|
51
|
-
#
|
|
52
|
-
# As a rule of thumb you can think of +camelize+ as the inverse of
|
|
53
|
-
# #underscore, though there are cases where that does not hold:
|
|
54
|
-
#
|
|
55
|
-
# camelize(underscore('SSLError')) # => "SslError"
|
|
56
|
-
#
|
|
57
|
-
# See active_support gem
|
|
58
|
-
def camelize(uppercase_first_letter = true)
|
|
59
|
-
if uppercase_first_letter
|
|
60
|
-
string = self.sub(/^[a-z\d]*/) {|match| match.capitalize}
|
|
61
|
-
else
|
|
62
|
-
string = self.sub(/^(?:(?-mix:(?=a)b)(?=\b|[A-Z_])|\w)/) {|match| match.downcase}
|
|
63
|
-
end
|
|
64
|
-
string.gsub!(/(?:_|(\/))([a-z\d]*)/i) {"#{$1}#{$2.capitalize}"}
|
|
65
|
-
string.gsub!('/'.freeze, '::'.freeze)
|
|
66
|
-
string
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
# Returns the plural form of the word in the string.
|
|
70
|
-
#
|
|
71
|
-
# If passed an optional +locale+ parameter, the word will be
|
|
72
|
-
# pluralized using rules defined for that language. By default,
|
|
73
|
-
# this parameter is set to <tt>:en</tt>.
|
|
74
|
-
#
|
|
75
|
-
# pluralize('post') # => "posts"
|
|
76
|
-
# pluralize('octopus') # => "octopi"
|
|
77
|
-
# pluralize('sheep') # => "sheep"
|
|
78
|
-
# pluralize('words') # => "words"
|
|
79
|
-
# pluralize('CamelOctopus') # => "CamelOctopi"
|
|
80
|
-
#
|
|
81
|
-
# See active_support gem
|
|
82
|
-
def pluralize
|
|
83
|
-
rules = [[/(z)ombies$/i, "\\1ombies"],
|
|
84
|
-
[/(z)ombie$/i, "\\1ombies"],
|
|
85
|
-
[/(m)oves$/i, "\\1oves"],
|
|
86
|
-
[/(m)ove$/i, "\\1oves"],
|
|
87
|
-
[/(s)exes$/i, "\\1exes"],
|
|
88
|
-
[/(s)ex$/i, "\\1exes"],
|
|
89
|
-
[/(c)hildren$/i, "\\1hildren"],
|
|
90
|
-
[/(c)hild$/i, "\\1hildren"],
|
|
91
|
-
[/(m)en$/i, "\\1en"],
|
|
92
|
-
[/(m)an$/i, "\\1en"],
|
|
93
|
-
[/(p)eople$/i, "\\1eople"],
|
|
94
|
-
[/(p)erson$/i, "\\1eople"],
|
|
95
|
-
[/(quiz)$/i, "\\1zes"],
|
|
96
|
-
[/^(oxen)$/i, "\\1"],
|
|
97
|
-
[/^(ox)$/i, "\\1en"],
|
|
98
|
-
[/^(m|l)ice$/i, "\\1ice"],
|
|
99
|
-
[/^(m|l)ouse$/i, "\\1ice"],
|
|
100
|
-
[/(matr|vert|ind)(?:ix|ex)$/i, "\\1ices"],
|
|
101
|
-
[/(x|ch|ss|sh)$/i, "\\1es"],
|
|
102
|
-
[/([^aeiouy]|qu)y$/i, "\\1ies"],
|
|
103
|
-
[/(hive)$/i, "\\1s"],
|
|
104
|
-
[/(?:([^f])fe|([lr])f)$/i, "\\1\\2ves"],
|
|
105
|
-
[/sis$/i, "ses"], [/([ti])a$/i, "\\1a"],
|
|
106
|
-
[/([ti])um$/i, "\\1a"],
|
|
107
|
-
[/(buffal|tomat)o$/i, "\\1oes"],
|
|
108
|
-
[/(bu)s$/i, "\\1ses"],
|
|
109
|
-
[/(alias|status)$/i, "\\1es"],
|
|
110
|
-
[/(octop|vir)i$/i, "\\1i"],
|
|
111
|
-
[/(octop|vir)us$/i, "\\1i"],
|
|
112
|
-
[/^(ax|test)is$/i, "\\1es"],
|
|
113
|
-
[/s$/i, "s"], [/$/, "s"]]
|
|
114
|
-
apply_inflections(self, rules)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
# The reverse of #pluralize, returns the singular form of a word in a
|
|
118
|
-
# string.
|
|
119
|
-
#
|
|
120
|
-
# If passed an optional +locale+ parameter, the word will be
|
|
121
|
-
# singularized using rules defined for that language. By default,
|
|
122
|
-
# this parameter is set to <tt>:en</tt>.
|
|
123
|
-
#
|
|
124
|
-
# singularize('posts') # => "post"
|
|
125
|
-
# singularize('octopi') # => "octopus"
|
|
126
|
-
# singularize('sheep') # => "sheep"
|
|
127
|
-
# singularize('word') # => "word"
|
|
128
|
-
# singularize('CamelOctopi') # => "CamelOctopus"
|
|
129
|
-
# singularize('leyes', :es) # => "ley"
|
|
130
|
-
#
|
|
131
|
-
# See active_support gem
|
|
132
|
-
def singularize
|
|
133
|
-
rules = [[/(z)ombies$/i, "\\1ombie"],
|
|
134
|
-
[/(z)ombie$/i, "\\1ombie"],
|
|
135
|
-
[/(m)oves$/i, "\\1ove"],
|
|
136
|
-
[/(m)ove$/i, "\\1ove"],
|
|
137
|
-
[/(s)exes$/i, "\\1ex"],
|
|
138
|
-
[/(s)ex$/i, "\\1ex"],
|
|
139
|
-
[/(c)hildren$/i, "\\1hild"],
|
|
140
|
-
[/(c)hild$/i, "\\1hild"],
|
|
141
|
-
[/(m)en$/i, "\\1an"],
|
|
142
|
-
[/(m)an$/i, "\\1an"],
|
|
143
|
-
[/(p)eople$/i, "\\1erson"],
|
|
144
|
-
[/(p)erson$/i, "\\1erson"],
|
|
145
|
-
[/(database)s$/i, "\\1"],
|
|
146
|
-
[/(quiz)zes$/i, "\\1"],
|
|
147
|
-
[/(matr)ices$/i, "\\1ix"],
|
|
148
|
-
[/(vert|ind)ices$/i, "\\1ex"],
|
|
149
|
-
[/^(ox)en/i, "\\1"],
|
|
150
|
-
[/(alias|status)(es)?$/i, "\\1"],
|
|
151
|
-
[/(octop|vir)(us|i)$/i, "\\1us"],
|
|
152
|
-
[/^(a)x[ie]s$/i, "\\1xis"],
|
|
153
|
-
[/(cris|test)(is|es)$/i, "\\1is"],
|
|
154
|
-
[/(shoe)s$/i, "\\1"],
|
|
155
|
-
[/(o)es$/i, "\\1"],
|
|
156
|
-
[/(bus)(es)?$/i, "\\1"],
|
|
157
|
-
[/^(m|l)ice$/i, "\\1ouse"],
|
|
158
|
-
[/(x|ch|ss|sh)es$/i, "\\1"],
|
|
159
|
-
[/(m)ovies$/i, "\\1ovie"],
|
|
160
|
-
[/(s)eries$/i, "\\1eries"],
|
|
161
|
-
[/([^aeiouy]|qu)ies$/i, "\\1y"],
|
|
162
|
-
[/([lr])ves$/i, "\\1f"],
|
|
163
|
-
[/(tive)s$/i, "\\1"],
|
|
164
|
-
[/(hive)s$/i, "\\1"],
|
|
165
|
-
[/([^f])ves$/i, "\\1fe"],
|
|
166
|
-
[/(^analy)(sis|ses)$/i, "\\1sis"],
|
|
167
|
-
[/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, "\\1sis"],
|
|
168
|
-
[/([ti])a$/i, "\\1um"],
|
|
169
|
-
[/(n)ews$/i, "\\1ews"],
|
|
170
|
-
[/(ss)$/i, "\\1"],
|
|
171
|
-
[/s$/i, ""]]
|
|
172
|
-
|
|
173
|
-
apply_inflections(self, rules)
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
private
|
|
177
|
-
|
|
178
|
-
# Applies inflection rules for +singularize+ and +pluralize+.
|
|
179
|
-
#
|
|
180
|
-
# apply_inflections('post', inflections.plurals) # => "posts"
|
|
181
|
-
# apply_inflections('posts', inflections.singulars) # => "post"
|
|
182
|
-
#
|
|
183
|
-
# See active_support gem
|
|
184
|
-
def apply_inflections(word, rules)
|
|
185
|
-
result = word.dup
|
|
186
|
-
|
|
187
|
-
if word.empty?
|
|
188
|
-
result
|
|
189
|
-
else
|
|
190
|
-
rules.each {|(rule, replacement)| break if result.sub!(rule, replacement)}
|
|
191
|
-
result
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
20
|
end
|
|
195
21
|
end
|
|
196
22
|
end
|
data/lib/metannotation/define.rb
CHANGED
|
@@ -1,20 +1,34 @@
|
|
|
1
|
-
require 'metannotation/
|
|
1
|
+
require 'metannotation/core_ext/string'
|
|
2
2
|
|
|
3
3
|
module Metannotation # :nodoc:
|
|
4
4
|
# Define annotation
|
|
5
5
|
module Define
|
|
6
6
|
class << self
|
|
7
7
|
# An interface to define an annotation
|
|
8
|
-
def
|
|
9
|
-
|
|
8
|
+
def define_annotation(annotation, type)
|
|
9
|
+
annotation_reflect annotation, type
|
|
10
|
+
annotation_define annotation, type
|
|
11
|
+
annotation_to_do annotation
|
|
12
|
+
annotation_included annotation
|
|
10
13
|
end
|
|
11
14
|
|
|
12
15
|
private
|
|
13
16
|
|
|
14
17
|
# Define core features
|
|
15
|
-
def annotation_define(annotation)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
def annotation_define(annotation, type)
|
|
19
|
+
annotation.send :define_method, annotation.annotation_name do |*args, target|
|
|
20
|
+
# check target a method or a class or a other
|
|
21
|
+
instance_exec(target, &type.instance_variable_get(:@__annotation_check))
|
|
22
|
+
# execute annotation's +to_do_block+
|
|
23
|
+
# An annotation can include another annotations, all same type included annotations's +to_do_block+
|
|
24
|
+
# will be execute.
|
|
25
|
+
annotation.included_modules.unshift(annotation).each do |super_annotation|
|
|
26
|
+
class_exec(target, annotation, *args, &super_annotation.annotated_do) if super_annotation.singleton_class.method_defined?(:annotated_do) and
|
|
27
|
+
super_annotation.annotation_type == annotation.annotation_type
|
|
28
|
+
end
|
|
29
|
+
# an1 an2 target
|
|
30
|
+
target
|
|
31
|
+
end
|
|
18
32
|
end
|
|
19
33
|
|
|
20
34
|
# Define +to+ method that will be execute when annotate target
|
|
@@ -24,7 +38,6 @@ module Metannotation # :nodoc:
|
|
|
24
38
|
annotation.singleton_class.send(:attr_accessor, :annotated_do)
|
|
25
39
|
annotation.annotated_do = block
|
|
26
40
|
end
|
|
27
|
-
annotation
|
|
28
41
|
end
|
|
29
42
|
|
|
30
43
|
# Define what to do when annotation includes another annotation
|
|
@@ -37,7 +50,13 @@ module Metannotation # :nodoc:
|
|
|
37
50
|
annotation.define_singleton_method(:included) do |sub_annotation|
|
|
38
51
|
sub_annotation.include annotation.annotation_type unless sub_annotation.respond_to? :annotation_type
|
|
39
52
|
end
|
|
40
|
-
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
using StringExt
|
|
56
|
+
# Define some variables and methods that provide annotation information in the module
|
|
57
|
+
def annotation_reflect(annotation, type)
|
|
58
|
+
annotation.define_singleton_method(:annotation_type) {type}
|
|
59
|
+
annotation.define_singleton_method(:annotation_name) {"at#{to_s.demodulize}"}
|
|
41
60
|
end
|
|
42
61
|
end
|
|
43
62
|
end
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module Metannotation
|
|
2
|
-
VERSION = "
|
|
3
|
-
end
|
|
1
|
+
module Metannotation
|
|
2
|
+
VERSION = "2.0.0Beta2"
|
|
3
|
+
end
|
data/metannotation.gemspec
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
lib = File.expand_path("../lib", __FILE__)
|
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
-
require "metannotation/version"
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name = "metannotation"
|
|
7
|
-
spec.version = Metannotation::VERSION
|
|
8
|
-
spec.authors = ["Hdzi"]
|
|
9
|
-
spec.email = ["taojinhou@qq.com"]
|
|
10
|
-
|
|
11
|
-
spec.summary = %q{Ruby Annotation}
|
|
12
|
-
spec.description = %q{This Gem provides "annotation" for Ruby.}
|
|
13
|
-
spec.homepage = "https://github.com/Hdzi/metannotation"
|
|
14
|
-
spec.license = "MIT"
|
|
15
|
-
|
|
16
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
17
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
18
|
-
# if spec.respond_to?(:metadata)
|
|
19
|
-
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
|
20
|
-
# else
|
|
21
|
-
# raise "RubyGems 2.0 or newer is required to protect against " \
|
|
22
|
-
# "public gem pushes."
|
|
23
|
-
# end
|
|
24
|
-
|
|
25
|
-
# Specify which files should be added to the gem when it is released.
|
|
26
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
27
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
28
|
-
`git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/})}
|
|
29
|
-
end
|
|
30
|
-
spec.bindir = "exe"
|
|
31
|
-
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f)}
|
|
32
|
-
spec.require_paths = ["lib"]
|
|
33
|
-
|
|
34
|
-
spec.add_development_dependency "bundler", "~> 1.16"
|
|
35
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
|
36
|
-
spec.add_development_dependency "minitest", "~> 5.0"
|
|
37
|
-
end
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require "metannotation/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "metannotation"
|
|
7
|
+
spec.version = Metannotation::VERSION
|
|
8
|
+
spec.authors = ["Hdzi"]
|
|
9
|
+
spec.email = ["taojinhou@qq.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = %q{Ruby Annotation}
|
|
12
|
+
spec.description = %q{This Gem provides "annotation" for Ruby.}
|
|
13
|
+
spec.homepage = "https://github.com/Hdzi/metannotation"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
18
|
+
# if spec.respond_to?(:metadata)
|
|
19
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
|
20
|
+
# else
|
|
21
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
|
22
|
+
# "public gem pushes."
|
|
23
|
+
# end
|
|
24
|
+
|
|
25
|
+
# Specify which files should be added to the gem when it is released.
|
|
26
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
27
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
28
|
+
`git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/})}
|
|
29
|
+
end
|
|
30
|
+
spec.bindir = "exe"
|
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f)}
|
|
32
|
+
spec.require_paths = ["lib"]
|
|
33
|
+
|
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
36
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
|
37
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: metannotation
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0Beta2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hdzi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-08-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -65,7 +65,6 @@ files:
|
|
|
65
65
|
- README.md
|
|
66
66
|
- Rakefile
|
|
67
67
|
- lib/metannotation.rb
|
|
68
|
-
- lib/metannotation/core.rb
|
|
69
68
|
- lib/metannotation/core_ext/module.rb
|
|
70
69
|
- lib/metannotation/core_ext/string.rb
|
|
71
70
|
- lib/metannotation/define.rb
|
data/lib/metannotation/core.rb
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
module Metannotation # :nodoc:
|
|
2
|
-
# It's core of annotation
|
|
3
|
-
module Core
|
|
4
|
-
class << self
|
|
5
|
-
# Define annotation's core features depend it's type
|
|
6
|
-
def define(annotation)
|
|
7
|
-
annotation.send(:define_method, annotation.simple_name, &send("def_#{annotation.annotation_type.simple_name}_annotation", annotation))
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
private
|
|
11
|
-
|
|
12
|
-
# Define the method-annotation
|
|
13
|
-
def def_method_annotation(annotation)
|
|
14
|
-
def_annotation_common(annotation) do |fun_sym|
|
|
15
|
-
# check it a method
|
|
16
|
-
raise "Annotation's last parameter must be a method symbol!" unless public_method_defined?(fun_sym) ||
|
|
17
|
-
protected_method_defined?(fun_sym) ||
|
|
18
|
-
private_method_defined?(fun_sym)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# Define the class-annotation
|
|
23
|
-
def def_class_annotation(annotation)
|
|
24
|
-
def_annotation_common(annotation) do |cls|
|
|
25
|
-
# check it a class
|
|
26
|
-
raise "Annotation's last parameter must be a class constant!" unless cls.class.is_a? Module
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# Define what to do when annotation a target
|
|
31
|
-
def def_annotation_common(annotation, &block)
|
|
32
|
-
# What target to do
|
|
33
|
-
proc do |*args, target|
|
|
34
|
-
# check target a method or a class or a other
|
|
35
|
-
instance_exec(target, &block)
|
|
36
|
-
# execute annotation's +to_do_block+
|
|
37
|
-
# An annotation can include another annotations, all same type included annotations's +to_do_block+
|
|
38
|
-
# will be execute.
|
|
39
|
-
annotation.included_modules.unshift(annotation).each do |super_annotation|
|
|
40
|
-
class_exec(target, annotation, *args, &super_annotation.annotated_do) if super_annotation.singleton_class.method_defined?(:annotated_do) and
|
|
41
|
-
super_annotation.annotation_type == annotation.annotation_type
|
|
42
|
-
end
|
|
43
|
-
# an1 an2 target
|
|
44
|
-
target
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|