hanami-utils 1.3.7 → 2.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
@@ -50,7 +50,7 @@ module Hanami
50
50
  @paths = original.instance_variable_get(:@paths).dup
51
51
  end
52
52
 
53
- # Iterates through the collection and yields the given block.
53
+ # Iterates thru the collection and yields the given block.
54
54
  # It skips duplications and raises an error in case one of the paths
55
55
  # doesn't exist.
56
56
  #
@@ -117,7 +117,7 @@ module Hanami
117
117
  self
118
118
  end
119
119
 
120
- alias_method :<<, :push
120
+ alias << push
121
121
 
122
122
  # It freezes the object by preventing further modifications.
123
123
  #
@@ -158,7 +158,7 @@ module Hanami
158
158
 
159
159
  private
160
160
 
161
- # Allows subclasses to define their own policy to discover the realpath
161
+ # Allow subclasses to define their own policy to discover the realpath
162
162
  # of the given path.
163
163
  #
164
164
  # @since 0.2.0
@@ -12,7 +12,7 @@ module Hanami
12
12
  # @api private
13
13
  HASH_SEPARATOR = ","
14
14
 
15
- # Serializes input into a query string
15
+ # Serialize 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
- # Escapes codes for terminals to output strings in colors
21
+ # Escape 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
- # Colorizes output
36
+ # Colorize 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,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "hanami/utils/inflector"
4
3
  require "transproc"
5
4
  require "concurrent/map"
6
5
 
@@ -9,7 +8,7 @@ module Hanami
9
8
  # String on steroids
10
9
  #
11
10
  # @since 0.1.0
12
- class String
11
+ class String # rubocop:disable Metrics/ClassLength
13
12
  # Empty string for #classify
14
13
  #
15
14
  # @since 0.6.0
@@ -74,17 +73,16 @@ module Hanami
74
73
  #
75
74
  # @since 0.3.4
76
75
  # @api private
77
- CLASSIFY_WORD_SEPARATOR = /#{CLASSIFY_SEPARATOR}|#{NAMESPACE_SEPARATOR}|#{UNDERSCORE_SEPARATOR}|#{DASHERIZE_SEPARATOR}/.freeze # rubocop:disable Layout/LineLength
76
+ CLASSIFY_WORD_SEPARATOR = /#{CLASSIFY_SEPARATOR}|#{NAMESPACE_SEPARATOR}|#{UNDERSCORE_SEPARATOR}|#{DASHERIZE_SEPARATOR}/.freeze
78
77
 
79
78
  @__transformations__ = Concurrent::Map.new
80
79
 
81
80
  extend Transproc::Registry
82
81
  extend Transproc::Composer
83
82
 
84
- # Applies the given transformation(s) to `input`
83
+ # Apply the given transformation(s) to `input`
85
84
  #
86
- # It performs a pipeline of transformations, by applying the given
87
- # functions from `Hanami::Utils::String` and `::String`.
85
+ # It performs a pipeline of transformations, by applying the given functions from `Hanami::Utils::String` and `::String`.
88
86
  # The transformations are applied in the given order.
89
87
  #
90
88
  # It doesn't mutate the input, unless you use destructive methods from `::String`
@@ -132,6 +130,8 @@ module Hanami
132
130
  # Hanami::Utils::String.transform("Cherry", -> { "blossom" }))
133
131
  # # => ArgumentError: wrong number of arguments (given 1, expected 0)
134
132
  #
133
+ # rubocop:disable Metrics/AbcSize
134
+ # rubocop:disable Metrics/MethodLength
135
135
  def self.transform(input, *transformations)
136
136
  fn = @__transformations__.fetch_or_store(transformations.hash) do
137
137
  compose do |fns|
@@ -143,7 +143,7 @@ module Hanami
143
143
  elsif input.respond_to?(transformation)
144
144
  t(:bind, input, ->(i) { i.public_send(transformation, *args) })
145
145
  else
