hanami-utils 1.3.7 → 2.0.0.alpha3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '02818d90409ea03d89ca587c97fe418bbf17a8694662a2313609c0710466b0f9'
4
- data.tar.gz: 973ef420992dd9ea30ab880d43e8cc70eee59cae6fb7b1ba17038c5ce8d536a4
3
+ metadata.gz: a34d2521940dfea9fb6d12a6cf65022aa340567e741801e3740d06e0e620d1f3
4
+ data.tar.gz: d7396f0786283c15a398e41a1c3b62659be3d786b2df295733bca55253cb7def
5
5
  SHA512:
6
- metadata.gz: d49d6ad21aa25f285c9165c4619d6b2d7fe348513481bf30b8f231211d4e270f7502e2e3594f082789fdf32e9170a33e038329394ae5f43170ab778ebe01892f
7
- data.tar.gz: 8b8832a39855525d6818de385212fb1c9d7c5c0f79874f60ead95ee1c592377f6bfec0ade5701a4340b87fe920c495889a9586d81fe2091d8691b52b14f297fa
6
+ metadata.gz: 15f71cb5b8f88f6bb0ac02dce471120115923d8dff3676a5ed12860bc743d7d20ce9e6ad8ef5a29e233f63dbe5299510757c0f25b25d75c6818e8e72d9f7407c
7
+ data.tar.gz: 85d58a5238393e7647a3b5dac295182619ae7f583c96d53c2928a8f79d3cee8cb0a5a7e306fc7e8705b884b76cb305e37e55afa3a9b9bb1122b049fb6776400a
data/CHANGELOG.md CHANGED
@@ -1,6 +1,35 @@
1
1
  # Hanami::Utils
2
2
  Ruby core extentions and class utilities for Hanami
3
3
 
4
+ ## v2.0.0.alpha3 - 2021-11-09
5
+ No changes.
6
+
7
+ ## v2.0.0.alpha2 - 2021-05-04
8
+ ### Changed
9
+ - [Luca Guidi] Drop support for Ruby: MRI 2.5.
10
+ - [Luca Guidi] Transform `Utils::String` from class to module
11
+
12
+ ## v2.0.0.alpha1 - 2019-01-30
13
+ ### Added
14
+ - [Gustavo Caso] Introduce `Hanami::Middleware` namespace
15
+ - [Luca Guidi] Introduce `Callbacks::Chain#dup`
16
+
17
+ ### Changed
18
+ - [Luca Guidi] Drop support for Ruby: MRI 2.3, and 2.4.
19
+ - [Luca Guidi] Remove `Utils::Duplicable`
20
+ - [Luca Guidi] Remove `Utils::Inflector`
21
+ - [Luca Guidi] Remove `Utils::String.singularize`, and `.pluralize`
22
+ - [Luca Guidi] Remove `Utils::String#singularize`, and `#pluralize`
23
+ - [Luca Guidi] Remove instance level interface for `Utils::Hash`
24
+ - [Luca Guidi] Transform `Utils::Hash` from class to module
25
+ - [Luca Guidi] Remove `Utils.reload!`
26
+ - [Gustavo Caso] Remove `Utils::File.rewrite`
27
+ - [Vladimir Suvorov] Remove `Utils::Class.load_from_pattern!`
28
+
29
+ ## v1.3.8 - 2021-05-03
30
+ ### Fixed
31
+ - [Hiếu Nguyễn] Ensure `Hanami::Interactor#initialize` to accept keyword arguments while working with Ruby 3
32
+
4
33
  ## v1.3.7 - 2021-01-04
5
34
  ### Added
6
35
  - [Luca Guidi] Official support for Ruby: MRI 3.0
@@ -179,7 +208,7 @@ Ruby core extentions and class utilities for Hanami
179
208
  - [Grachev Mikhail] Introduced `Hanami::Interactor::Result#failure?`
180
209
 
181
210
  ### Fixed
182
- - [Paweł Świątkowski] `Utils::Inflector.pluralize` Pluralize -en to -ens instead of -ina
211
+ - [Paweł Świątkowski] `Utils::Inflector.pluralize` Pluralize -en to -ens instead of -ina
183
212
 
