ronin-core 0.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.github/workflows/ruby.yml +41 -0
  4. data/.gitignore +12 -0
  5. data/.rspec +1 -0
  6. data/.rubocop.yml +160 -0
  7. data/.ruby-version +1 -0
  8. data/.yardopts +1 -0
  9. data/COPYING.txt +165 -0
  10. data/ChangeLog.md +11 -0
  11. data/Gemfile +30 -0
  12. data/README.md +299 -0
  13. data/Rakefile +34 -0
  14. data/examples/ruby_shell.rb +11 -0
  15. data/gemspec.yml +28 -0
  16. data/lib/ronin/core/class_registry.rb +246 -0
  17. data/lib/ronin/core/cli/command.rb +87 -0
  18. data/lib/ronin/core/cli/command_shell/command.rb +110 -0
  19. data/lib/ronin/core/cli/command_shell.rb +345 -0
  20. data/lib/ronin/core/cli/generator/options/author.rb +106 -0
  21. data/lib/ronin/core/cli/generator/options/description.rb +54 -0
  22. data/lib/ronin/core/cli/generator/options/reference.rb +60 -0
  23. data/lib/ronin/core/cli/generator/options/summary.rb +54 -0
  24. data/lib/ronin/core/cli/generator.rb +238 -0
  25. data/lib/ronin/core/cli/logging.rb +59 -0
  26. data/lib/ronin/core/cli/options/param.rb +68 -0
  27. data/lib/ronin/core/cli/options/values/arches.rb +45 -0
  28. data/lib/ronin/core/cli/options/values/oses.rb +32 -0
  29. data/lib/ronin/core/cli/printing/arch.rb +71 -0
  30. data/lib/ronin/core/cli/printing/metadata.rb +113 -0
  31. data/lib/ronin/core/cli/printing/os.rb +54 -0
  32. data/lib/ronin/core/cli/printing/params.rb +69 -0
  33. data/lib/ronin/core/cli/ruby_shell.rb +131 -0
  34. data/lib/ronin/core/cli/shell.rb +186 -0
  35. data/lib/ronin/core/git.rb +73 -0
  36. data/lib/ronin/core/home.rb +86 -0
  37. data/lib/ronin/core/metadata/authors/author.rb +241 -0
  38. data/lib/ronin/core/metadata/authors.rb +120 -0
  39. data/lib/ronin/core/metadata/description.rb +100 -0
  40. data/lib/ronin/core/metadata/id.rb +88 -0
  41. data/lib/ronin/core/metadata/references.rb +87 -0
  42. data/lib/ronin/core/metadata/summary.rb +78 -0
  43. data/lib/ronin/core/metadata/version.rb +74 -0
  44. data/lib/ronin/core/params/exceptions.rb +38 -0
  45. data/lib/ronin/core/params/mixin.rb +317 -0
  46. data/lib/ronin/core/params/param.rb +137 -0
  47. data/lib/ronin/core/params/types/boolean.rb +64 -0
  48. data/lib/ronin/core/params/types/enum.rb +107 -0
  49. data/lib/ronin/core/params/types/float.rb +68 -0
  50. data/lib/ronin/core/params/types/integer.rb +100 -0
  51. data/lib/ronin/core/params/types/numeric.rb +106 -0
  52. data/lib/ronin/core/params/types/regexp.rb +67 -0
  53. data/lib/ronin/core/params/types/string.rb +118 -0
  54. data/lib/ronin/core/params/types/type.rb +54 -0
  55. data/lib/ronin/core/params/types/uri.rb +72 -0
  56. data/lib/ronin/core/params/types.rb +62 -0
  57. data/lib/ronin/core/params.rb +19 -0
  58. data/lib/ronin/core/version.rb +24 -0
  59. data/ronin-core.gemspec +59 -0
  60. data/spec/class_registry_spec.rb +224 -0
  61. data/spec/cli/command_shell/command_spec.rb +113 -0
  62. data/spec/cli/command_shell_spec.rb +1114 -0
  63. data/spec/cli/command_spec.rb +16 -0
  64. data/spec/cli/fixtures/irb_command +8 -0
  65. data/spec/cli/fixtures/template/dir/file1.txt +1 -0
  66. data/spec/cli/fixtures/template/dir/file2.txt +1 -0
  67. data/spec/cli/fixtures/template/file.erb +1 -0
  68. data/spec/cli/fixtures/template/file.txt +1 -0
  69. data/spec/cli/generator/options/author_spec.rb +121 -0
  70. data/spec/cli/generator/options/description_spec.rb +45 -0
  71. data/spec/cli/generator/options/reference_spec.rb +53 -0
  72. data/spec/cli/generator/options/summary_spec.rb +45 -0
  73. data/spec/cli/generator_spec.rb +244 -0
  74. data/spec/cli/logging_spec.rb +95 -0
  75. data/spec/cli/options/param_spec.rb +67 -0
  76. data/spec/cli/options/values/arches_spec.rb +62 -0
  77. data/spec/cli/printing/arch_spec.rb +130 -0
  78. data/spec/cli/printing/metadata_spec.rb +211 -0
  79. data/spec/cli/printing/os_spec.rb +64 -0
  80. data/spec/cli/printing/params_spec.rb +63 -0
  81. data/spec/cli/ruby_shell.rb +99 -0
  82. data/spec/cli/shell_spec.rb +211 -0
  83. data/spec/fixtures/example_class_registry/base_class.rb +9 -0
  84. data/spec/fixtures/example_class_registry/classes/loaded_class.rb +9 -0
  85. data/spec/fixtures/example_class_registry/classes/name_mismatch.rb +9 -0
  86. data/spec/fixtures/example_class_registry/classes/no_module.rb +4 -0
  87. data/spec/fixtures/example_class_registry.rb +8 -0
  88. data/spec/git_spec.rb +58 -0
  89. data/spec/home_spec.rb +64 -0
  90. data/spec/metadata/authors/author_spec.rb +335 -0
  91. data/spec/metadata/authors_spec.rb +126 -0
  92. data/spec/metadata/description_spec.rb +74 -0
  93. data/spec/metadata/id_spec.rb +92 -0
  94. data/spec/metadata/references_spec.rb +100 -0
  95. data/spec/metadata/summary_spec.rb +74 -0
  96. data/spec/metadata/version_spec.rb +72 -0
  97. data/spec/params/mixin_spec.rb +484 -0
  98. data/spec/params/param_spec.rb +164 -0
  99. data/spec/params/types/boolean_spec.rb +56 -0
  100. data/spec/params/types/enum_spec.rb +94 -0
  101. data/spec/params/types/float_spec.rb +107 -0
  102. data/spec/params/types/integer_spec.rb +155 -0
  103. data/spec/params/types/numeric_spec.rb +138 -0
  104. data/spec/params/types/regexp_spec.rb +64 -0
  105. data/spec/params/types/string_spec.rb +174 -0
  106. data/spec/params/types/type_spec.rb +14 -0
  107. data/spec/params/types/uri_spec.rb +62 -0
  108. data/spec/spec_helper.rb +11 -0
  109. metadata +252 -0
