hanami-utils 1.3.6 → 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
@@ -1,10 +1,12 @@
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
12
  # Defines top level constant Boolean, so it can be easily used by other libraries
@@ -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"
@@ -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
@@ -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
  #
@@ -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
@@ -23,14 +23,14 @@ module Hanami
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
36
  # Colorizes output
@@ -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,43 +38,43 @@ 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
 
@@ -81,7 +83,8 @@ module Hanami
81
83
 
82
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
  #
@@ -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
@@ -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,7 +586,6 @@ module Hanami
588
586
 
589
587
  nil
590
588
  end
591
- # rubocop:enable Metrics/MethodLength
592
589
 
593
590
  # Returns a pluralized version of self.
594
591
  #
@@ -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,7 +645,7 @@ module Hanami
648
645
  to_s == other
649
646
  end
650
647
 
651
- alias eql? ==
648
+ alias_method :eql?, :==
652
649
 
653
650
  # Splits the string with the given pattern
654
651
  #
@@ -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
@@ -733,7 +730,9 @@ module Hanami
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)
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hanami
2
4
  module Utils
3
5
  # Defines the version
4
6
  #
5
7
  # @since 0.1.0
6
- VERSION = '1.3.6'.freeze
8
+ VERSION = "1.3.7"
7
9
  end
8
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.6
4
+ version: 1.3.7
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: 2020-01-07 00:00:00.000000000 Z
11
+ date: 2021-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: transproc
@@ -78,14 +78,28 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '3.7'
81
+ version: '3.9'
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.7'
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'
89
103
  description: Hanami utilities
90
104
  email:
91
105
  - me@lucaguidi.com
@@ -129,7 +143,7 @@ homepage: http://hanamirb.org
129
143
  licenses:
130
144
  - MIT
131
145
  metadata: {}
132
- post_install_message:
146
+ post_install_message:
133
147
  rdoc_options: []
134
148
  require_paths:
135
149
  - lib
@@ -144,8 +158,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
158
  - !ruby/object:Gem::Version
145
159
  version: '0'
146
160
  requirements: []
147
- rubygems_version: 3.1.2
148
- signing_key:
161
+ rubygems_version: 3.2.4
162
+ signing_key:
149
163
  specification_version: 4
150
164
  summary: Ruby core extentions and Hanami utilities
151
165
  test_files: []