184
213
  ### Changed
185
214
  - [Grachev Mikhail] Deprecate `Hanami::Interactor::Result#failing?` in favor of `#failure?`
@@ -199,7 +228,7 @@ Ruby core extentions and class utilities for Hanami
199
228
  ### Added
200
229
  – [Luca Guidi] Introduced `Utils.require!` to recursively require Ruby files with an order that is consistent across platforms
201
230
  – [Luca Guidi] Introduced `Utils::FileList` as cross-platform ordered list of files, alternative to `Dir.glob`
202
- - [Luca Guidi] Make `Utils::BasicObject` pretty printable
231
+ - [Luca Guidi] Make `Utils::BasicObject` pretty printable
203
232
  - [Grachev Mikhail] Added `Interactor::Result#successful?` and `#failing?`
204
233
 
205
234
  ### Fixed
@@ -403,7 +432,7 @@ Ruby core extentions and class utilities for Hanami
403
432
  ## v0.1.0 - 2014-01-23
404
433
  ### Added
405
434
  - [Luca Guidi] Introduced `Lotus::Utils::String#demodulize`
406
- - [Luca Guidi] Introduced `Lotus::Utils::IO.silence_warnings`
435
+ - [Luca Guidi] Introduced `Lotus::Utils::IO.silence_warnings`
407
436
  - [Luca Guidi] Introduced class loading mechanism from a string: `Utils::Class.load!`
408
437
  - [Luca Guidi] Introduced callbacks support for classes
409
438
  - [Luca Guidi] Introduced inheritable class level attributes