@@ -0,0 +1,241 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2021-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ #
5
+ # ronin-core is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published
7
+ # by the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # ronin-core is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with ronin-core. If not, see <https://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ module Ronin
20
+ module Core
21
+ module Metadata
22
+ module Authors
23
+ class Author
24
+
25
+ # The author's name.
26
+ #
27
+ # @return [String]
28
+ attr_reader :name
29
+
30
+ # The author's email.
31
+ #
32
+ # @return [String, nil]
33
+ attr_reader :email
34
+
35
+ # The author's PGP Key ID.
36
+ #
37
+ # @return [String, nil]
38
+ attr_reader :pgp
39
+
40
+ # The author's website
41
+ #
42
+ # @return [String, nil]
43
+ attr_reader :website
44
+
45
+ # The author's blog.
46
+ #
47
+ # @return [String, nil]
48
+ attr_reader :blog
49
+
50
+ # The author's GitHub user name.
51
+ #
52
+ # @return [String, nil]
53
+ attr_reader :github
54
+
55
+ # The author's GitLab user name.
56
+ #
57
+ # @return [String, nil]
58
+ attr_reader :gitlab
59
+
60
+ # The author's Twitter handle.
61
+ #
62
+ # @return [String, nil]
63
+ attr_reader :twitter
64
+
65
+ # The author's Discord handle.
66
+ #
67
+ # @return [String, nil]
68
+ attr_reader :discord
69
+
70
+ #
71
+ # Initializes the author.
72
+ #
73
+ # @param [String] name
74
+ # The author's name.
75
+ #
76
+ # @param [String, nil] email
77
+ # The author's email.
78
+ #
79
+ # @param [String, nil] pgp
80
+ # The author's PGP Key ID.
81
+ #
82
+ # @param [String, nil] website
83
+ # The author's website.
84
+ #
85
+ # @param [String, nil] blog
86
+ # The author's blog.
87
+ #
88
+ # @param [String, nil] github
89
+ # The author's GitHub user name.
90
+ #
91
+ # @param [String, nil] gitlab
92
+ # The author's GitLab user name.
93
+ #
94
+ # @param [String, nil] twitter
95
+ # The author's Twitter handle.
96
+ #
97
+ # @param [String, nil] discord
98
+ # The author's Discord handle.
99
+ #
100
+ def initialize(name, email: nil,
101
+ pgp: nil,
102
+ website: nil,
103
+ blog: nil,
104
+ github: nil,
105
+ gitlab: nil,
106
+ twitter: nil,
107
+ discord: nil)
108
+ @name = name
109
+ @email = email
110
+ @pgp = pgp
111
+
112
+ @website = website
113
+ @blog = blog
114
+ @github = github
115
+ @gitlab = gitlab
116
+ @twitter = twitter
117
+ @discord = discord
118
+ end
119
+
120
+ #
121
+ # Determines if the author has an {#email} set.
122
+ #
123
+ # @return [Boolean]
124
+ #
125
+ def email?
126
+ @email != nil
127
+ end
128
+
129
+ #
130
+ # Determines if the author has a {#pgp} Key ID set.
131
+ #
132
+ # @return [Boolean]
133
+ #
134
+ def pgp?
135
+ @pgp != nil
136
+ end
137
+
138
+ #
139
+ # Determines if the author has a {#website} set.
140
+ #
141
+ # @return [Boolean]
142
+ #
143
+ def website?
144
+ @website != nil
145
+ end
146
+
147
+ #
148
+ # Determines if the author has a {#blog} set.
149
+ #
150
+ # @return [Boolean]
151
+ #
152
+ def blog?
153
+ @blog != nil
154
+ end
155
+
156
+ #
157
+ # Determines if the author has a {#github} user name set.
158
+ #
159
+ # @return [Boolean]
160
+ #
161
+ def github?
162
+ @github != nil
163
+ end
164
+
165
+ #
166
+ # Determines if the author has a {#gitlab} user name set.
167
+ #
168
+ # @return [Boolean]
169
+ #
170
+ def gitlab?
171
+ @gitlab != nil
172
+ end
173
+
174
+ #
175
+ # Determines if the author has a {#twitter} handle set.
176
+ #
177
+ # @return [Boolean]
178
+ #
179
+ def twitter?
180
+ @twitter != nil
181
+ end
182
+
183
+ #
184
+ # Determines if the author has a {#discord} handle set.
185
+ #
186
+ # @return [Boolean]
187
+ #
188
+ def discord?
189
+ @discord != nil
190
+ end
191
+
192
+ #
193
+ # Returns the URL to the author's GitHub profile.
194
+ #
195
+ # @return [String, nil]
196
+ # Returns the URL to the author's GitHub profile, or `nil`
197
+ # if no {#github} user name has been set.
198
+ #
199
+ def github_url
200
+ "https://github.com/#{@github.sub(/\A@/,'')}" if @github
201
+ end
202
+
203
+ #
204
+ # Returns the URL to the author's GitLab profile.
205
+ #
206
+ # @return [String, nil]
207
+ # Returns the URL to the author's GitLab profile, or `nil`
208
+ # if no {#gitlab} user name has been set.
209
+ #
210
+ def gitlab_url
211
+ "https://gitlab.com/#{@gitlab.sub(/\A@/,'')}" if @gitlab
212
+ end
213
+
214
+ #
215
+ # Returns the URL to the author's Twitter profile.
216
+ #
217
+ # @return [String, nil]
218
+ # Returns the URL to the author's Twitter profile, or `nil`
219
+ # if no {#twitter} user name has been set.
220
+ #
221
+ def twitter_url
222
+ "https://twitter.com/#{@twitter.sub(/\A@/,'')}" if @twitter
223
+ end
224
+
225
+ #
226
+ # Converts the author to a String.
227
+ #
228
+ # @return [String]
229
+ # The author's name and/or email.
230
+ #
231
+ def to_s
232
+ if @email then "#{@name} <#{@email}>"
233
+ else @name
234
+ end
235
+ end
236
+
237
+ end
238
+ end
239
+ end
240
+ end
241
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2021-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ #
5
+ # ronin-core is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published
7
+ # by the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # ronin-core is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with ronin-core. If not, see <https://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ require 'ronin/core/metadata/authors/author'
20
+
21
+ module Ronin
22
+ module Core
23
+ module Metadata
24
+ #
25
+ # Adds {Authors::ClassMethods#author authors} metadata attribute to a
26
+ # class.
27
+ #
28
+ # ### Example
29
+ #
30
+ # class MyModule
31
+ #
32
+ # include Ronin::Core::Metadata::Authors
33
+ #
34
+ # author 'John Doe'
35
+ # author 'John Smith', email: 'john.smith@example.com'
36
+ #
37
+ # end
38
+ #
39
+ # puts MyModule.authors
40
+ # # John Doe
41
+ # # John Smith <john.smith@example.com>
42
+ #
43
+ module Authors
44
+ #
45
+ # Adds {ClassMethods} to the class.
46
+ #
47
+ # @param [Class] base
48
+ # The base class which is including {Authors}.
49
+ #
50
+ # @api private
51
+ #
52
+ def self.included(base)
53
+ base.extend ClassMethods
54
+ end
55
+
56
+ module ClassMethods
57
+ #
58
+ # The authors associated with the class.
59
+ #
60
+ # @return [Array<Authors::Author>]
61
+ #
62
+ # @api semipublic
63
+ #
64
+ def authors
65
+ @authors ||= if superclass.kind_of?(ClassMethods)
66
+ superclass.authors.dup
67
+ else
68
+ []
69
+ end
70
+ end
71
+
72
+ #
73
+ # Adds an author.
74
+ #
75
+ # @param [String, nil] name
76
+ # The new author name to add.
77
+ #
78
+ # @param [Hash{Symbol => Object}] kwargs
79
+ # Additional keyword arguments for {Author#initialize}.
80
+ #
81
+ # @option kwargs [String, nil] :email
82
+ # The author's email.
83
+ #
84
+ # @option kwargs [String, nil] :pgp
85
+ # The author's PGP Key ID.
86
+ #
87
+ # @option kwargs [String, nil] :website
88
+ # The author's website.
89
+ #
90
+ # @option kwargs [String, nil] :blog
91
+ # The author's blog.
92
+ #
93
+ # @option kwargs [String, nil] :github
94
+ # The author's GitHub user name.
95
+ #
96
+ # @option kwargs [String, nil] :gitlab
97
+ # The author's GitLab user name.
98
+ #
99
+ # @option kwargs [String, nil] :twitter
100
+ # The author's Twitter handle.
101
+ #
102
+ # @option kwargs [String, nil] :discord
103
+ # The author's Discord handle.
104
+ #
105
+ # @example Adds an author name:
106
+ # author 'John Smith'
107
+ #
108
+ # @example Adds an author name and email:
109
+ # author 'John Smith', email: 'john.smith@example.com'
110
+ #
111
+ # @api public
112
+ #
113
+ def author(name,**kwargs)
114
+ authors << Ronin::Core::Metadata::Authors::Author.new(name,**kwargs)
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2021-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ #
5
+ # ronin-core is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published
7
+ # by the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # ronin-core is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with ronin-core. If not, see <https://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ module Ronin
20
+ module Core
21
+ module Metadata
22
+ #
23
+ # Adds a {Description::ClassMethods#description description} metadata
24
+ # attribute to a class.
25
+ #
26
+ # ### Example
27
+ #
28
+ # class MyModule
29
+ #
30
+ # include Ronin::Core::Metadata::Description
31
+ #
32
+ # description <<~DESC
33
+ # Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
34
+ # eiusmod tempor incididunt ut labore et dolore magna aliqua.
35
+ #
36
+ # Ut enim ad minim veniam, quis nostrud exercitation ullamco
37
+ # laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
38
+ # dolor in reprehenderit in voluptate velit esse cillum dolore eu
39
+ #
40
+ # fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
41
+ # proident, sunt in culpa qui officia deserunt mollit anim id est
42
+ # laborum.
43
+ # DESC
44
+ #
45
+ # end
46
+ #
47
+ module Description
48
+ #
49
+ # Adds {ClassMethods} to the class.
50
+ #
51
+ # @param [Class] base
52
+ # The base class which is including {Description}.
53
+ #
54
+ # @api private
55
+ #
56
+ def self.included(base)
57
+ base.extend ClassMethods
58
+ end
59
+
60
+ module ClassMethods
61
+ #
62
+ # Gets or sets the description.
63
+ #
64
+ # @param [String, nil] new_description
65
+ # The optional new description text to set.
66
+ #
67
+ # @return [String, nil]
68
+ # The previously set description text.
69
+ #
70
+ # @example Setting the description:
71
+ # description <<~DESC
72
+ # Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
73
+ # eiusmod tempor incididunt ut labore et dolore magna aliqua.
74
+ #
75
+ # Ut enim ad minim veniam, quis nostrud exercitation ullamco
76
+ # laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
77
+ # dolor in reprehenderit in voluptate velit esse cillum dolore eu
78
+ #
79
+ # fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
80
+ # proident, sunt in culpa qui officia deserunt mollit anim id est
81
+ # laborum.
82
+ # DESC
83
+ #
84
+ # @example Getting the description:
85
+ # MyModule.description
86
+ #
87
+ def description(new_description=nil)
88
+ if new_description
89
+ @description = new_description
90
+ else
91
+ @description || if superclass.kind_of?(ClassMethods)
92
+ superclass.description
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2021-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ #
5
+ # ronin-core is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published
7
+ # by the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # ronin-core is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with ronin-core. If not, see <https://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ module Ronin
20
+ module Core
21
+ module Metadata
22
+ #
23
+ # Adds a {ID::ClassMethods#id id} metadata attribute to a class.
24
+ #
25
+ # ### Example
26
+ #
27
+ # class MyClass
28
+ #
29
+ # include Ronin::Core::Metadata::ID
30
+ #
31
+ # id 'my_class'
32
+ #
33
+ # end
34
+ #
35
+ module ID
36
+ #
37
+ # Adds {ClassMethods} to the class.
38
+ #
39
+ # @param [Class] base
40
+ # The base class which is including {ID}.
41
+ #
42
+ # @private
43
+ #
44
+ def self.included(base)
45
+ base.extend ClassMethods
46
+ end
47
+
48
+ module ClassMethods
49
+ #
50
+ # Gets or sets the class `id`.
51
+ #
52
+ # @param [String, nil] new_id
53
+ # The optional new class `id` to set.
54
+ #
55
+ # @return [String, nil]
56
+ # The previously set class `id`.
57
+ #
58
+ # @example Setting the class `id`:
59
+ # class MyClass
60
+ # include Ronin::Core::Metadata::ID
61
+ # id 'my_class'
62
+ # end
63
+ #
64
+ # @example Getting the class `id`:
65
+ # MyClass.id
66
+ # # => "my_class"
67
+ #
68
+ def id(new_id=nil)
69
+ if new_id then @id = new_id
70
+ else @id
71
+ end
72
+ end
73
+ end
74
+
75
+ #
76
+ # The {ClassMethods#id id} of the class.
77
+ #
78
+ # @return [String, nil]
79
+ #
80
+ # @see ClassMethods#id
81
+ #
82
+ def class_id
83
+ self.class.id
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2021-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ #
5
+ # ronin-core is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published
7
+ # by the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # ronin-core is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with ronin-core. If not, see <https://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ module Ronin
20
+ module Core
21
+ module Metadata
22
+ #
23
+ # Adds a {References::ClassMethods#references references} metadata
24
+ # attribute to a class.
25
+ #
26
+ # ### Example
27
+ #
28
+ # class MyModule
29
+ #
30
+ # include Ronin::Core::Metadata::References
31
+ #
32
+ # references [
33
+ # "https://...",
34
+ # ...
35
+ # ]
36
+ #
37
+ # end
38
+ #
39
+ module References
40
+ #
41
+ # Adds {ClassMethods} to the class.
42
+ #
43
+ # @param [Class] base
44
+ # The base class which is including {References}.
45
+ #
46
+ # @api private
47
+ #
48
+ def self.included(base)
49
+ base.extend ClassMethods
50
+ end
51
+
52
+ module ClassMethods
53
+ #
54
+ # Gets or sets the reference links.
55
+ #
56
+ # @param [Array<String>, nil] new_references
57
+ # The optional new reference links to set.
58
+ #
59
+ # @return [Array<String>]
60
+ # The previously set reference links.
61
+ #
62
+ # @example Set the references:
63
+ # references [
64
+ # "https://...",
65
+ # ...
66
+ # ]
67
+ #
68
+ # @example Get the reference links:
69
+ # MyModule.references
70
+ # # => ["https://...", ...]
71
+ #
72
+ def references(new_references=nil)
73
+ if new_references
74
+ @references = references() + new_references
75
+ else
76
+ @references || if superclass.kind_of?(ClassMethods)
77
+ superclass.references
78
+ else
79
+ []
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright (c) 2021-2022 Hal Brodigan (postmodern.mod3 at gmail.com)
4
+ #
5
+ # ronin-core is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published
7
+ # by the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # ronin-core is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with ronin-core. If not, see <https://www.gnu.org/licenses/>.
17
+ #
18
+
19
+ module Ronin
20
+ module Core
21
+ module Metadata
22
+ #
23
+ # Adds a {Summary::ClassMethods#summary summary} metadata
24
+ # attribute to a class.
25
+ #
26
+ # ### Example
27
+ #
28
+ # class MyModule
29
+ #
30
+ # include Ronin::Core::Metadata::Summary
31
+ #
32
+ # summary "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
33
+ #
34
+ # end
35
+ #
36
+ module Summary
37
+ #
38
+ # Adds {ClassMethods} to the class.
39
+ #
40
+ # @param [Class] base
41
+ # The base class which is including {Summary}.
42
+ #
43
+ # @api private
44
+ #
45
+ def self.included(base)
46
+ base.extend ClassMethods
47
+ end
48
+
49
+ module ClassMethods
50
+ #
51
+ # Gets or sets the summary.
52
+ #
53
+ # @param [String, nil] new_summary
54
+ # The optional new summary text to set.
55
+ #
56
+ # @return [String, nil]
57
+ # The previously set summary text.
58
+ #
59
+ # @example Setting the summary:
60
+ # summary "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
61
+ #
62
+ # @example Getting the summary:
63
+ # MyModule.summary
64
+ #
65
+ def summary(new_summary=nil)
66
+ if new_summary
67
+ @summary = new_summary
68
+ else
69
+ @summary || if superclass.kind_of?(ClassMethods)
70
+ superclass.summary
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end