hanami-utils 1.3.2 → 1.3.7

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.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hanami
2
4
  module Utils
3
5
  # IO utils
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
- require 'multi_json'
4
+ require "multi_json"
3
5
  rescue LoadError
4
- require 'json'
6
+ require "json"
5
7
  end
6
8
 
7
9
  module Hanami
@@ -41,7 +43,7 @@ module Hanami
41
43
  end
42
44
  # rubocop:enable Style/ClassVars
43
45
 
44
- # Parse the given JSON paylod
46
+ # Parses the given JSON paylod
45
47
  #
46
48
  # @param payload [String] a JSON payload
47
49
  #
@@ -1,13 +1,15 @@
1
- require 'set'
2
- require 'date'
3
- require 'time'
4
- require 'pathname'
5
- require 'bigdecimal'
6
- require 'hanami/utils'
7
- require 'hanami/utils/string'
1
+ # frozen_string_literal: true
2
+
3
+ require "set"
4
+ require "date"
5
+ require "time"
6
+ require "pathname"
7
+ require "bigdecimal"
8
+ require "hanami/utils"
9
+ require "hanami/utils/string"
8
10
 
9
11
  unless defined?(Boolean)
10
- # Define top level constant Boolean, so it can be easily used by other libraries
12
+ # Defines top level constant Boolean, so it can be easily used by other libraries
11
13
  # in coercions DSLs
12
14
  #
13
15
  # @since 0.3.0
@@ -30,7 +32,7 @@ module Hanami
30
32
 
31
33
  # @since 0.8.0
32
34
  # @api private
33
- BOOLEAN_FALSE_STRING = '0'.freeze
35
+ BOOLEAN_FALSE_STRING = "0"
34
36
 
35
37
  # @since 0.8.0
36
38
  # @api private
@@ -325,7 +327,7 @@ module Hanami
325
327
  # # big complex represented as a string
326
328
  # input = Complex(2, 3)
327
329
  # Hanami::Utils::Kernel.Integer(input) # => TypeError
328
- def self.Integer(arg) # rubocop:disable Metrics/MethodLength
330
+ def self.Integer(arg)
329
331
  super(arg)
330
332
  rescue ArgumentError, TypeError, NoMethodError
331
333
  begin
@@ -416,7 +418,6 @@ module Hanami
416
418
  # input = BasicObject.new
417
419
  # Hanami::Utils::Kernel.BigDecimal(input) # => TypeError
418
420
  #
419
- # rubocop:disable Metrics/MethodLength
420
421
  def self.BigDecimal(arg, precision = ::Float::DIG)
421
422
  case arg
422
423
  when NilClass # This is only needed by Ruby 2.6
@@ -433,7 +434,6 @@ module Hanami
433
434
  rescue NoMethodError
434
435
  raise TypeError.new "can't convert #{inspect_type_error(arg)}into BigDecimal"
435
436
  end
436
- # rubocop:enable Metrics/MethodLength
437
437
 
438
438
  # Coerces the argument to be a Float.
439
439
  #
@@ -547,7 +547,7 @@ module Hanami
547
547
  # # big complex represented as a string
548
548
  # input = Complex(2, 3)
549
549
  # Hanami::Utils::Kernel.Float(input) # => TypeError
550
- def self.Float(arg) # rubocop:disable Metrics/MethodLength
550
+ def self.Float(arg)
551
551
  super(arg)
552
552
  rescue ArgumentError, TypeError
553
553
  begin
@@ -736,7 +736,8 @@ module Hanami
736
736
  # require 'hanami/utils/kernel'
737
737
  #
738
738
  # Hanami::Utils::Kernel.DateTime(3483943)
739
- # # => Time.at(3483943).to_datetime #<DateTime: 1970-02-10T08:45:43+01:00 ((2440628j,27943s,0n),+3600s,2299161j)>
739
+ # # => Time.at(3483943).to_datetime
740
+ # # #<DateTime: 1970-02-10T08:45:43+01:00 ((2440628j,27943s,0n),+3600s,2299161j)>
740
741
  #