data/README.md CHANGED
@@ -5,11 +5,16 @@ Ruby core extensions and class utilities for [Hanami](http://hanamirb.org)
5
5
  ## Status
6
6
 
7
7
  [![Gem Version](https://badge.fury.io/rb/hanami-utils.svg)](https://badge.fury.io/rb/hanami-utils)
8
- [![CI](https://github.com/hanami/utils/workflows/ci/badge.svg?branch=master)](https://github.com/hanami/utils/actions?query=workflow%3Aci+branch%3Amaster)
9
- [![Test Coverage](https://codecov.io/gh/hanami/utils/branch/master/graph/badge.svg)](https://codecov.io/gh/hanami/utils)
8
+ [![CI](https://github.com/hanami/utils/workflows/ci/badge.svg?branch=main)](https://github.com/hanami/utils/actions?query=workflow%3Aci+branch%3Amain)
9
+ [![Test Coverage](https://codecov.io/gh/hanami/utils/branch/main/graph/badge.svg)](https://codecov.io/gh/hanami/utils)
10
10
  [![Depfu](https://badges.depfu.com/badges/a8545fb67cf32a2c75b6227bc0821027/overview.svg)](https://depfu.com/github/hanami/utils?project=Bundler)
11
11
  [![Inline Docs](http://inch-ci.org/github/hanami/utils.svg)](http://inch-ci.org/github/hanami/utils)
12
12
 
13
+
14
+ ## Version
15
+
16
+ **This branch contains the code for `hanami-utils` 2.x.**
17
+
13
18
  ## Contact
14
19
 
15
20
  * Home page: http://hanamirb.org
@@ -21,7 +26,7 @@ Ruby core extensions and class utilities for [Hanami](http://hanamirb.org)
21
26
 
22
27
  ## Rubies
23
28
 
24
- __Hanami::Utils__ supports Ruby (MRI) 2.3+, JRuby 9.1.5.0+
29
+ __Hanami::Utils__ supports Ruby (MRI) 2.6+
25
30
 
26
31
  ## Installation
27
32
 
@@ -78,11 +83,6 @@ Inheritable class attributes. [[API doc](http://www.rubydoc.info/gems/hanami-uti
78
83
 
79
84
  Deprecate Hanami features. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Deprecation)]
80
85
 
81
- ### Hanami::Utils::Duplicable
82
-
83
- Safe `#dup` logic for Ruby objects. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Duplicable)]
84
-
85
-
86
86
  ### Hanami::Utils::Escape
87
87
 
88
88
  Safe and fast escape for URLs, HTML content and attributes. Based on OWASP/ESAPI code. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Escape)]
@@ -97,16 +97,12 @@ File utilities to manipulate files and directories. [[API doc](http://www.rubydo
97
97
 
98
98
  ### Hanami::Utils::Hash
99
99
 
100
- Enhanced version of Ruby's `Hash`. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Hash)]
100
+ `Hash` transformations. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Hash)]
101
101
 
102
102
  ### Hanami::Utils::IO
103
103
 
104
104
  Silence Ruby warnings. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/IO)]
105
105
 
106
- ### Hanami::Utils::Inflector
107
-
108
- Complete and customizable english inflections (pluralization and singularization). [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Inflector)]
109
-
110
106
  ### Hanami::Utils::Json
111
107
 
112
108
  JSON engine with swappable backends (via optional `multi_json` gem) or powered by Ruby's `json` (default). [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Json)]
data/hanami-utils.gemspec CHANGED
@@ -18,13 +18,13 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
- spec.required_ruby_version = ">= 2.3.0"
21
+ spec.required_ruby_version = ">= 2.6.0"
22
22
 
23
- spec.add_dependency "transproc", "~> 1.0"
23
+ spec.add_dependency "dry-transformer", "~> 0.1"
24
24
  spec.add_dependency "concurrent-ruby", "~> 1.0"
25
25
 
26
26
  spec.add_development_dependency "bundler", ">= 1.6", "< 3"
27
27
  spec.add_development_dependency "rake", "~> 13"
28
28
  spec.add_development_dependency "rspec", "~> 3.9"
29
- spec.add_development_dependency "rubocop", "0.81" # rubocop 0.81+ removed support for Ruby 2.3
29
+ spec.add_development_dependency "rubocop", "0.91"
30
30
  end
@@ -181,10 +181,18 @@ module Hanami
181
181
  # # ...
182
182
  # end
183
183
  # end
184
- def initialize(*args)
185
- super
186
- ensure
187
- @__result = ::Hanami::Interactor::Result.new
184
+ if RUBY_VERSION >= "3.0"
185
+ def initialize(*args, **kwargs)
186
+ super
187
+ ensure
188
+ @__result = ::Hanami::Interactor::Result.new
189
+ end
190
+ else
191
+ def initialize(*args)
192
+ super
193
+ ensure
194
+ @__result = ::Hanami::Interactor::Result.new
195
+ end
188
196
  end
189
197
 
190
198
  # Triggers the operation and return a result.
@@ -572,7 +580,7 @@ module Hanami
572
580
  # @since 0.5.0
573
581
  # @api private
574
582
  def _exposures
575
- Hash[].tap do |result|
583
+ ::Hash[].tap do |result|
576
584
  self.class.exposures.each do |name, ivar|
577
585
  result[name] = instance_variable_defined?(ivar) ? instance_variable_get(ivar) : nil
578
586
  end
@@ -99,16 +99,13 @@ module Hanami
99
99
  # @since 1.3.7
100
100
  # @api private
101
101
  def _deep_dup(hash)
102
- hash.map do |key, value|
103
- [
104
- key,
105
- if value.is_a?(Hash)
106
- _deep_dup(value)
107
- else
108
- _key_paths?(value) ? value.dup : value
109
- end
110
- ]
111
- end.to_h
102
+ hash.transform_values do |value|
103
+ if value.is_a?(Hash)
104
+ _deep_dup(value)
105
+ else
106
+ _key_paths?(value) ? value.dup : value
107
+ end
108
+ end
112
109
  end
113
110
 
114
111
  # @since 1.3.7
@@ -105,16 +105,16 @@ module Hanami
105
105
  # @api private
106
106
  def _message_hash(message)
107
107
  case message
108
- when Hash
108
+ when ::Hash
109
109
  @filter.call(message)
110
110
  when Exception
111
- Hash[
111
+ ::Hash[
112
112
  message: message.message,
113
113
  backtrace: message.backtrace || [],
114
114
  error: message.class
115
115
  ]
116
116
  else
117
- Hash[message: message]
117
+ ::Hash[message: message]
118
118
  end
119
119
  end
120
120
 
data/lib/hanami/logger.rb CHANGED
@@ -317,7 +317,7 @@ module Hanami
317
317
  #
318
318
  # @since 0.8.0
319
319
  def close
320
- super unless [STDOUT, $stdout].include?(@stream)
320
+ super unless [STDOUT, $stdout].include?(@stream) # rubocop:disable Style/GlobalStdStream
321
321
  end
322
322
 
323
323
  private
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hanami
4
+ module Middleware
5
+ # Hanami middleware utils
6
+
7
+ # @since 2.0.0
8
+ class Error < ::StandardError
9
+ end
10
+ end
11
+ end
@@ -21,7 +21,6 @@ module Hanami
21
21
  # Hanami::Utils::Blank.blank?(Hanami::Utils::String.new('')) # => true
22
22
  # Hanami::Utils::Blank.blank?(' ') # => true
23
23
  # Hanami::Utils::Blank.blank?(nil) # => true
24
- # Hanami::Utils::Blank.blank?(Hanami::Utils::Hash.new({})) # => true
25
24
  # Hanami::Utils::Blank.blank?(true) # => false
26
25
  # Hanami::Utils::Blank.blank?(1) # => false
27
26
  #
@@ -34,8 +33,8 @@ module Hanami
34
33
  def self.blank?(object)
35
34
  case object
36
35
  when String, ::String
37
- STRING_MATCHER === object # rubocop:disable Style/CaseEquality
38
- when Hash, ::Hash, ::Array
36
+ STRING_MATCHER === object
37
+ when ::Hash, ::Array
39
38
  object.empty?
40
39
  when TrueClass, Numeric
41
40
  false
@@ -56,7 +55,6 @@ module Hanami
56
55
  # Hanami::Utils::Blank.filled?(Hanami::Utils::String.new('')) # => false
57
56
  # Hanami::Utils::Blank.filled?(' ') # => false
58
57
  # Hanami::Utils::Blank.filled?(nil) # => false
59
- # Hanami::Utils::Blank.filled?(Hanami::Utils::Hash.new({})) # => false
60
58
  #
61
59
  # @param object the argument
62
60
  #
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "concurrent/array"
4
+
3
5
  module Hanami
4
6
  module Utils
5
7
  # Before and After callbacks
@@ -18,7 +20,7 @@ module Hanami
18
20
  #
19
21
  # @since 0.2.0
20
22
  def initialize
21
- @chain = []
23
+ @chain = Concurrent::Array.new
22
24
  end
23
25
 
24
26
  # Appends the given callbacks to the end of the chain.
@@ -150,6 +152,17 @@ module Hanami
150
152
  end
151
153
  end
152
154
 
155
+ # Return a duplicate callbacks chain
156
+ #
157
+ # @return [Hanami::Utils::Callbacks] the duplicated chain
158
+ #
159
+ # @since 2.0.0
160
+ def dup
161
+ super.tap do |instance|
162
+ instance.instance_variable_set(:@chain, instance.chain.dup)
163
+ end
164
+ end
165
+
153
166
  # It freezes the object by preventing further modifications.
154
167
  #
155
168
  # @since 0.2.0
@@ -170,6 +183,10 @@ module Hanami
170
183
  @chain.freeze
171
184
  end
172
185
 
186
+ protected
187
+
188
+ attr_reader :chain
189
+
173
190
  private
174
191
 
175
192
  # @api private
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "hanami/utils/deprecation"
4
-
5
3
  module Hanami
6
4
  module Utils
7
5
  # Class utilities
@@ -74,57 +72,6 @@ module Hanami
74
72
  load!(name, namespace) if namespace.const_defined?(name.to_s, false)
75
73
  end
76
74
 
77
- # Loads a class from the given pattern name and namespace
78
- #
79
- # @param pattern [String] the class name pattern
80
- # @param namespace [Class, Module] the Ruby namespace where we want to perform the lookup.
81
- # @return [Class, Module] the found Ruby constant.
82
- #
83
- # @raise [NameError] if no constant can be found.
84
- #
85
- # @since 0.3.1
86
- #
87
- # @see Hanami::Utils::String#tokenize
88
- #
89
- # @example
90
- # require 'hanami/utils/class'
91
- #
92
- # module App
93
- # module Service
94
- # class Endpoint
95
- # end
96
- # end
97
- #
98
- # class ServiceEndpoint
99
- # end
100
- # end
101
- #
102
- # # basic usage
103
- # Hanami::Utils::Class.load_from_pattern!('App::Service') # => App::Service
104
- #
105
- # # with explicit namespace
106
- # Hanami::Utils::Class.load_from_pattern!('Service', App) # => App::Service
107
- #
108
- # # with pattern
109
- # Hanami::Utils::Class.load_from_pattern!('App::Service(::Endpoint|Endpoint)') # => App::Service::Endpoint
110
- # Hanami::Utils::Class.load_from_pattern!('App::Service(Endpoint|::Endpoint)') # => App::ServiceEndpoint
111
- #
112
- # # with missing constant
113
- # Hanami::Utils::Class.load_from_pattern!('Unknown') # => raises NameError
114
- def self.load_from_pattern!(pattern, namespace = Object)
115
- Deprecation.new("Hanami::Utils::Class.load_from_pattern! is deprecated, please use Hanami::Utils::Class.load! instead") # rubocop:disable Layout/LineLength
116
-
117
- tokenize(pattern) do |token|
118
- begin
119
- return namespace.const_get(token, false)
120
- rescue NameError # rubocop:disable Lint/SuppressedException
121
- end
122
- end
123
-
124
- full_name = [(namespace == Object ? nil : namespace), pattern].compact.join("::")
125
- raise NameError.new("uninitialized constant #{full_name}")
126
- end
127
-
128
75
  def self.tokenize(pattern)
129
76
  if match = TOKENIZE_REGEXP.match(pattern)
130
77
  pre = match.pre_match
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "concurrent/map"
4
+
5
+ module Hanami
6
+ module Utils
7
+ module ClassAttribute
8
+ # Class attributes set
9
+ #
10
+ # @since 2.0.0
11
+ # @api private
12
+ class Attributes
13
+ # @since 2.0.0
14
+ # @api private
15
+ def initialize(attributes: Concurrent::Map.new)
16
+ @attributes = attributes
17
+ end
18
+
19
+ # @since 2.0.0
20
+ # @api private
21
+ def []=(key, value)
22
+ @attributes[key.to_sym] = value
23
+ end
24
+
25
+ # @since 2.0.0
26
+ # @api private
27
+ def [](key)
28
+ @attributes.fetch(key, nil)
29
+ end
30
+
31
+ # @since 2.0.0
32
+ # @api private
33
+ def dup
34
+ attributes = Concurrent::Map.new.tap do |attrs|
35
+ @attributes.each do |key, value|
36
+ attrs[key.to_sym] = value.dup
37
+ end
38
+ end
39
+
40
+ self.class.new(attributes: attributes)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "set"
4
- require "hanami/utils/duplicable"
5
-
6
3
  module Hanami
7
4
  module Utils
8
5
  # Inheritable class level variable accessors.
@@ -10,6 +7,8 @@ module Hanami
10
7
  #
11
8
  # @see Hanami::Utils::ClassAttribute::ClassMethods
12
9
  module ClassAttribute
10
+ require "hanami/utils/class_attribute/attributes"
11
+
13
12
  # @api private
14
13
  def self.included(base)
15
14
  base.extend ClassMethods
@@ -18,6 +17,12 @@ module Hanami
18
17
  # @since 0.1.0
19
18
  # @api private
20
19
  module ClassMethods
20
+ def self.extended(base)
21
+ base.class_eval do
22
+ @__class_attributes = Attributes.new unless defined?(@__class_attributes)
23
+ end
24
+ end
25
+
21
26
  # Defines a class level accessor for the given attribute(s).
22
27
  #
23
28
  # A value set for a superclass is automatically available by their
@@ -68,11 +73,17 @@ module Hanami
68
73
  # SmallAirplane.engines # => 2
69
74
  # SmallAirplane.wheels # => 8
70
75
  def class_attribute(*attributes)
71
- singleton_class.class_eval do
72
- attr_accessor(*attributes)
73
- end
76
+ attributes.each do |attr|
77
+ singleton_class.class_eval %(
78
+ def #{attr}
79
+ class_attributes[:#{attr}]
80
+ end
74
81
 
75
- class_attributes.merge(attributes)
82
+ def #{attr}=(value)
83
+ class_attributes[:#{attr}] = value
84
+ end
85
+ ), __FILE__, __LINE__ - 8
86
+ end
76
87
  end
77
88
 
78
89
  protected
@@ -80,11 +91,9 @@ module Hanami
80
91
  # @see Class#inherited
81
92
  # @api private
82
93
  def inherited(subclass)
83
- class_attributes.each do |attr|
84
- value = send(attr)
85
- value = Duplicable.dup(value)
86
- subclass.class_attribute attr
87
- subclass.send("#{attr}=", value)
94
+ ca = class_attributes.dup
95
+ subclass.class_eval do
96
+ @__class_attributes = ca
88
97
  end
89
98
 
90
99
  super
@@ -95,7 +104,7 @@ module Hanami
95
104
  # Class accessor for class attributes.
96
105
  # @api private
97
106
  def class_attributes
98
- @class_attributes ||= Set.new
107
+ @__class_attributes
99
108
  end
100
109
  end
101
110
  end
@@ -14,8 +14,28 @@ module Hanami
14
14
  # @since 0.9.0
15
15
  #
16
16
  # @see https://ruby-doc.org/core/Dir.html#method-c-glob
17
+ #
18
+ # @example simple usage
19
+ # require "hanami/utils/file_list"
20
+ #
21
+ # Hanami::Utils::FileList["spec/support/fixtures/file_list/*.rb"]
22
+ # # => [
23
+ # "spec/support/fixtures/file_list/a.rb",
24
+ # "spec/support/fixtures/file_list/aa.rb",
25
+ # "spec/support/fixtures/file_list/ab.rb"
26
+ # ]
27
+ #
28
+ # @example token usage
29
+ # require "hanami/utils/file_list"
30
+ #
31
+ # Hanami::Utils::FileList["spec", "support", "fixtures", "file_list", "*.rb"]
32
+ # # => [
33
+ # "spec/support/fixtures/file_list/a.rb",
34
+ # "spec/support/fixtures/file_list/aa.rb",
35
+ # "spec/support/fixtures/file_list/ab.rb"
36
+ # ]
17
37
  def self.[](*args)
18
- Dir.glob(*args).sort!
38
+ Dir.glob(::File.join(*args)).sort!
19
39
  end
20
40
  end
21
41
  end
@@ -34,24 +34,6 @@ module Hanami
34
34
  open(path, ::File::CREAT | ::File::WRONLY | ::File::TRUNC, *content) # rubocop:disable Security/Open - this isn't a call to `::Kernel.open`, but to `self.open`
35
35
  end
36
36
 
37
- # Rewrites the contents of an existing file.
38
- # If the path already exists, it replaces the contents.
39
- #
40
- # @param path [String,Pathname] the path to file
41
- # @param content [String, Array<String>] the content to write
42
- #
43
- # @raise [Errno::ENOENT] if the path doesn't exist
44
- #
45
- # @since 1.1.0
46
- def self.rewrite(path, *content)
47
- Hanami::Utils::Deprecation.new(
48
- "`.rewrite' is deprecated, please use `.write'"
49
- )
50
- raise Errno::ENOENT unless File.exist?(path)
51
-
52
- write(path, *content)
53
- end
54
-
55
37
  # Copies source into destination.
56
38
  # All the intermediate directories are created.
57
39
  # If the destination already exists, it overrides the contents.
@@ -331,8 +313,8 @@ module Hanami
331
313
  starting = index(content, path, target)
332
314
  line = content[starting]
333
315
  size = line[/\A[[:space:]]*/].bytesize
334
- closing = (" " * size) + (target =~ /{/ ? "}" : "end")
335
- ending = starting + index(content[starting..-1], path, closing)
316
+ closing = (" " * size) + (/{/.match?(target) ? "}" : "end")
317
+ ending = starting + index(content[starting..], path, closing)
336
318
 
337
319
  content.slice!(starting..ending)
338
320
  write(path, content)