sigterm_extensions 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +17 -0
- data/Gemfile +6 -0
- data/LICENSE.md +0 -0
- data/README.md +0 -0
- data/bin/ctxirb +156 -0
- data/lib/git.rb +166 -0
- data/lib/git/LICENSE +21 -0
- data/lib/git/author.rb +14 -0
- data/lib/git/base.rb +551 -0
- data/lib/git/base/factory.rb +75 -0
- data/lib/git/branch.rb +126 -0
- data/lib/git/branches.rb +71 -0
- data/lib/git/config.rb +22 -0
- data/lib/git/diff.rb +159 -0
- data/lib/git/index.rb +5 -0
- data/lib/git/lib.rb +1041 -0
- data/lib/git/log.rb +128 -0
- data/lib/git/object.rb +312 -0
- data/lib/git/path.rb +31 -0
- data/lib/git/remote.rb +36 -0
- data/lib/git/repository.rb +6 -0
- data/lib/git/stash.rb +27 -0
- data/lib/git/stashes.rb +55 -0
- data/lib/git/status.rb +199 -0
- data/lib/git/version.rb +5 -0
- data/lib/git/working_directory.rb +4 -0
- data/lib/sigterm_extensions.rb +75 -0
- data/lib/sigterm_extensions/all.rb +12 -0
- data/lib/sigterm_extensions/backtrace_cleaner.rb +129 -0
- data/lib/sigterm_extensions/callbacks.rb +847 -0
- data/lib/sigterm_extensions/concern.rb +169 -0
- data/lib/sigterm_extensions/configurable.rb +38 -0
- data/lib/sigterm_extensions/core_ext.rb +4 -0
- data/lib/sigterm_extensions/core_ext/array.rb +3 -0
- data/lib/sigterm_extensions/core_ext/array/extract.rb +19 -0
- data/lib/sigterm_extensions/core_ext/array/extract_options.rb +29 -0
- data/lib/sigterm_extensions/core_ext/class.rb +3 -0
- data/lib/sigterm_extensions/core_ext/class/attribute.rb +139 -0
- data/lib/sigterm_extensions/core_ext/class/attribute_accessors.rb +4 -0
- data/lib/sigterm_extensions/core_ext/class/subclasses.rb +52 -0
- data/lib/sigterm_extensions/core_ext/custom.rb +12 -0
- data/lib/sigterm_extensions/core_ext/digest.rb +3 -0
- data/lib/sigterm_extensions/core_ext/digest/uuid.rb +51 -0
- data/lib/sigterm_extensions/core_ext/enumerable.rb +232 -0
- data/lib/sigterm_extensions/core_ext/file.rb +3 -0
- data/lib/sigterm_extensions/core_ext/file/atomic.rb +68 -0
- data/lib/sigterm_extensions/core_ext/hash.rb +3 -0
- data/lib/sigterm_extensions/core_ext/hash/deep_merge.rb +41 -0
- data/lib/sigterm_extensions/core_ext/hash/deep_transform_values.rb +44 -0
- data/lib/sigterm_extensions/core_ext/hash/except.rb +22 -0
- data/lib/sigterm_extensions/core_ext/hash/keys.rb +141 -0
- data/lib/sigterm_extensions/core_ext/hash/reverse_merge.rb +23 -0
- data/lib/sigterm_extensions/core_ext/hash/slice.rb +24 -0
- data/lib/sigterm_extensions/core_ext/kernel.rb +3 -0
- data/lib/sigterm_extensions/core_ext/kernel/concern.rb +12 -0
- data/lib/sigterm_extensions/core_ext/kernel/reporting.rb +43 -0
- data/lib/sigterm_extensions/core_ext/kernel/singleton_class.rb +6 -0
- data/lib/sigterm_extensions/core_ext/load_error.rb +7 -0
- data/lib/sigterm_extensions/core_ext/module.rb +3 -0
- data/lib/sigterm_extensions/core_ext/module/aliasing.rb +29 -0
- data/lib/sigterm_extensions/core_ext/module/anonymous.rb +28 -0
- data/lib/sigterm_extensions/core_ext/module/attr_internal.rb +36 -0
- data/lib/sigterm_extensions/core_ext/module/attribute_accessors.rb +208 -0
- data/lib/sigterm_extensions/core_ext/module/attribute_accessors_per_thread.rb +146 -0
- data/lib/sigterm_extensions/core_ext/module/concerning.rb +132 -0
- data/lib/sigterm_extensions/core_ext/module/delegation.rb +319 -0
- data/lib/sigterm_extensions/core_ext/module/redefine_method.rb +38 -0
- data/lib/sigterm_extensions/core_ext/module/remove_method.rb +15 -0
- data/lib/sigterm_extensions/core_ext/name_error.rb +36 -0
- data/lib/sigterm_extensions/core_ext/object.rb +3 -0
- data/lib/sigterm_extensions/core_ext/object/blank.rb +153 -0
- data/lib/sigterm_extensions/core_ext/object/colors.rb +39 -0
- data/lib/sigterm_extensions/core_ext/object/duplicable.rb +47 -0
- data/lib/sigterm_extensions/core_ext/object/inclusion.rb +27 -0
- data/lib/sigterm_extensions/core_ext/object/instance_variables.rb +28 -0
- data/lib/sigterm_extensions/core_ext/object/methods.rb +61 -0
- data/lib/sigterm_extensions/core_ext/object/with_options.rb +80 -0
- data/lib/sigterm_extensions/core_ext/range.rb +3 -0
- data/lib/sigterm_extensions/core_ext/range/compare_range.rb +74 -0
- data/lib/sigterm_extensions/core_ext/range/conversions.rb +39 -0
- data/lib/sigterm_extensions/core_ext/range/overlaps.rb +8 -0
- data/lib/sigterm_extensions/core_ext/securerandom.rb +43 -0
- data/lib/sigterm_extensions/core_ext/string.rb +3 -0
- data/lib/sigterm_extensions/core_ext/string/access.rb +93 -0
- data/lib/sigterm_extensions/core_ext/string/filters.rb +143 -0
- data/lib/sigterm_extensions/core_ext/string/starts_ends_with.rb +4 -0
- data/lib/sigterm_extensions/core_ext/string/strip.rb +25 -0
- data/lib/sigterm_extensions/core_ext/tryable.rb +132 -0
- data/lib/sigterm_extensions/descendants_tracker.rb +108 -0
- data/lib/sigterm_extensions/gem_methods.rb +47 -0
- data/lib/sigterm_extensions/hash_binding.rb +16 -0
- data/lib/sigterm_extensions/inflector.rb +339 -0
- data/lib/sigterm_extensions/inflector/acronyms.rb +42 -0
- data/lib/sigterm_extensions/inflector/inflections.rb +249 -0
- data/lib/sigterm_extensions/inflector/inflections/defaults.rb +117 -0
- data/lib/sigterm_extensions/inflector/rules.rb +37 -0
- data/lib/sigterm_extensions/inflector/version.rb +8 -0
- data/lib/sigterm_extensions/interactive_editor.rb +120 -0
- data/lib/sigterm_extensions/lazy.rb +34 -0
- data/lib/sigterm_extensions/lazy_load_hooks.rb +79 -0
- data/lib/sigterm_extensions/option_merger.rb +32 -0
- data/lib/sigterm_extensions/ordered_hash.rb +48 -0
- data/lib/sigterm_extensions/ordered_options.rb +83 -0
- data/lib/sigterm_extensions/paths.rb +235 -0
- data/lib/sigterm_extensions/per_thread_registry.rb +58 -0
- data/lib/sigterm_extensions/proxy_object.rb +14 -0
- data/lib/sigterm_extensions/staging/boot.rb +31 -0
- data/lib/sigterm_extensions/staging/boot/bundler_patch.rb +24 -0
- data/lib/sigterm_extensions/staging/boot/command.rb +26 -0
- data/lib/sigterm_extensions/staging/boot/gemfile_next_auto_sync.rb +79 -0
- data/lib/sigterm_extensions/version.rb +4 -0
- data/lib/sigterm_extensions/wrappable.rb +16 -0
- data/sigterm_extensions.gemspec +42 -0
- data/templates/dotpryrc.rb.erb +124 -0
- metadata +315 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SigtermExtensions
|
4
|
+
class Inflector
|
5
|
+
# A set of acronyms
|
6
|
+
#
|
7
|
+
# @since 0.1.2
|
8
|
+
# @api private
|
9
|
+
class Acronyms
|
10
|
+
attr_reader :regex
|
11
|
+
|
12
|
+
# @since 0.1.2
|
13
|
+
# @api private
|
14
|
+
def initialize
|
15
|
+
@rules = {}
|
16
|
+
define_regex_patterns
|
17
|
+
end
|
18
|
+
|
19
|
+
# @since 0.1.2
|
20
|
+
# @api private
|
21
|
+
def apply_to(word, capitalize = true)
|
22
|
+
@rules[word.downcase] || (capitalize ? word.capitalize : word)
|
23
|
+
end
|
24
|
+
|
25
|
+
# @since 0.1.2
|
26
|
+
# @api private
|
27
|
+
def add(rule, replacement)
|
28
|
+
@rules[rule] = replacement
|
29
|
+
define_regex_patterns
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# @since 0.1.2
|
35
|
+
# @api private
|
36
|
+
def define_regex_patterns
|
37
|
+
regex = @rules.empty? ? /(?=a)b/ : /#{@rules.values.join("|")}/
|
38
|
+
@regex = /(?:(?<=([A-Za-z\d]))|\b)(#{regex})(?=\b|[^a-z])/
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,249 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "set"
|
4
|
+
require_relative "rules"
|
5
|
+
require_relative "acronyms"
|
6
|
+
|
7
|
+
module SigtermExtensions
|
8
|
+
class Inflector
|
9
|
+
# Inflections
|
10
|
+
#
|
11
|
+
# @since 0.1.0
|
12
|
+
class Inflections
|
13
|
+
require_relative "inflections/defaults"
|
14
|
+
|
15
|
+
# Instantiate a set of inflection rules.
|
16
|
+
# It adds the default rules and the optional customizations, passed as a block.
|
17
|
+
#
|
18
|
+
# @param blk [Proc] the optional, custom rules
|
19
|
+
#
|
20
|
+
# @since 0.1.0
|
21
|
+
# @api private
|
22
|
+
def self.build(&blk)
|
23
|
+
new do |inflect|
|
24
|
+
Defaults.call(inflect)
|
25
|
+
blk.call(inflect) if block_given?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Pluralization rules
|
30
|
+
#
|
31
|
+
# @return [Dry::Inflector::Rules]
|
32
|
+
#
|
33
|
+
# @since 0.1.0
|
34
|
+
# @api private
|
35
|
+
attr_reader :plurals
|
36
|
+
|
37
|
+
# Singularization rules
|
38
|
+
#
|
39
|
+
# @return [Dry::Inflector::Rules]
|
40
|
+
#
|
41
|
+
# @since 0.1.0
|
42
|
+
# @api private
|
43
|
+
attr_reader :singulars
|
44
|
+
|
45
|
+
# Uncountable rules
|
46
|
+
#
|
47
|
+
# @return [Set]
|
48
|
+
#
|
49
|
+
# @since 0.1.0
|
50
|
+
# @api private
|
51
|
+
attr_reader :uncountables
|
52
|
+
|
53
|
+
# Human rules
|
54
|
+
#
|
55
|
+
# @return [Dry::Inflector::Rules]
|
56
|
+
#
|
57
|
+
# @since 0.1.0
|
58
|
+
# @api private
|
59
|
+
attr_reader :humans
|
60
|
+
|
61
|
+
# Acronyms
|
62
|
+
#
|
63
|
+
# @return [Dry::Inflector::Acronyms]
|
64
|
+
#
|
65
|
+
# @since 0.1.2
|
66
|
+
# @api private
|
67
|
+
attr_reader :acronyms
|
68
|
+
|
69
|
+
# Instantiate the rules
|
70
|
+
#
|
71
|
+
# @return [Dry::Inflector::Inflections]
|
72
|
+
# @yieldparam [self]
|
73
|
+
#
|
74
|
+
# @since 0.1.0
|
75
|
+
# @api private
|
76
|
+
def initialize
|
77
|
+
@plurals = Rules.new
|
78
|
+
@singulars = Rules.new
|
79
|
+
@humans = Rules.new
|
80
|
+
@uncountables = Set[]
|
81
|
+
@acronyms = Acronyms.new
|
82
|
+
|
83
|
+
yield(self) if block_given?
|
84
|
+
end
|
85
|
+
|
86
|
+
# Add a custom pluralization rule
|
87
|
+
#
|
88
|
+
# Specifies a new pluralization rule and its replacement.
|
89
|
+
# The rule can either be a string or a regular expression.
|
90
|
+
# The replacement should always be a string that may include references to the matched data from the rule.
|
91
|
+
#
|
92
|
+
# @param rule [String, Regexp] the rule
|
93
|
+
# @param replacement [String] the replacement
|
94
|
+
#
|
95
|
+
# @since 0.1.0
|
96
|
+
#
|
97
|
+
# @example
|
98
|
+
# require "dry/inflector"
|
99
|
+
#
|
100
|
+
# inflector = Dry::Inflector.new do |inflections|
|
101
|
+
# inflections.plural "virus", "viruses"
|
102
|
+
# end
|
103
|
+
def plural(rule, replacement)
|
104
|
+
rule(rule, replacement, plurals)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Add a custom singularization rule
|
108
|
+
#
|
109
|
+
# Specifies a new singularization rule and its replacement.
|
110
|
+
# The rule can either be a string or a regular expression.
|
111
|
+
# The replacement should always be a string that may include references to the matched data from the rule.
|
112
|
+
#
|
113
|
+
# @param rule [String, Regexp] the rule
|
114
|
+
# @param replacement [String] the replacement
|
115
|
+
#
|
116
|
+
# @since 0.1.0
|
117
|
+
#
|
118
|
+
# @example
|
119
|
+
# require "dry/inflector"
|
120
|
+
#
|
121
|
+
# inflector = Dry::Inflector.new do |inflections|
|
122
|
+
# inflections.singular "thieves", "thief"
|
123
|
+
# end
|
124
|
+
def singular(rule, replacement)
|
125
|
+
rule(rule, replacement, singulars)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Add a custom pluralization rule
|
129
|
+
#
|
130
|
+
# Specifies a new irregular that applies to both pluralization and singularization at the same time.
|
131
|
+
# This can only be used for strings, not regular expressions.
|
132
|
+
# You simply pass the irregular in singular and plural form.
|
133
|
+
#
|
134
|
+
# @param singular [String] the singular
|
135
|
+
# @param plural [String] the plural
|
136
|
+
#
|
137
|
+
# @since 0.1.0
|
138
|
+
#
|
139
|
+
# @example
|
140
|
+
# require "dry/inflector"
|
141
|
+
#
|
142
|
+
# inflector = Dry::Inflector.new do |inflections|
|
143
|
+
# inflections.singular "octopus", "octopi"
|
144
|
+
# end
|
145
|
+
def irregular(singular, plural)
|
146
|
+
uncountables.delete(singular)
|
147
|
+
uncountables.delete(plural)
|
148
|
+
|
149
|
+
add_irregular(singular, plural, plurals)
|
150
|
+
add_irregular(plural, singular, singulars)
|
151
|
+
end
|
152
|
+
|
153
|
+
# Add a custom rule for uncountable words
|
154
|
+
#
|
155
|
+
# Uncountable will not be inflected
|
156
|
+
#
|
157
|
+
# @param [Enumerable<String>] words
|
158
|
+
#
|
159
|
+
# @since 0.1.0
|
160
|
+
#
|
161
|
+
# @example
|
162
|
+
# require "dry/inflector"
|
163
|
+
#
|
164
|
+
# inflector = Dry::Inflector.new do |inflections|
|
165
|
+
# inflections.uncountable "money"
|
166
|
+
# inflections.uncountable "money", "information"
|
167
|
+
# inflections.uncountable %w(money information rice)
|
168
|
+
# end
|
169
|
+
def uncountable(*words)
|
170
|
+
uncountables.merge(words.flatten)
|
171
|
+
end
|
172
|
+
|
173
|
+
# Add one or more acronyms
|
174
|
+
#
|
175
|
+
# Acronyms affect how basic operations are performed, such
|
176
|
+
# as camelize/underscore.
|
177
|
+
#
|
178
|
+
# @param words [Array<String>] a list of acronyms
|
179
|
+
#
|
180
|
+
# @since 0.1.2
|
181
|
+
#
|
182
|
+
# @example
|
183
|
+
# require "dry/inflector"
|
184
|
+
#
|
185
|
+
# inflector = Dry::Inflector.new do |inflections|
|
186
|
+
# inflections.acronym "HTML"
|
187
|
+
# end
|
188
|
+
#
|
189
|
+
# inflector.camelize("html") # => "HTML"
|
190
|
+
# inflector.underscore("HTMLIsFun") # => "html_is_fun"
|
191
|
+
def acronym(*words)
|
192
|
+
words.each { |word| @acronyms.add(word.downcase, word) }
|
193
|
+
end
|
194
|
+
|
195
|
+
# Add a custom humanize rule
|
196
|
+
#
|
197
|
+
# Specifies a humanized form of a string by a regular expression rule or by a string mapping.
|
198
|
+
# When using a regular expression based replacement, the normal humanize formatting is called after the replacement.
|
199
|
+
# When a string is used, the human form should be specified as desired (example: `"The name"`, not `"the_name"`)
|
200
|
+
#
|
201
|
+
# @param rule [String, Regexp] the rule
|
202
|
+
# @param replacement [String] the replacement
|
203
|
+
#
|
204
|
+
# @since 0.1.0
|
205
|
+
#
|
206
|
+
# @example
|
207
|
+
# require "dry/inflector"
|
208
|
+
#
|
209
|
+
# inflector = Dry::Inflector.new do |inflections|
|
210
|
+
# inflections.human(/_cnt$/i, '\1_count')
|
211
|
+
# inflections.human("legacy_col_person_name", "Name")
|
212
|
+
# end
|
213
|
+
def human(rule, replacement)
|
214
|
+
humans.insert(0, [rule, replacement])
|
215
|
+
end
|
216
|
+
|
217
|
+
private
|
218
|
+
|
219
|
+
# Add irregular inflection
|
220
|
+
#
|
221
|
+
# @param rule [String] the rule
|
222
|
+
# @param replacement [String] the replacement
|
223
|
+
#
|
224
|
+
# @return [undefined]
|
225
|
+
#
|
226
|
+
# @since 0.1.0
|
227
|
+
# @api private
|
228
|
+
def add_irregular(rule, replacement, target)
|
229
|
+
head, *tail = rule.chars.to_a
|
230
|
+
rule(/(#{head})#{tail.join}\z/i, '\1' + replacement[1..-1], target)
|
231
|
+
end
|
232
|
+
|
233
|
+
# Add a new rule
|
234
|
+
#
|
235
|
+
# @param rule [String, Regexp] the rule
|
236
|
+
# @param replacement [String, Regexp] the replacement
|
237
|
+
# @param target [Dry::Inflector::Rules] the target
|
238
|
+
#
|
239
|
+
# @since 0.1.0
|
240
|
+
# @api private
|
241
|
+
def rule(rule, replacement, target)
|
242
|
+
uncountables.delete(rule)
|
243
|
+
uncountables.delete(replacement)
|
244
|
+
|
245
|
+
target.insert(0, [rule, replacement])
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SigtermExtensions
|
4
|
+
class Inflector
|
5
|
+
class Inflections
|
6
|
+
# Default inflections
|
7
|
+
#
|
8
|
+
# @since 0.1.0
|
9
|
+
# @api private
|
10
|
+
#
|
11
|
+
# rubocop:disable Metrics/AbcSize
|
12
|
+
# rubocop:disable Metrics/MethodLength
|
13
|
+
module Defaults
|
14
|
+
# @since 0.1.0
|
15
|
+
# @api private
|
16
|
+
def self.call(inflect)
|
17
|
+
plural(inflect)
|
18
|
+
singular(inflect)
|
19
|
+
irregular(inflect)
|
20
|
+
uncountable(inflect)
|
21
|
+
acronyms(inflect)
|
22
|
+
end
|
23
|
+
|
24
|
+
# @since 0.1.0
|
25
|
+
# @api private
|
26
|
+
def self.plural(inflect)
|
27
|
+
inflect.plural(/\z/, "s")
|
28
|
+
inflect.plural(/s\z/i, "s")
|
29
|
+
inflect.plural(/(ax|test)is\z/i, '\1es')
|
30
|
+
inflect.plural(/(.*)us\z/i, '\1uses')
|
31
|
+
inflect.plural(/(octop|vir|cact)us\z/i, '\1i')
|
32
|
+
inflect.plural(/(octop|vir)i\z/i, '\1i')
|
33
|
+
inflect.plural(/(alias|status)\z/i, '\1es')
|
34
|
+
inflect.plural(/(buffal|domin|ech|embarg|her|mosquit|potat|tomat)o\z/i, '\1oes')
|
35
|
+
inflect.plural(/(?<!b)um\z/i, '\1a')
|
36
|
+
inflect.plural(/([ti])a\z/i, '\1a')
|
37
|
+
inflect.plural(/sis\z/i, "ses")
|
38
|
+
inflect.plural(/(.*)(?:([^f]))f[e]*\z/i, '\1\2ves')
|
39
|
+
inflect.plural(/(hive|proof)\z/i, '\1s') # TODO: proof can be moved in the above regexp
|
40
|
+
inflect.plural(/([^aeiouy]|qu)y\z/i, '\1ies')
|
41
|
+
inflect.plural(/(x|ch|ss|sh)\z/i, '\1es')
|
42
|
+
inflect.plural(/(stoma|epo)ch\z/i, '\1chs')
|
43
|
+
inflect.plural(/(matr|vert|ind)(?:ix|ex)\z/i, '\1ices')
|
44
|
+
inflect.plural(/([m|l])ouse\z/i, '\1ice')
|
45
|
+
inflect.plural(/([m|l])ice\z/i, '\1ice')
|
46
|
+
inflect.plural(/^(ox)\z/i, '\1en')
|
47
|
+
inflect.plural(/^(oxen)\z/i, '\1')
|
48
|
+
inflect.plural(/(quiz)\z/i, '\1zes')
|
49
|
+
inflect.plural(/(.*)non\z/i, '\1na')
|
50
|
+
inflect.plural(/(.*)ma\z/i, '\1mata')
|
51
|
+
inflect.plural(/(.*)(eau|eaux)\z/, '\1eaux')
|
52
|
+
end
|
53
|
+
|
54
|
+
# @since 0.1.0
|
55
|
+
# @api private
|
56
|
+
def self.singular(inflect)
|
57
|
+
inflect.singular(/s\z/i, "")
|
58
|
+
inflect.singular(/(n)ews\z/i, '\1ews')
|
59
|
+
inflect.singular(/([ti])a\z/i, '\1um')
|
60
|
+
inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)\z/i, '\1\2sis')
|
61
|
+
inflect.singular(/(^analy)(sis|ses)\z/i, '\1sis')
|
62
|
+
inflect.singular(/([^f])ves\z/i, '\1fe')
|
63
|
+
inflect.singular(/(hive)s\z/i, '\1')
|
64
|
+
inflect.singular(/(tive)s\z/i, '\1')
|
65
|
+
inflect.singular(/([lr])ves\z/i, '\1f')
|
66
|
+
inflect.singular(/([^aeiouy]|qu)ies\z/i, '\1y')
|
67
|
+
inflect.singular(/(s)eries\z/i, '\1eries')
|
68
|
+
inflect.singular(/(m)ovies\z/i, '\1ovie')
|
69
|
+
inflect.singular(/(ss)\z/i, '\1')
|
70
|
+
inflect.singular(/(x|ch|ss|sh)es\z/i, '\1')
|
71
|
+
inflect.singular(/([m|l])ice\z/i, '\1ouse')
|
72
|
+
inflect.singular(/(bus)(es)?\z/i, '\1')
|
73
|
+
inflect.singular(/(o)es\z/i, '\1')
|
74
|
+
inflect.singular(/(shoe)s\z/i, '\1')
|
75
|
+
inflect.singular(/(cris|ax|test)(is|es)\z/i, '\1is')
|
76
|
+
inflect.singular(/(octop|vir)(us|i)\z/i, '\1us')
|
77
|
+
inflect.singular(/(alias|status)(es)?\z/i, '\1')
|
78
|
+
inflect.singular(/^(ox)en/i, '\1')
|
79
|
+
inflect.singular(/(vert|ind)ices\z/i, '\1ex')
|
80
|
+
inflect.singular(/(matr)ices\z/i, '\1ix')
|
81
|
+
inflect.singular(/(quiz)zes\z/i, '\1')
|
82
|
+
inflect.singular(/(database)s\z/i, '\1')
|
83
|
+
end
|
84
|
+
|
85
|
+
# @since 0.1.0
|
86
|
+
# @api private
|
87
|
+
def self.irregular(inflect)
|
88
|
+
inflect.irregular("person", "people")
|
89
|
+
inflect.irregular("man", "men")
|
90
|
+
inflect.irregular("human", "humans") # NOTE: this is here only to override the previous rule
|
91
|
+
inflect.irregular("child", "children")
|
92
|
+
inflect.irregular("sex", "sexes")
|
93
|
+
inflect.irregular("foot", "feet")
|
94
|
+
inflect.irregular("tooth", "teeth")
|
95
|
+
inflect.irregular("goose", "geese")
|
96
|
+
inflect.irregular("forum", "forums") # FIXME: this is here because I need to fix the "um" regexp
|
97
|
+
end
|
98
|
+
|
99
|
+
# @since 0.1.0
|
100
|
+
# @api private
|
101
|
+
def self.uncountable(inflect)
|
102
|
+
inflect.uncountable(%w[hovercraft moose deer milk rain Swiss grass equipment information rice money species series fish sheep jeans])
|
103
|
+
end
|
104
|
+
|
105
|
+
# @since 0.1.2
|
106
|
+
# @api private
|
107
|
+
def self.acronyms(inflect)
|
108
|
+
inflect.acronym(*%w[JSON HTTP OpenSSL HMAC])
|
109
|
+
end
|
110
|
+
|
111
|
+
private_class_method :plural, :singular, :irregular, :uncountable, :acronyms
|
112
|
+
end
|
113
|
+
# rubocop:enable Metrics/MethodLength
|
114
|
+
# rubocop:enable Metrics/AbcSize
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SigtermExtensions
|
4
|
+
class Inflector
|
5
|
+
# A set of inflection rules
|
6
|
+
#
|
7
|
+
# @since 0.1.0
|
8
|
+
# @api private
|
9
|
+
class Rules
|
10
|
+
# @since 0.1.0
|
11
|
+
# @api private
|
12
|
+
def initialize
|
13
|
+
@rules = []
|
14
|
+
end
|
15
|
+
|
16
|
+
# @since 0.1.0
|
17
|
+
# @api private
|
18
|
+
def apply_to(word)
|
19
|
+
result = word.dup
|
20
|
+
each { |rule, replacement| break if result.gsub!(rule, replacement) }
|
21
|
+
result
|
22
|
+
end
|
23
|
+
|
24
|
+
# @since 0.1.0
|
25
|
+
# @api private
|
26
|
+
def insert(index, array)
|
27
|
+
@rules.insert(index, array)
|
28
|
+
end
|
29
|
+
|
30
|
+
# @since 0.1.0
|
31
|
+
# @api private
|
32
|
+
def each(&blk)
|
33
|
+
@rules.each(&blk)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|