741
742
  # Hanami::Utils::Kernel.DateTime(DateTime.now)
742
743
  # # => #<DateTime: 2014-04-18T09:33:49+02:00 ((2456766j,27229s,690849000n),+7200s,2299161j)>
@@ -896,7 +897,7 @@ module Hanami
896
897
  # # Missing #respond_to?
897
898
  # input = BasicObject.new
898
899
  # Hanami::Utils::Kernel.Boolean(input) # => TypeError
899
- def self.Boolean(arg) # rubocop:disable Metrics/MethodLength
900
+ def self.Boolean(arg)
900
901
  case arg
901
902
  when Numeric
902
903
  arg.to_i == BOOLEAN_TRUE_INTEGER
@@ -1012,7 +1013,7 @@ module Hanami
1012
1013
  # Hanami::Utils::Kernel.Symbol(input) # => TypeError
1013
1014
  def self.Symbol(arg)
1014
1015
  case arg
1015
- when '' then raise TypeError.new "can't convert #{inspect_type_error(arg)}into Symbol"
1016
+ when "" then raise TypeError.new "can't convert #{inspect_type_error(arg)}into Symbol"
1016
1017
  when ->(a) { a.respond_to?(:to_sym) } then arg.to_sym
1017
1018
  else
1018
1019
  raise TypeError.new "can't convert #{inspect_type_error(arg)}into Symbol"
@@ -1021,7 +1022,7 @@ module Hanami
1021
1022
  raise TypeError.new "can't convert #{inspect_type_error(arg)}into Symbol"
1022
1023
  end
1023
1024
 
1024
- # Check if the given argument is a string representation of a number
1025
+ # Checks if the given argument is a string representation of a number
1025
1026
  #
1026
1027
  # @param arg [Object] the input
1027
1028
  #
@@ -1042,11 +1043,11 @@ module Hanami
1042
1043
  # @since 0.4.3
1043
1044
  # @api private
1044
1045
  def self.inspect_type_error(arg)
1045
- (arg.respond_to?(:inspect) ? arg.inspect : arg.to_s) << ' '
1046
+ (arg.respond_to?(:inspect) ? arg.inspect : arg.to_s) + " "
1046
1047
  rescue NoMethodError
1047
1048
  # missing the #respond_to? method, fall back to returning the class' name
1048
1049
  begin
1049
- arg.class.name << ' instance '
1050
+ arg.class.name + " instance "
1050
1051
  rescue NoMethodError
1051
1052
  # missing the #class method, can't fall back to anything better than nothing
1052
1053
  # Callers will have to guess from their code
@@ -1055,7 +1056,7 @@ module Hanami
1055
1056
  end
1056
1057
 
1057
1058
  class << self
1058
- private :inspect_type_error # rubocop:disable Style/AccessModifierDeclarations
1059
+ private :inspect_type_error
1059
1060
  end
1060
1061
  end
1061
1062
  end
@@ -1,4 +1,6 @@
1
- require 'hanami/utils/kernel'
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/utils/kernel"
2
4
 
3
5
  module Hanami
4
6
  module Utils
@@ -48,7 +50,7 @@ module Hanami
48
50
  @paths = original.instance_variable_get(:@paths).dup
49
51
  end
50
52
 
51
- # Iterates thru the collection and yields the given block.
53
+ # Iterates through the collection and yields the given block.
52
54
  # It skips duplications and raises an error in case one of the paths
53
55
  # doesn't exist.
54
56
  #
@@ -115,7 +117,7 @@ module Hanami
115
117
  self
116
118
  end
117
119
 
118
- alias << push
120
+ alias_method :<<, :push
119
121
 
120
122
  # It freezes the object by preventing further modifications.
121
123
  #
@@ -156,7 +158,7 @@ module Hanami
156
158
 