146
- raise NoMethodError.new(%(undefined method `#{transformation.inspect}' for #{input.inspect}:#{input.class})) # rubocop:disable Layout/LineLength
146
+ raise NoMethodError.new(%(undefined method `#{transformation.inspect}' for #{input.inspect}:#{input.class}))
147
147
  end
148
148
  end
149
149
  end
@@ -151,6 +151,8 @@ module Hanami
151
151
 
152
152
  fn.call(input)
153
153
  end
154
+ # rubocop:enable Metrics/MethodLength
155
+ # rubocop:enable Metrics/AbcSize
154
156
 
155
157
  # Extracted from `transproc` source code
156
158
  #
@@ -163,7 +165,7 @@ module Hanami
163
165
  binding.instance_exec(value, &fun)
164
166
  end
165
167
 
166
- # Returns a titleized version of the string
168
+ # Return a titleized version of the string
167
169
  #
168
170
  # @param input [::String] the input
169
171
  #
@@ -180,7 +182,7 @@ module Hanami
180
182
  underscore(string).split(CLASSIFY_SEPARATOR).map(&:capitalize).join(TITLEIZE_SEPARATOR)
181
183
  end
182
184
 
183
- # Returns a capitalized version of the string
185
+ # Return a capitalized version of the string
184
186
  #
185
187
  # @param input [::String] the input
186
188
  #
@@ -207,7 +209,7 @@ module Hanami
207
209
  tail.unshift(head.capitalize).join(CAPITALIZE_SEPARATOR)
208
210
  end
209
211
 
210
- # Returns a CamelCase version of the string
212
+ # Return a CamelCase version of the string
211
213
  #
212
214
  # @param input [::String] the input
213
215
  #
@@ -231,7 +233,7 @@ module Hanami
231
233
  words.zip(delimiters).join
232
234
  end
233
235
 
234
- # Returns a downcased and underscore separated version of the string
236
+ # Return a downcased and underscore separated version of the string
235
237
  #
236
238
  # Revised version of `ActiveSupport::Inflector.underscore` implementation
237
239
  # @see https://github.com/rails/rails/blob/feaa6e2048fe86bcf07e967d6e47b865e42e055b/activesupport/lib/active_support/inflector/methods.rb#L90
@@ -256,7 +258,7 @@ module Hanami
256
258
  string.downcase
257
259
  end
258
260
 
259
- # Returns a downcased and dash separated version of the string
261
+ # Return a downcased and dash separated version of the string
260
262
  #
261
263
  # @param input [::String] the input
262
264
  #
@@ -277,7 +279,7 @@ module Hanami
277
279
  underscore(string).split(CLASSIFY_SEPARATOR).join(DASHERIZE_SEPARATOR)
278
280
  end
279
281
 
280
- # Returns the string without the Ruby namespace of the class
282
+ # Return the string without the Ruby namespace of the class
281
283
  #
282
284
  # @param input [::String] the input
283
285
  #
@@ -295,7 +297,7 @@ module Hanami
295
297
  ::String.new(input.to_s).split(NAMESPACE_SEPARATOR).last
296
298
  end
297
299
 
298
- # Returns the top level namespace name
300
+ # Return the top level namespace name
299
301
  #
300
302
  # @param input [::String] the input
301
303
  #
@@ -313,47 +315,7 @@ module Hanami
313
315
  ::String.new(input.to_s).split(NAMESPACE_SEPARATOR).first
314
316
  end
315
317
 
316
- # Returns a pluralized version of self.
317
- #
318
- # @param input [::String] the input
319
- #
320
- # @return [::String] the pluralized string.
321
- #
322
- # @since 1.1.0
323
- #
324
- # @see Hanami::Utils::Inflector
325
- # @deprecated
326
- #
327
- # @example
328
- # require 'hanami/utils/string'
329
- #
330
- # Hanami::Utils::String.pluralize('book') # => 'books'
331
- def self.pluralize(input)
332
- string = ::String.new(input.to_s)
333
- Inflector.pluralize(string)
334
- end
335
-
336
- # Returns a singularized version of self.
337
- #
338
- # @param input [::String] the input
339
- #
340
- # @return [::String] the singularized string.
341
- #
342
- # @since 1.1.0
343
- # @deprecated
344
- #
345
- # @see Hanami::Utils::Inflector
346
- #
347
- # @example
348
- # require 'hanami/utils/string'
349
- #
350
- # Hanami::Utils::String.singularize('books') # => 'book'
351
- def self.singularize(input)
352
- string = ::String.new(input.to_s)
353
- Inflector.singularize(string)
354
- end
355
-
356
- # Replaces the rightmost match of `pattern` with `replacement`
318
+ # Replace the rightmost match of `pattern` with `replacement`
357
319
  #
358
320
  # If the pattern cannot be matched, it returns the original string.
359
321
  #
@@ -374,7 +336,7 @@ module Hanami
374
336
  # # => 'authors/books#index'
375
337
  def self.rsub(input, pattern, replacement)
376
338
  string = ::String.new(input.to_s)
377
- if i = string.rindex(pattern)
339
+ if i = string.rindex(pattern) # rubocop:disable Lint/AssignmentInCondition
378
340
  s = string.dup
379
341
  s[i] = replacement
380
342
  s
@@ -395,7 +357,7 @@ module Hanami
395
357
  @string = string.to_s
396
358
  end
397
359
 
398
- # Returns a titleized version of the string
360
+ # Return a titleized version of the string
399
361
  #
400
362
  # @return [Hanami::Utils::String] the transformed string
401
363
  #
@@ -411,7 +373,7 @@ module Hanami
411
373
  self.class.new underscore.split(CLASSIFY_SEPARATOR).map(&:capitalize).join(TITLEIZE_SEPARATOR)
412
374
  end
413
375
 
414
- # Returns a capitalized version of the string
376
+ # Return a capitalized version of the string
415
377
  #
416
378
  # @return [Hanami::Utils::String] the transformed string
417
379
  #
@@ -443,7 +405,7 @@ module Hanami
443
405
  )
444
406
  end
445
407
 
446
- # Returns a CamelCase version of the string
408
+ # Return a CamelCase version of the string
447
409
  #
448
410
  # @return [Hanami::Utils::String] the transformed string
449
411
  #
@@ -466,7 +428,7 @@ module Hanami
466
428
  self.class.new words.zip(delimiters).join
467
429
  end
468
430
 
469
- # Returns a downcased and underscore separated version of the string
431
+ # Return a downcased and underscore separated version of the string
470
432
  #
471
433
  # Revised version of `ActiveSupport::Inflector.underscore` implementation
472
434
  # @see https://github.com/rails/rails/blob/feaa6e2048fe86bcf07e967d6e47b865e42e055b/activesupport/lib/active_support/inflector/methods.rb#L90
@@ -490,7 +452,7 @@ module Hanami
490
452
  self.class.new new_string
491
453
  end
492
454
 
493
- # Returns a downcased and dash separated version of the string
455
+ # Return a downcased and dash separated version of the string
494
456
  #
495
457
  # @return [Hanami::Utils::String] the transformed string
496
458
  #
@@ -512,7 +474,7 @@ module Hanami
512
474
  self.class.new underscore.split(CLASSIFY_SEPARATOR).join(DASHERIZE_SEPARATOR)
513
475
  end
514
476
 
515
- # Returns the string without the Ruby namespace of the class
477
+ # Return the string without the Ruby namespace of the class
516
478
  #
517
479
  # @return [Hanami::Utils::String] the transformed string
518
480
  #
@@ -531,7 +493,7 @@ module Hanami
531
493
  self.class.new split(NAMESPACE_SEPARATOR).last
532
494
  end
533
495
 
534
- # Returns the top level namespace name
496
+ # Return the top level namespace name
535
497
  #
536
498
  # @return [Hanami::Utils::String] the transformed string
537
499
  #
@@ -572,8 +534,9 @@ module Hanami
572
534
  # 'Hanami::Utils'
573
535
  # 'Hanami::App'
574
536
  #
537
+ # rubocop:disable Metrics/MethodLength
575
538
  def tokenize
576
- if match = TOKENIZE_REGEXP.match(@string)
539
+ if match = TOKENIZE_REGEXP.match(@string) # rubocop:disable Lint/AssignmentInCondition
577
540
  pre = match.pre_match
578
541
  post = match.post_match
579
542
  tokens = match[1].split(TOKENIZE_SEPARATOR)
@@ -586,32 +549,7 @@ module Hanami
586
549
 
587
550
  nil
588
551
  end
589
-
590
- # Returns a pluralized version of self.
591
- #
592
- # @return [Hanami::Utils::String] the pluralized string.
593
- #
594
- # @api private
595
- # @since 0.4.1
596
- # @deprecated
597
- #
598
- # @see Hanami::Utils::Inflector
599
- def pluralize
600
- self.class.new Inflector.pluralize(self)
601
- end
602
-
603
- # Returns a singularized version of self.
604
- #
605
- # @return [Hanami::Utils::String] the singularized string.
606
- #
607
- # @api private
608
- # @since 0.4.1
609
- # @deprecated
610
- #
611
- # @see Hanami::Utils::Inflector
612
- def singularize
613
- self.class.new Inflector.singularize(self)
614
- end
552
+ # rubocop:enable Metrics/MethodLength
615
553
 
616
554
  # Returns the hash of the internal string
617
555
  #
@@ -633,7 +571,7 @@ module Hanami
633
571
  @string
634
572
  end
635
573
 
636
- alias_method :to_str, :to_s
574
+ alias to_str to_s
637
575
 
638
576
  # Equality
639
577
  #
@@ -645,9 +583,9 @@ module Hanami
645
583
  to_s == other
646
584
  end
647
585
 
648
- alias_method :eql?, :==
586
+ alias eql? ==
649
587
 
650
- # Splits the string with the given pattern
588
+ # Split the string with the given pattern
651
589
  #
652
590
  # @return [Array<::String>]
653
591
  #
@@ -659,7 +597,7 @@ module Hanami
659
597
  @string.split(pattern, limit)
660
598
  end
661
599
 
662
- # Replaces the given pattern with the given replacement
600
+ # Replace the given pattern with the given replacement
663
601
  #
664
602
  # @return [::String]
665
603
  #
@@ -675,7 +613,7 @@ module Hanami
675
613
  end
676
614
  end
677
615
 
678
- # Iterates through the string, matching the pattern.
616
+ # Iterate through the string, matching the pattern.
679
617
  # Either return all those patterns, or pass them to the block.
680
618
  #
681
619
  # @return [Array<::String>]
@@ -688,7 +626,7 @@ module Hanami
688
626
  @string.scan(pattern, &blk)
689
627
  end
690
628
 
691
- # Replaces the rightmost match of `pattern` with `replacement`
629
+ # Replace the rightmost match of `pattern` with `replacement`
692
630
  #
693
631
  # If the pattern cannot be matched, it returns the original string.
694
632
  #
@@ -714,7 +652,7 @@ module Hanami
714
652
  # puts result
715
653
  # # => #<Hanami::Utils::String:0x007fdb41232ed0 @string="authors/books#index">
716
654
  def rsub(pattern, replacement)
717
- if i = rindex(pattern)
655
+ if i = rindex(pattern) # rubocop:disable Lint/AssignmentInCondition
718
656
  s = @string.dup
719
657
  s[i] = replacement
720
658
  self.class.new s
@@ -723,23 +661,21 @@ module Hanami
723
661
  end
724
662
  end
725
663
 
726
- # Overrides Ruby's method_missing in order to provide ::String interface
664
+ # Override Ruby's method_missing in order to provide ::String interface
727
665
  #
728
666
  # @api private
729
667
  # @since 0.3.0
730
668
  #
731
669
  # @raise [NoMethodError] If doesn't respond to the given method
732
670
  def method_missing(method_name, *args, &blk)
733
- unless respond_to?(method_name)
734
- raise NoMethodError.new(%(undefined method `#{method_name}' for "#{@string}":#{self.class}))
735
- end
671
+ raise NoMethodError.new(%(undefined method `#{method_name}' for "#{@string}":#{self.class})) unless respond_to?(method_name)
736
672
 
737
673
  s = @string.__send__(method_name, *args, &blk)
738
674
  s = self.class.new(s) if s.is_a?(::String)
739
675
  s
740
676
  end
741
677
 
742
- # Overrides Ruby's respond_to_missing? in order to support ::String interface
678
+ # Override Ruby's respond_to_missing? in order to support ::String interface
743
679
  #
744
680
  # @api private
745
681
  # @since 0.3.0
@@ -5,6 +5,6 @@ module Hanami
5
5
  # Defines the version
6
6
  #
7
7
  # @since 0.1.0
8
- VERSION = "1.3.7"
8
+ VERSION = "2.0.0.alpha1"
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.7
4
+ version: 2.0.0.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-04 00:00:00.000000000 Z
11
+ date: 2019-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: transproc
@@ -64,42 +64,28 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '13'
67
+ version: '12'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '13'
74
+ version: '12'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rspec
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '3.9'
81
+ version: '3.7'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '3.9'
89
- - !ruby/object:Gem::Dependency
90
- name: rubocop
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - '='
94
- - !ruby/object:Gem::Version
95
- version: '0.81'
96
- type: :development
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - '='
101
- - !ruby/object:Gem::Version
102
- version: '0.81'
88
+ version: '3.7'
103
89
  description: Hanami utilities
104
90
  email:
105
91
  - me@lucaguidi.com
@@ -117,19 +103,19 @@ files:
117
103
  - lib/hanami/logger/colorizer.rb
118
104
  - lib/hanami/logger/filter.rb
119
105
  - lib/hanami/logger/formatter.rb
106
+ - lib/hanami/middleware.rb
120
107
  - lib/hanami/utils.rb
121
108
  - lib/hanami/utils/basic_object.rb
122
109
  - lib/hanami/utils/blank.rb
123
110
  - lib/hanami/utils/callbacks.rb
124
111
  - lib/hanami/utils/class.rb
125
112
  - lib/hanami/utils/class_attribute.rb
113
+ - lib/hanami/utils/class_attribute/attributes.rb
126
114
  - lib/hanami/utils/deprecation.rb
127
- - lib/hanami/utils/duplicable.rb
128
115
  - lib/hanami/utils/escape.rb
129
116
  - lib/hanami/utils/file_list.rb
130
117
  - lib/hanami/utils/files.rb
131
118
  - lib/hanami/utils/hash.rb
132
- - lib/hanami/utils/inflector.rb
133
119
  - lib/hanami/utils/io.rb
134
120
  - lib/hanami/utils/json.rb
135
121
  - lib/hanami/utils/kernel.rb
@@ -143,7 +129,7 @@ homepage: http://hanamirb.org
143
129
  licenses:
144
130
  - MIT
145
131
  metadata: {}
146
- post_install_message:
132
+ post_install_message:
147
133
  rdoc_options: []
148
134
  require_paths:
149
135
  - lib
@@ -151,15 +137,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
137
  requirements:
152
138
  - - ">="
153
139
  - !ruby/object:Gem::Version
154
- version: 2.3.0
140
+ version: 2.5.0
155
141
  required_rubygems_version: !ruby/object:Gem::Requirement
156
142
  requirements:
157
- - - ">="
143
+ - - ">"
158
144
  - !ruby/object:Gem::Version
159
- version: '0'
145
+ version: 1.3.1
160
146
  requirements: []
161
- rubygems_version: 3.2.4
162
- signing_key:
147
+ rubygems_version: 3.0.2
148
+ signing_key:
163
149
  specification_version: 4
164
150
  summary: Ruby core extentions and Hanami utilities
165
151
  test_files: []