annotable 0.1.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c994186b8487d47a54dd1379d33e54e25f53117458c33317119bb2c9e57e9b2
4
- data.tar.gz: 32b4e9043b9162ceb1710283998e802baf8d977e711a084a7215d096713ab6ac
3
+ metadata.gz: 400e3451d726f63e94de8f930e030ad5d59ea7d331ad1676a5877e17190a5074
4
+ data.tar.gz: 20a5d99733b9d0a0a22d5891fc6741de340f67ea9ce2ab152cfbbcd7d4e7fe14
5
5
  SHA512:
6
- metadata.gz: e0299fc20ed9c02ac517ca7be9e7ec6aa0170bdb8690c8bd1437c3b8e13d7bbd3ecf2dd3c16b2dedd5a2444f31724358c7a506a5c3b5e189f85fb1b0bfb51902
7
- data.tar.gz: da8f86804d96c76055a369e83032c3fbad2891a325bcf9b1274a05e634d9ed26445fd25e3e58d5e749d672e4f6bd9f7a92d15b9d372c93b0e0394a45086e569c
6
+ metadata.gz: e447fc5c32676723bc2f8c1da58770266ac801ffb8065f9a03e15aa32fe5ed45d961c54335e5abad8541247cbec6904f335c0ee7c942edd8489bc9d98e322ae6
7
+ data.tar.gz: 7f6cc87158f6e3fc9a0cf09557f11d085e8678b2b2f6374059845c3c2e5941e2c9eb766f4fe9a034b5c539d1e107c1f7b4ed266975bfa44797ba8609aee8a985
data/Gemfile.lock CHANGED
@@ -1,72 +1,86 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- annotable (0.1.2)
4
+ annotable (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- ast (2.4.2)
10
- commander (4.6.0)
11
- highline (~> 2.0.0)
12
- diff-lcs (1.5.0)
9
+ ast (2.4.3)
10
+ commander (5.0.0)
11
+ highline (~> 3.0.0)
12
+ diff-lcs (1.6.2)
13
13
  docile (1.4.0)
14
- highline (2.0.3)
15
- parallel (1.22.1)
16
- parlour (5.0.0)
17
- commander (~> 4.5)
14
+ highline (3.0.1)
15
+ json (2.12.2)
16
+ language_server-protocol (3.17.0.5)
17
+ lint_roller (1.1.0)
18
+ logger (1.7.0)
19
+ parallel (1.27.0)
20
+ parlour (9.1.2)
21
+ commander (~> 5.0)
18
22
  parser
19
23
  rainbow (~> 3.0)
20
24
  sorbet-runtime (>= 0.5)
21
- parser (3.1.2.0)
25
+ parser (3.3.8.0)
22
26
  ast (~> 2.4.1)
27
+ racc
28
+ prism (1.4.0)
29
+ racc (1.8.1)
23
30
  rainbow (3.1.1)
24
- rake (13.0.6)
25
- regexp_parser (2.4.0)
26
- rexml (3.2.5)
27
- rspec (3.11.0)
28
- rspec-core (~> 3.11.0)
29
- rspec-expectations (~> 3.11.0)
30
- rspec-mocks (~> 3.11.0)
31
- rspec-core (3.11.0)
32
- rspec-support (~> 3.11.0)
33
- rspec-expectations (3.11.0)
31
+ rake (13.3.0)
32
+ rbs (3.9.4)
33
+ logger
34
+ regexp_parser (2.10.0)
35
+ rspec (3.13.1)
36
+ rspec-core (~> 3.13.0)
37
+ rspec-expectations (~> 3.13.0)
38
+ rspec-mocks (~> 3.13.0)
39
+ rspec-core (3.13.5)
40
+ rspec-support (~> 3.13.0)
41
+ rspec-expectations (3.13.5)
34
42
  diff-lcs (>= 1.2.0, < 2.0)
35
- rspec-support (~> 3.11.0)
36
- rspec-mocks (3.11.1)
43
+ rspec-support (~> 3.13.0)
44
+ rspec-mocks (3.13.5)
37
45
  diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (~> 3.11.0)
39
- rspec-support (3.11.0)
40
- rubocop (1.30.0)
46
+ rspec-support (~> 3.13.0)
47
+ rspec-support (3.13.4)
48
+ rubocop (1.78.0)
49
+ json (~> 2.3)
50
+ language_server-protocol (~> 3.17.0.2)
51
+ lint_roller (~> 1.1.0)
41
52
  parallel (~> 1.10)
42
- parser (>= 3.1.0.0)
53
+ parser (>= 3.3.0.2)
43
54
  rainbow (>= 2.2.2, < 4.0)
44
- regexp_parser (>= 1.8, < 3.0)
45
- rexml (>= 3.2.5, < 4.0)
46
- rubocop-ast (>= 1.18.0, < 2.0)
55
+ regexp_parser (>= 2.9.3, < 3.0)
56
+ rubocop-ast (>= 1.45.1, < 2.0)
47
57
  ruby-progressbar (~> 1.7)
48
- unicode-display_width (>= 1.4.0, < 3.0)
49
- rubocop-ast (1.18.0)
50
- parser (>= 3.1.1.0)
51
- rubocop-rspec (2.11.1)
52
- rubocop (~> 1.19)
53
- ruby-progressbar (1.11.0)
58
+ unicode-display_width (>= 2.4.0, < 4.0)
59
+ rubocop-ast (1.45.1)
60
+ parser (>= 3.3.7.2)
61
+ prism (~> 1.4)
62
+ rubocop-rspec (3.6.0)
63
+ lint_roller (~> 1.1)
64
+ rubocop (~> 1.72, >= 1.72.1)
65
+ ruby-progressbar (1.13.0)
54
66
  simplecov (0.21.2)
55
67
  docile (~> 1.1)
56
68
  simplecov-html (~> 0.11)
57
69
  simplecov_json_formatter (~> 0.1)
58
70
  simplecov-html (0.12.3)
59
71
  simplecov_json_formatter (0.1.4)
60
- sorbet-runtime (0.5.10184)
61
- sord (4.0.0)
62
- commander (~> 4.5)
63
- parlour (~> 5.0)
72
+ sorbet-runtime (0.5.12222)
73
+ sord (7.1.0)
74
+ commander (~> 5.0)
75
+ parlour (~> 9.1)
76
+ parser
77
+ rbs (>= 3.0, < 5)
64
78
  sorbet-runtime
65
79
  yard
66
- unicode-display_width (2.1.0)
67
- webrick (1.7.0)
68
- yard (0.9.28)
69
- webrick (~> 1.7.0)
80
+ unicode-display_width (3.1.4)
81
+ unicode-emoji (~> 4.0, >= 4.0.4)
82
+ unicode-emoji (4.0.4)
83
+ yard (0.9.37)
70
84
 
71
85
  PLATFORMS
72
86
  x86_64-linux
@@ -74,12 +88,12 @@ PLATFORMS
74
88
 
75
89
  DEPENDENCIES
76
90
  annotable!
77
- rake (~> 13.0)
78
- rspec (~> 3.11)
79
- rubocop (~> 1.29)
80
- rubocop-rspec (~> 2.11)
91
+ rake (~> 13.3)
92
+ rspec (~> 3.13)
93
+ rubocop (~> 1.78)
94
+ rubocop-rspec (~> 3.6)
81
95
  simplecov (~> 0.21)
82
- sord (~> 4.0)
96
+ sord (~> 7.1)
83
97
 
84
98
  BUNDLED WITH
85
99
  2.3.7
data/README.md CHANGED
@@ -37,6 +37,36 @@ class Needy
37
37
  end
38
38
  ```
39
39
 
40
+ You can use `annotation` to declare one annotation along with it's validation block:
41
+
42
+ ```ruby
43
+ require "annotable" # Require the gem
44
+
45
+ class Needy
46
+ extend Annotable # Extend your class or module with Annotable
47
+ annotation :my_annotation do |params, options| # Declare your annotations with a validation block
48
+ raise ArgumentError, "my_annotation doesn't accept parameters" unless params.empty?
49
+
50
+ case options
51
+ in foo:
52
+ raise ArgumentError, "foo must be a String" unless foo.is_a? String
53
+ else
54
+ raise ArgumentError, "foo is mandatory"
55
+ end
56
+ end
57
+
58
+ my_annotation foo: "world!" # Annotate your methods
59
+ def method_needing_meta_data
60
+ # ...
61
+ end
62
+
63
+ my_annotation foo: 42 # Raises an error
64
+ def regular_method
65
+ # ...
66
+ end
67
+ end
68
+ ```
69
+
40
70
  `Annotable` adds several methods to your class or module, providing access to annotations and their metadata:
41
71
  ```ruby
42
72
  Needy.annotated_method_exist? :method_needing_meta_data
data/annotable.gemspec CHANGED
@@ -32,10 +32,10 @@ Gem::Specification.new do |spec|
32
32
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
33
33
  spec.require_paths = ["lib"]
34
34
 
35
- spec.add_development_dependency "rake", "~> 13.0"
36
- spec.add_development_dependency "rspec", "~> 3.11"
37
- spec.add_development_dependency "rubocop", "~> 1.29"
38
- spec.add_development_dependency "rubocop-rspec", "~> 2.11"
35
+ spec.add_development_dependency "rake", "~> 13.3"
36
+ spec.add_development_dependency "rspec", "~> 3.13"
37
+ spec.add_development_dependency "rubocop", "~> 1.78"
38
+ spec.add_development_dependency "rubocop-rspec", "~> 3.6"
39
39
  spec.add_development_dependency "simplecov", "~> 0.21"
40
- spec.add_development_dependency "sord", "~> 4.0"
40
+ spec.add_development_dependency "sord", "~> 7.1"
41
41
  end
@@ -24,10 +24,17 @@ module Annotable
24
24
  # @param [Array<Object>] params The annotation's params
25
25
  # @param [Hash<Symbol, Object>] options The annotation's options
26
26
  #
27
- def initialize(name, params = [], options = {})
27
+ #
28
+ # [params, options] params and/or options validation block
29
+ # @yieldparam [Array<Object>] params the annotation parameters
30
+ # @yieldparam [Hash<Symbol, Object>] options the annotation options
31
+ #
32
+ def initialize(name, params = [], options = {}, &)
28
33
  @name = name
29
34
  @params = params
30
35
  @options = options
36
+
37
+ yield(params, options) if block_given?
31
38
  end
32
39
  end
33
40
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Annotable
4
4
  # @return [String] The gem version number
5
- VERSION = "0.1.2"
5
+ VERSION = "0.2.0"
6
6
  end
data/lib/annotable.rb CHANGED
@@ -62,7 +62,7 @@ module Annotable
62
62
  # annotable :my_annotation, :my_other_annotation
63
63
  #
64
64
  # This will generate two class methods named after the given symbols.
65
- # These methods, will push a new `Annotation` in the `current_annotation` array.
65
+ # These methods will push a new `Annotation` instance in the `current_annotation` array.
66
66
  #
67
67
  # @param [Array<Symbol>] annotation_names The names of annotations to declare
68
68
  #
@@ -78,6 +78,39 @@ module Annotable
78
78
  end
79
79
  end
80
80
 
81
+ #
82
+ # Declares one annotation usable in the module or class.
83
+ # The annotation can be validated using a block.
84
+ #
85
+ # annotation :my_annotation do |params, options|
86
+ # raise ArgumentError, "my_annotation doesn't accept parameters" unless params.empty?
87
+ #
88
+ # case options
89
+ # in foo:
90
+ # raise ArgumentError, "foo must be a String" unless foo.is_a? String
91
+ # else
92
+ # raise ArgumentError, "foo is mandatory"
93
+ # end
94
+ # end
95
+ #
96
+ # This will generate a class method named after the given symbol.
97
+ # This method intialize a new `Annotation` which then execute the validation block.
98
+ # The annotation instance will be pushed in the `current_annotation` array.
99
+ #
100
+ # @param [Symbol] name The names of annotations to declare
101
+ #
102
+ # @yield [params, options] params and/or options validation block
103
+ # @yieldparam [Array<Object>] params the annotation parameters
104
+ # @yieldparam [Hash<Symbol, Object>] options the annotation options
105
+ #
106
+ # @return [void]
107
+ #
108
+ def annotation(name, &validator)
109
+ define_singleton_method(name) do |*params, **options|
110
+ current_annotations.push Annotable::Annotation.new(name, params, options, &validator)
111
+ end
112
+ end
113
+
81
114
  #
82
115
  # Return all annotated methods or those matching the given annotation names.
83
116
  #
data/sig/annotable.rbs CHANGED
@@ -56,11 +56,32 @@ module Annotable
56
56
  # annotable :my_annotation, :my_other_annotation
57
57
  #
58
58
  # This will generate two class methods named after the given symbols.
59
- # These methods, will push a new `Annotation` in the `current_annotation` array.
59
+ # These methods will push a new `Annotation` instance in the `current_annotation` array.
60
60
  #
61
61
  # _@param_ `annotation_names` — The names of annotations to declare
62
62
  def annotable: (*::Array[Symbol] annotation_names) -> void
63
63
 
64
+ # Declares one annotation usable in the module or class.
65
+ # The annotation can be validated using a block.
66
+ #
67
+ # annotation :my_annotation do |params, options|
68
+ # raise ArgumentError, "my_annotation doesn't accept parameters" unless params.empty?
69
+ #
70
+ # case options
71
+ # in foo:
72
+ # raise ArgumentError, "foo must be a String" unless foo.is_a? String
73
+ # else
74
+ # raise ArgumentError, "foo is mandatory"
75
+ # end
76
+ # end
77
+ #
78
+ # This will generate a class method named after the given symbol.
79
+ # This method intialize a new `Annotation` which then execute the validation block.
80
+ # The annotation instance will be pushed in the `current_annotation` array.
81
+ #
82
+ # _@param_ `name` — The names of annotations to declare
83
+ def annotation: (Symbol name) ?{ (::Array[Object] params, ::Hash[Symbol, Object] options) -> void } -> void
84
+
64
85
  # Return all annotated methods or those matching the given annotation names.
65
86
  #
66
87
  # _@param_ `names` — The annotation names to find
@@ -149,12 +170,14 @@ module Annotable
149
170
  class Annotation
150
171
  # Creates an new annotation.
151
172
  #
173
+ # [params, options] params and/or options validation block
174
+ #
152
175
  # _@param_ `name` — The annotation's name
153
176
  #
154
177
  # _@param_ `params` — The annotation's params
155
178
  #
156
179
  # _@param_ `options` — The annotation's options
157
- def initialize: (Symbol name, ?::Array[Object] params, ?::Hash[Symbol, Object] options) -> void
180
+ def initialize: (Symbol name, ?::Array[Object] params, ?::Hash[Symbol, Object] options) ?{ (::Array[Object] params, ::Hash[Symbol, Object] options) -> void } -> void
158
181
 
159
182
  # _@return_ — The annotation's name
160
183
  attr_reader name: Symbol
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annotable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathieu MOREL
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-03-14 00:00:00.000000000 Z
10
+ date: 2025-07-14 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rake
@@ -16,56 +15,56 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '13.0'
18
+ version: '13.3'
20
19
  type: :development
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '13.0'
25
+ version: '13.3'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: rspec
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '3.11'
32
+ version: '3.13'
34
33
  type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: '3.11'
39
+ version: '3.13'
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: rubocop
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - "~>"
46
45
  - !ruby/object:Gem::Version
47
- version: '1.29'
46
+ version: '1.78'
48
47
  type: :development
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - "~>"
53
52
  - !ruby/object:Gem::Version
54
- version: '1.29'
53
+ version: '1.78'
55
54
  - !ruby/object:Gem::Dependency
56
55
  name: rubocop-rspec
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - "~>"
60
59
  - !ruby/object:Gem::Version
61
- version: '2.11'
60
+ version: '3.6'
62
61
  type: :development
63
62
  prerelease: false
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
64
  requirements:
66
65
  - - "~>"
67
66
  - !ruby/object:Gem::Version
68
- version: '2.11'
67
+ version: '3.6'
69
68
  - !ruby/object:Gem::Dependency
70
69
  name: simplecov
71
70
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +85,14 @@ dependencies:
86
85
  requirements:
87
86
  - - "~>"
88
87
  - !ruby/object:Gem::Version
89
- version: '4.0'
88
+ version: '7.1'
90
89
  type: :development
91
90
  prerelease: false
92
91
  version_requirements: !ruby/object:Gem::Requirement
93
92
  requirements:
94
93
  - - "~>"
95
94
  - !ruby/object:Gem::Version
96
- version: '4.0'
95
+ version: '7.1'
97
96
  description: Provides a simple way to add annotations to your method declarations.
98
97
  email:
99
98
  - mathieu@lamanufacture.dev
@@ -125,7 +124,6 @@ metadata:
125
124
  homepage_uri: https://github.com/ductr-io/annotable
126
125
  source_code_uri: https://github.com/ductr-io/annotable
127
126
  changelog_uri: https://github.com/ductr-io/annotable/releases
128
- post_install_message:
129
127
  rdoc_options: []
130
128
  require_paths:
131
129
  - lib
@@ -140,8 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
138
  - !ruby/object:Gem::Version
141
139
  version: '0'
142
140
  requirements: []
143
- rubygems_version: 3.3.26
144
- signing_key:
141
+ rubygems_version: 3.6.6
145
142
  specification_version: 4
146
143
  summary: A simple zero-dependency method annotation gem
147
144
  test_files: []