157
159
  private
158
160
 
159
- # Allow subclasses to define their own policy to discover the realpath
161
+ # Allows subclasses to define their own policy to discover the realpath
160
162
  # of the given path.
161
163
  #
162
164
  # @since 0.2.0
@@ -1,5 +1,7 @@
1
- require 'hanami/utils/string'
2
- require 'hanami/utils/kernel'
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/utils/string"
4
+ require "hanami/utils/kernel"
3
5
 
4
6
  module Hanami
5
7
  module Utils
@@ -11,7 +13,7 @@ module Hanami
11
13
  #
12
14
  # @since 0.3.1
13
15
  # @api private
14
- DEFAULT_SEPARATOR = '/'.freeze
16
+ DEFAULT_SEPARATOR = "/"
15
17
 
16
18
  # Initialize the path prefix
17
19
  #
@@ -133,7 +135,7 @@ module Hanami
133
135
  # @see #relative
134
136
  def relative!
135
137
  @string.gsub!(/(?<!:)#{separator * 2}/, separator)
136
- @string[/\A#{separator}|^/] = ''
138
+ @string[/\A#{separator}|^/] = ""
137
139
 
138
140
  self
139
141
  end
@@ -12,7 +12,7 @@ module Hanami
12
12
  # @api private
13
13
  HASH_SEPARATOR = ","
14
14
 
15
- # Serialize input into a query string
15
+ # Serializes input into a query string
16
16
  #
17
17
  # @param input [Object] the input
18
18
  #
@@ -18,22 +18,22 @@ module Hanami
18
18
  end
19
19
  end
20
20
 
21
- # Escape codes for terminals to output strings in colors
21
+ # Escapes codes for terminals to output strings in colors
22
22
  #
23
23
  # @since 1.2.0
24
24
  # @api private
25
25
  COLORS = ::Hash[
26
- black: 30,
27
- red: 31,
28
- green: 32,
29
- yellow: 33,
30
- blue: 34,
26
+ black: 30,
27
+ red: 31,
28
+ green: 32,
29
+ yellow: 33,
30
+ blue: 34,
31
31
  magenta: 35,
32
- cyan: 36,
33
- gray: 37,
32
+ cyan: 36,
33
+ gray: 37,
34
34
  ].freeze
35
35
 
36
- # Colorize output
36
+ # Colorizes output
37
37
  # 8 colors available: black, red, green, yellow, blue, magenta, cyan, and gray
38
38
  #
39
39
  # @param input [#to_s] the string to colorize
@@ -1,30 +1,32 @@
1
- require 'hanami/utils/inflector'
2
- require 'transproc'
3
- require 'concurrent/map'
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/utils/inflector"
4
+ require "transproc"
5
+ require "concurrent/map"
4
6
 
5
7
  module Hanami
6
8
  module Utils
7
9
  # String on steroids
8
10
  #
9
11
  # @since 0.1.0
10
- class String # rubocop:disable Metrics/ClassLength
12
+ class String
11
13
  # Empty string for #classify
12
14
  #
13
15
  # @since 0.6.0
14
16
  # @api private
15
- EMPTY_STRING = ''.freeze
17
+ EMPTY_STRING = ""
16
18
 
17
19
  # Separator between Ruby namespaces
18
20
  #
19
21
  # @since 0.1.0
20
22
  # @api private
21
- NAMESPACE_SEPARATOR = '::'.freeze
23
+ NAMESPACE_SEPARATOR = "::"
22
24
 
23
25
  # Separator for #classify
24
26
  #
25
27
  # @since 0.3.0
26
28
  # @api private
27
- CLASSIFY_SEPARATOR = '_'.freeze
29
+ CLASSIFY_SEPARATOR = "_"
28
30
 
29
31
  # Regexp for #tokenize
30
32
  #
@@ -36,52 +38,53 @@ module Hanami
36
38
  #
37
39
  # @since 0.3.0
38
40
  # @api private
39
- TOKENIZE_SEPARATOR = '|'.freeze
41
+ TOKENIZE_SEPARATOR = "|"
40
42
 
41
43
  # Separator for #underscore
42
44
  #
43
45
  # @since 0.3.0
44
46
  # @api private
45
- UNDERSCORE_SEPARATOR = '/'.freeze
47
+ UNDERSCORE_SEPARATOR = "/"
46
48
 
47
49
  # gsub second parameter used in #underscore
48
50
  #
49
51
  # @since 0.3.0
50
52
  # @api private
51
- UNDERSCORE_DIVISION_TARGET = '\1_\2'.freeze
53
+ UNDERSCORE_DIVISION_TARGET = '\1_\2'
52
54
 
53
55
  # Separator for #titleize
54
56
  #
55
57
  # @since 0.4.0
56
58
  # @api private
57
- TITLEIZE_SEPARATOR = ' '.freeze
59
+ TITLEIZE_SEPARATOR = " "
58
60
 
59
61
  # Separator for #capitalize
60
62
  #
61
63
  # @since 0.5.2
62
64
  # @api private
63
- CAPITALIZE_SEPARATOR = ' '.freeze
65
+ CAPITALIZE_SEPARATOR = " "
64
66
 
65
67
  # Separator for #dasherize
66
68
  #
67
69
  # @since 0.4.0
68
70
  # @api private
69
- DASHERIZE_SEPARATOR = '-'.freeze
71
+ DASHERIZE_SEPARATOR = "-"
70
72
 
71
73
  # Regexp for #classify
72
74
  #
73
75
  # @since 0.3.4
74
76
  # @api private
75
- CLASSIFY_WORD_SEPARATOR = /#{CLASSIFY_SEPARATOR}|#{NAMESPACE_SEPARATOR}|#{UNDERSCORE_SEPARATOR}|#{DASHERIZE_SEPARATOR}/.freeze
77
+ CLASSIFY_WORD_SEPARATOR = /#{CLASSIFY_SEPARATOR}|#{NAMESPACE_SEPARATOR}|#{UNDERSCORE_SEPARATOR}|#{DASHERIZE_SEPARATOR}/.freeze # rubocop:disable Layout/LineLength
76
78
 
77
79
  @__transformations__ = Concurrent::Map.new
78
80
 
79
81
  extend Transproc::Registry
80
82
  extend Transproc::Composer
81
83
 
82
- # Apply the given transformation(s) to `input`
84
+ # Applies the given transformation(s) to `input`
83
85
  #
84
- # It performs a pipeline of transformations, by applying the given functions from `Hanami::Utils::String` and `::String`.
86
+ # It performs a pipeline of transformations, by applying the given
87
+ # functions from `Hanami::Utils::String` and `::String`.
85
88
  # The transformations are applied in the given order.
86
89
  #
87
90
  # It doesn't mutate the input, unless you use destructive methods from `::String`
@@ -129,8 +132,6 @@ module Hanami
129
132
  # Hanami::Utils::String.transform("Cherry", -> { "blossom" }))
130
133
  # # => ArgumentError: wrong number of arguments (given 1, expected 0)
131
134
  #
132
- # rubocop:disable Metrics/AbcSize
133
- # rubocop:disable Metrics/MethodLength
134
135
  def self.transform(input, *transformations)
135
136
  fn = @__transformations__.fetch_or_store(transformations.hash) do
136
137
  compose do |fns|
@@ -142,7 +143,7 @@ module Hanami
142
143
  elsif input.respond_to?(transformation)
143
144
  t(:bind, input, ->(i) { i.public_send(transformation, *args) })
144
145
  else
145
- raise NoMethodError.new(%(undefined method `#{transformation.inspect}' for #{input.inspect}:#{input.class}))
146
+ raise NoMethodError.new(%(undefined method `#{transformation.inspect}' for #{input.inspect}:#{input.class})) # rubocop:disable Layout/LineLength
146
147
  end
147
148
  end
148
149
  end
@@ -150,8 +151,6 @@ module Hanami
150
151
 
151
152
  fn.call(input)
152
153
  end
153
- # rubocop:enable Metrics/MethodLength
154
- # rubocop:enable Metrics/AbcSize
155
154
 
156
155
  # Extracted from `transproc` source code
157
156
  #
@@ -164,7 +163,7 @@ module Hanami
164
163
  binding.instance_exec(value, &fun)
165
164
  end
166
165
 
167
- # Return a titleized version of the string
166
+ # Returns a titleized version of the string
168
167
  #
169
168
  # @param input [::String] the input
170
169
  #
@@ -181,7 +180,7 @@ module Hanami
181
180
  underscore(string).split(CLASSIFY_SEPARATOR).map(&:capitalize).join(TITLEIZE_SEPARATOR)
182
181
  end
183
182
 
184
- # Return a capitalized version of the string
183
+ # Returns a capitalized version of the string
185
184
  #
186
185
  # @param input [::String] the input
187
186
  #
@@ -208,7 +207,7 @@ module Hanami
208
207
  tail.unshift(head.capitalize).join(CAPITALIZE_SEPARATOR)
209
208
  end
210
209
 
211
- # Return a CamelCase version of the string
210
+ # Returns a CamelCase version of the string
212
211
  #
213
212
  # @param input [::String] the input
214
213
  #
@@ -232,7 +231,7 @@ module Hanami
232
231
  words.zip(delimiters).join
233
232
  end
234
233
 
235
- # Return a downcased and underscore separated version of the string
234
+ # Returns a downcased and underscore separated version of the string
236
235
  #
237
236
  # Revised version of `ActiveSupport::Inflector.underscore` implementation
238
237
  # @see https://github.com/rails/rails/blob/feaa6e2048fe86bcf07e967d6e47b865e42e055b/activesupport/lib/active_support/inflector/methods.rb#L90
@@ -257,7 +256,7 @@ module Hanami
257
256
  string.downcase
258
257
  end
259
258
 
260
- # Return a downcased and dash separated version of the string
259
+ # Returns a downcased and dash separated version of the string
261
260
  #
262
261
  # @param input [::String] the input
263
262
  #
@@ -278,7 +277,7 @@ module Hanami
278
277
  underscore(string).split(CLASSIFY_SEPARATOR).join(DASHERIZE_SEPARATOR)
279
278
  end
280
279
 
281
- # Return the string without the Ruby namespace of the class
280
+ # Returns the string without the Ruby namespace of the class
282
281
  #
283
282
  # @param input [::String] the input
284
283
  #
@@ -296,7 +295,7 @@ module Hanami
296
295
  ::String.new(input.to_s).split(NAMESPACE_SEPARATOR).last
297
296
  end
298
297
 
299
- # Return the top level namespace name
298
+ # Returns the top level namespace name
300
299
  #
301
300
  # @param input [::String] the input
302
301
  #
@@ -314,7 +313,7 @@ module Hanami
314
313
  ::String.new(input.to_s).split(NAMESPACE_SEPARATOR).first
315
314
  end
316
315
 
317
- # Return a pluralized version of self.
316
+ # Returns a pluralized version of self.
318
317
  #
319
318
  # @param input [::String] the input
320
319
  #
@@ -334,7 +333,7 @@ module Hanami
334
333
  Inflector.pluralize(string)
335
334
  end
336
335
 
337
- # Return a singularized version of self.
336
+ # Returns a singularized version of self.
338
337
  #
339
338
  # @param input [::String] the input
340
339
  #
@@ -354,7 +353,7 @@ module Hanami
354
353
  Inflector.singularize(string)
355
354
  end
356
355
 
357
- # Replace the rightmost match of `pattern` with `replacement`
356
+ # Replaces the rightmost match of `pattern` with `replacement`
358
357
  #
359
358
  # If the pattern cannot be matched, it returns the original string.
360
359
  #
@@ -375,7 +374,7 @@ module Hanami
375
374
  # # => 'authors/books#index'
376
375
  def self.rsub(input, pattern, replacement)
377
376
  string = ::String.new(input.to_s)
378
- if i = string.rindex(pattern) # rubocop:disable Lint/AssignmentInCondition
377
+ if i = string.rindex(pattern)
379
378
  s = string.dup
380
379
  s[i] = replacement
381
380
  s
@@ -396,7 +395,7 @@ module Hanami
396
395
  @string = string.to_s
397
396
  end
398
397
 
399
- # Return a titleized version of the string
398
+ # Returns a titleized version of the string
400
399
  #
401
400
  # @return [Hanami::Utils::String] the transformed string
402
401
  #
@@ -412,7 +411,7 @@ module Hanami
412
411
  self.class.new underscore.split(CLASSIFY_SEPARATOR).map(&:capitalize).join(TITLEIZE_SEPARATOR)
413
412
  end
414
413
 
415
- # Return a capitalized version of the string
414
+ # Returns a capitalized version of the string
416
415
  #
417
416
  # @return [Hanami::Utils::String] the transformed string
418
417
  #
@@ -444,7 +443,7 @@ module Hanami
444
443
  )
445
444
  end
446
445
 
447
- # Return a CamelCase version of the string
446
+ # Returns a CamelCase version of the string
448
447
  #
449
448
  # @return [Hanami::Utils::String] the transformed string
450
449
  #
@@ -467,7 +466,7 @@ module Hanami
467
466
  self.class.new words.zip(delimiters).join
468
467
  end
469
468
 
470
- # Return a downcased and underscore separated version of the string
469
+ # Returns a downcased and underscore separated version of the string
471
470
  #
472
471
  # Revised version of `ActiveSupport::Inflector.underscore` implementation
473
472
  # @see https://github.com/rails/rails/blob/feaa6e2048fe86bcf07e967d6e47b865e42e055b/activesupport/lib/active_support/inflector/methods.rb#L90
@@ -491,7 +490,7 @@ module Hanami
491
490
  self.class.new new_string
492
491
  end
493
492
 
494
- # Return a downcased and dash separated version of the string
493
+ # Returns a downcased and dash separated version of the string
495
494
  #
496
495
  # @return [Hanami::Utils::String] the transformed string
497
496
  #
@@ -513,7 +512,7 @@ module Hanami
513
512
  self.class.new underscore.split(CLASSIFY_SEPARATOR).join(DASHERIZE_SEPARATOR)
514
513
  end
515
514
 
516
- # Return the string without the Ruby namespace of the class
515
+ # Returns the string without the Ruby namespace of the class
517
516
  #
518
517
  # @return [Hanami::Utils::String] the transformed string
519
518
  #
@@ -532,7 +531,7 @@ module Hanami
532
531
  self.class.new split(NAMESPACE_SEPARATOR).last
533
532
  end
534
533
 
535
- # Return the top level namespace name
534
+ # Returns the top level namespace name
536
535
  #
537
536
  # @return [Hanami::Utils::String] the transformed string
538
537
  #
@@ -573,9 +572,8 @@ module Hanami
573
572
  # 'Hanami::Utils'
574
573
  # 'Hanami::App'
575
574
  #
576
- # rubocop:disable Metrics/MethodLength
577
575
  def tokenize
578
- if match = TOKENIZE_REGEXP.match(@string) # rubocop:disable Lint/AssignmentInCondition
576
+ if match = TOKENIZE_REGEXP.match(@string)
579
577
  pre = match.pre_match
580
578
  post = match.post_match
581
579
  tokens = match[1].split(TOKENIZE_SEPARATOR)
@@ -588,9 +586,8 @@ module Hanami
588
586
 
589
587
  nil
590
588
  end
591
- # rubocop:enable Metrics/MethodLength
592
589
 
593
- # Return a pluralized version of self.
590
+ # Returns a pluralized version of self.
594
591
  #
595
592
  # @return [Hanami::Utils::String] the pluralized string.
596
593
  #
@@ -603,7 +600,7 @@ module Hanami
603
600
  self.class.new Inflector.pluralize(self)
604
601
  end
605
602
 
606
- # Return a singularized version of self.
603
+ # Returns a singularized version of self.
607
604
  #
608
605
  # @return [Hanami::Utils::String] the singularized string.
609
606
  #
@@ -636,7 +633,7 @@ module Hanami
636
633
  @string
637
634
  end
638
635
 
639
- alias to_str to_s
636
+ alias_method :to_str, :to_s
640
637
 
641
638
  # Equality
642
639
  #
@@ -648,9 +645,9 @@ module Hanami
648
645
  to_s == other
649
646
  end
650
647
 
651
- alias eql? ==
648
+ alias_method :eql?, :==
652
649
 
653
- # Split the string with the given pattern
650
+ # Splits the string with the given pattern
654
651
  #
655
652
  # @return [Array<::String>]
656
653
  #
@@ -662,7 +659,7 @@ module Hanami
662
659
  @string.split(pattern, limit)
663
660
  end
664
661
 
665
- # Replace the given pattern with the given replacement
662
+ # Replaces the given pattern with the given replacement
666
663
  #
667
664
  # @return [::String]
668
665
  #
@@ -678,7 +675,7 @@ module Hanami
678
675
  end
679
676
  end
680
677
 
681
- # Iterate through the string, matching the pattern.
678
+ # Iterates through the string, matching the pattern.
682
679
  # Either return all those patterns, or pass them to the block.
683
680
  #
684
681
  # @return [Array<::String>]
@@ -691,7 +688,7 @@ module Hanami
691
688
  @string.scan(pattern, &blk)
692
689
  end
693
690
 
694
- # Replace the rightmost match of `pattern` with `replacement`
691
+ # Replaces the rightmost match of `pattern` with `replacement`
695
692
  #
696
693
  # If the pattern cannot be matched, it returns the original string.
697
694
  #
@@ -717,7 +714,7 @@ module Hanami
717
714
  # puts result
718
715
  # # => #<Hanami::Utils::String:0x007fdb41232ed0 @string="authors/books#index">
719
716
  def rsub(pattern, replacement)
720
- if i = rindex(pattern) # rubocop:disable Lint/AssignmentInCondition
717
+ if i = rindex(pattern)
721
718
  s = @string.dup
722
719
  s[i] = replacement
723
720
  self.class.new s
@@ -726,21 +723,23 @@ module Hanami
726
723
  end
727
724
  end
728
725
 
729
- # Override Ruby's method_missing in order to provide ::String interface
726
+ # Overrides Ruby's method_missing in order to provide ::String interface
730
727
  #
731
728
  # @api private
732
729
  # @since 0.3.0
733
730
  #
734
731
  # @raise [NoMethodError] If doesn't respond to the given method
735
732
  def method_missing(method_name, *args, &blk)
736
- raise NoMethodError.new(%(undefined method `#{method_name}' for "#{@string}":#{self.class})) unless respond_to?(method_name)
733
+ unless respond_to?(method_name)
734
+ raise NoMethodError.new(%(undefined method `#{method_name}' for "#{@string}":#{self.class}))
735
+ end
737
736
 
738
737
  s = @string.__send__(method_name, *args, &blk)
739
738
  s = self.class.new(s) if s.is_a?(::String)
740
739
  s
741
740
  end
742
741
 
743
- # Override Ruby's respond_to_missing? in order to support ::String interface
742
+ # Overrides Ruby's respond_to_missing? in order to support ::String interface
744
743
  #
745
744
  # @api private
746
745
  # @since 0.3.0