simple_annotation 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 25158c07a27196aeecc5db4f08c8af0129f2485f5dab1184b14338a956f3284a
4
+ data.tar.gz: d412eb711e99836174a3d5c82b3ae44f4a1c9d02c1483f1c0836130ff67c3baf
5
+ SHA512:
6
+ metadata.gz: cac55700c541f2b9270181480c0eec12b80135da7b20d379a895469ac596d98ded201355fc8576cb405f43eb9565add697098fb24cab9067ec14f177d7f511c0
7
+ data.tar.gz: e0d53db327d871e5e264f0eb511c7fc63218d48d12163ac2f670c386feb6d5b20af2ab7e7c03709c3ef1eb2886b4a3cf95411a1d98ecf99697176f4485aeb7a2
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.1
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.15
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Style/StringLiterals:
7
+ Enabled: true
8
+ EnforcedStyle: single_quotes
9
+
10
+ Style/StringLiteralsInInterpolation:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Layout/LineLength:
15
+ Max: 120
16
+
17
+ Style/Documentation:
18
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-06-12
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in simple_annotation.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+
10
+ gem 'test-unit', '~> 3.0'
11
+
12
+ gem 'rubocop', '~> 1.7'
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ simple_annotation (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ parallel (1.20.1)
11
+ parser (3.0.1.1)
12
+ ast (~> 2.4.1)
13
+ power_assert (2.0.0)
14
+ rainbow (3.0.0)
15
+ rake (13.0.3)
16
+ regexp_parser (2.1.1)
17
+ rexml (3.2.5)
18
+ rubocop (1.16.0)
19
+ parallel (~> 1.10)
20
+ parser (>= 3.0.0.0)
21
+ rainbow (>= 2.2.2, < 4.0)
22
+ regexp_parser (>= 1.8, < 3.0)
23
+ rexml
24
+ rubocop-ast (>= 1.7.0, < 2.0)
25
+ ruby-progressbar (~> 1.7)
26
+ unicode-display_width (>= 1.4.0, < 3.0)
27
+ rubocop-ast (1.7.0)
28
+ parser (>= 3.0.1.1)
29
+ ruby-progressbar (1.11.0)
30
+ test-unit (3.4.4)
31
+ power_assert
32
+ unicode-display_width (2.0.0)
33
+
34
+ PLATFORMS
35
+ x86_64-darwin-19
36
+
37
+ DEPENDENCIES
38
+ simple_annotation!
39
+ rake (~> 13.0)
40
+ rubocop (~> 1.7)
41
+ test-unit (~> 3.0)
42
+
43
+ BUNDLED WITH
44
+ 2.2.15
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Tomohiro Nishimura
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 ADDED
@@ -0,0 +1,73 @@
1
+ # SimpleAnnotation
2
+
3
+ Annotate method with anything. Symbol, String and so on.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'simple_annotation'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install simple_annotation
20
+
21
+ ## Usage
22
+
23
+ ### Basic style
24
+
25
+ ```ruby
26
+ class A
27
+ include SimpleAnnotation::Annotatable
28
+
29
+ def meth; end
30
+ end
31
+
32
+ A.annotated?(:meth) #=> false
33
+
34
+ # Annotate method with :example
35
+ A.annotates(:meth, with: :example)
36
+
37
+ A.annotated?(:meth, with: :example) #=> true
38
+ A.annotations(:meth) #=> [:example]
39
+
40
+ A.public_instance_method(:meth).annotations #=> [:example]
41
+ A.new.method(:meth).annotations #=> [:example]
42
+ ```
43
+
44
+ ### Separate line style
45
+
46
+ ```ruby
47
+ class A
48
+ include SimpleAnnotation::Annotatable
49
+
50
+ annotates 'this is a annotation'
51
+ def meth; end
52
+ end
53
+
54
+ A.annotated?(:meth, with: 'this is a annotation') #=> true
55
+ A.annotations(:meth) #=> ['this is a annotation']
56
+
57
+ A.public_instance_method(:meth).annotations #=> ['this is a annotation']
58
+ A.new.method(:meth).annotations #=> ['this is a annotation']
59
+ ```
60
+
61
+ ## Development
62
+
63
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test-unit` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
64
+
65
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Sixeight/simple_annotation.
70
+
71
+ ## License
72
+
73
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ require 'rubocop/rake_task'
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'simple_annotation'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'simple_annotation/version'
4
+ require_relative 'simple_annotation/annotatable'
5
+
6
+ module SimpleAnnotation
7
+ def annotations
8
+ return [] unless owner.include? Annotatable
9
+
10
+ owner.annotations(original_name)
11
+ end
12
+
13
+ ::UnboundMethod.include self
14
+ ::Method.include self
15
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'set'
4
+
5
+ module SimpleAnnotation
6
+ module Annotatable
7
+ def self.included(mod)
8
+ mod.instance_variable_set(:@__method_to_annotations, Hash.new { |h, k| h[k] = Set.new })
9
+ mod.instance_variable_set(:@__standby_annotations, [])
10
+ mod.extend ClassMethods
11
+ end
12
+
13
+ module ClassMethods
14
+ def annotates(*method_or_annotations, with: nil)
15
+ if with.nil?
16
+ @__standby_annotations.concat(method_or_annotations)
17
+ else
18
+ method_or_annotations.each do |meth|
19
+ @__method_to_annotations[meth.to_sym] << with
20
+ end
21
+ end
22
+ end
23
+
24
+ def annotated?(meth, with: nil)
25
+ return @__method_to_annotations.include?(meth.to_sym) if with.nil?
26
+
27
+ @__method_to_annotations[meth.to_sym].include? with
28
+ end
29
+
30
+ def annotations(meth)
31
+ @__method_to_annotations[meth.to_sym].to_a
32
+ end
33
+
34
+ private
35
+
36
+ def method_added(meth)
37
+ super
38
+
39
+ @__standby_annotations.each do |annotation|
40
+ annotates meth, with: annotation
41
+ end
42
+ @__standby_annotations.clear
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleAnnotation
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/simple_annotation/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'simple_annotation'
7
+ spec.version = SimpleAnnotation::VERSION
8
+ spec.authors = ['Tomohiro Nishimura']
9
+ spec.email = ['tomohiro68@gmail.com']
10
+
11
+ spec.summary = 'Annotate method with anything.'
12
+ spec.description = 'Annotate method with anything. Symbol, String and so on'
13
+ spec.homepage = 'https://githuc.com/Sixeight/simple_annotation'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = spec.homepage
19
+ spec.metadata['changelog_uri'] = format('%s/blob/master/CHANGELOG.md', spec.homepage)
20
+
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+ spec.require_paths = ['lib']
25
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_annotation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomohiro Nishimura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Annotate method with anything. Symbol, String and so on
14
+ email:
15
+ - tomohiro68@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".github/workflows/main.yml"
21
+ - ".gitignore"
22
+ - ".rubocop.yml"
23
+ - CHANGELOG.md
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - bin/console
30
+ - bin/setup
31
+ - lib/simple_annotation.rb
32
+ - lib/simple_annotation/annotatable.rb
33
+ - lib/simple_annotation/version.rb
34
+ - simple_annotation.gemspec
35
+ homepage: https://githuc.com/Sixeight/simple_annotation
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ homepage_uri: https://githuc.com/Sixeight/simple_annotation
40
+ source_code_uri: https://githuc.com/Sixeight/simple_annotation
41
+ changelog_uri: https://githuc.com/Sixeight/simple_annotation/blob/master/CHANGELOG.md
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.5.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.2.15
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Annotate method with anything.
61
+ test_files: []