dry-files 1.1.0 → 1.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73391c6f7e4e115941911686c45307707e68fa4ba0f4be5a7cebba14d7eeb042
4
- data.tar.gz: dcd71ad5b06891df556f0146f2520e4b981024afa06291016e56b194a4f1fb2e
3
+ metadata.gz: 05354c104f2aa90d07d74b8059a31ebd655238e07cf940ac367a067a7dab541f
4
+ data.tar.gz: 0dc658366d6dd0f3ffb208145fc440115a790a4e5373dcdfb975aa29130c0fda
5
5
  SHA512:
6
- metadata.gz: 392bfc69636d993cd92e8462079079ad000ef6ebe60467eee72d30f9e2726fc04705f05ada482cfe0147320abab56afd91b6b782b25e9f3a042c563590d589fd
7
- data.tar.gz: 7c3a4723b89339db36f532f7579f6574c593864e6a79cecfc5cc382280d421338fdd2700c1edffb6fb83b5d917102a2c5be63306f2833c555d5250f0a8d9c1da
6
+ metadata.gz: b5983db3e5c15966b053194679dce7c694f79979ac7d4d4f78c0cc4ed86bcaf5916e2096d01fdfe3d5f6bbf7e12d558bd4dd8b4cf7c329b6bc65d5f856570761
7
+ data.tar.gz: ea880d184e8f862b878c8ee0c70da149a33d692eecc8906b4ccd878240f0a0735e3c34a81b5c63be7cd1bebe37dab8e0969a5cc8493d6a3a3291f373ca8f00ef
data/CHANGELOG.md CHANGED
@@ -1,66 +1,88 @@
1
- <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
1
+ # Changelog
2
2
 
3
- ## 1.1.0 2023-10-18
3
+ All notable changes to this project will be documented in this file.
4
4
 
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Break Versioning](https://www.taoensso.com/break-versioning).
6
+
7
+ ## [Unreleased]
5
8
 
6
9
  ### Added
7
10
 
8
- - Add `Dry::Files#chmod(path, mode)` to modify file permissions. Provide the mode as an integer
9
- to match UNIX octal permissions, such as `0o755`. (@timriley in #18)
11
+ ### Changed
10
12
 
13
+ ### Deprecated
14
+
15
+ ### Removed
16
+
17
+ ### Fixed
11
18
 
12
- [Compare v1.0.2...v1.1.0](https://github.com/dry-rb/dry-files/compare/v1.0.2...v1.1.0)
19
+ ### Security
13
20
 
14
- ## 1.0.2 2023-10-03
21
+ [Unreleased]: https://github.com/dry-rb/dry-files/compare/v1.2.0...main
15
22
 
23
+ ## [1.2.0] - 2026-11-19
24
+
25
+ ### Added
26
+
27
+ - Add `Dry::Files#readlines`. (@sandbergja in #23)
16
28
 
17
29
  ### Fixed
18
30
 
19
- - Ensure `Dry::Files#inject_line_at_block_bottom` to not match false positive closing blocks (@jodosha in #17)
31
+ - Detect binary content when writing to filesystem and handle a binary file write. (@katafrakt in #24)
32
+ - Ensure `Dry::Files#inject_line_at_class_bottom` injects before the class's own `end`, rather than the `end` of the first method, inner class, or module inside it. (@parndt in #25)
33
+
34
+ [1.2.0]: https://github.com/dry-rb/dry-files/compare/v1.1.0...v1.2.0
35
+
36
+ ## [1.1.0] - 2023-10-18
20
37
 
38
+ ### Added
21
39
 
22
- [Compare v1.0.1...v1.0.2](https://github.com/dry-rb/dry-files/compare/v1.0.1...v1.0.2)
40
+ - Add `Dry::Files#chmod(path, mode)` to modify file permissions. Provide the mode as an integer
41
+ to match UNIX octal permissions, such as `0o755`. (@timriley in #18)
23
42
 
24
- ## 1.0.1 2022-11-21
43
+ [1.1.0]: https://github.com/dry-rb/dry-files/compare/v1.0.2...v1.1.0
25
44
 
45
+ ## [1.0.2] - 2023-10-03
26
46
 
27
47
  ### Fixed
28
48
 
29
- - Do not introduce multiple newlines in `Dry::Files#append` (@timriley in #14)
49
+ - Ensure `Dry::Files#inject_line_at_block_bottom` to not match false positive closing blocks (@jodosha in #17)
30
50
 
51
+ [1.0.2]: https://github.com/dry-rb/dry-files/compare/v1.0.1...v1.0.2
31
52
 
32
- [Compare v1.0.0...v1.0.1](https://github.com/dry-rb/dry-files/compare/v1.0.0...v1.0.1)
53
+ ## [1.0.1] - 2022-11-21
33
54
 
34
- ## 1.0.0 2022-11-04
55
+ ### Fixed
35
56
 
57
+ - Do not introduce multiple newlines in `Dry::Files#append` (@timriley in #14)
58
+
59
+ [1.0.1]: https://github.com/dry-rb/dry-files/compare/v1.0.0...v1.0.1
60
+
61
+ ## [1.0.0] - 2022-11-04
36
62
 
37
63
  ### Changed
38
64
 
39
65
  - Bumped version to 1.0.0 (@solnic)
40
66
 
41
- [Compare v0.3.0...v1.0.0](https://github.com/dry-rb/dry-files/compare/v0.3.0...v1.0.0)
42
-
43
- ## 0.3.0 2022-09-19
67
+ [1.0.0]: https://github.com/dry-rb/dry-files/compare/v0.3.0...v1.0.0
44
68
 
69
+ ## [0.3.0] - 2022-09-19
45
70
 
46
71
  ### Added
47
72
 
48
73
  - Support for `inject_line_at_class_bottom` (via #13) (@jodosha)
49
74
 
75
+ [0.3.0]: https://github.com/dry-rb/dry-files/compare/v0.2.0...v0.3.0
50
76
 
51
- [Compare v0.2.0...v0.3.0](https://github.com/dry-rb/dry-files/compare/v0.2.0...v0.3.0)
52
-
53
- ## 0.2.0 2022-07-10
54
-
77
+ ## [0.2.0] - 2022-07-10
55
78
 
56
79
  ### Added
57
80
 
58
81
  - Dry::Files#append to create intermediate directory and touch destination file (via #8) (@jodosha)
59
82
 
83
+ [0.2.0]: https://github.com/dry-rb/dry-files/compare/v0.1.0...v0.2.0
60
84
 
61
- [Compare v0.1.0...v0.2.0](https://github.com/dry-rb/dry-files/compare/v0.1.0...v0.2.0)
62
-
63
- ## 0.1.0 2021-05-04
85
+ ## 0.1.0 - 2021-05-04
64
86
 
65
87
  Initial release
66
88
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2023 dry-rb team
3
+ Copyright (c) 2015-2026 Hanakai team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,22 +1,22 @@
1
- <!--- this file is synced from dry-rb/template-gem project -->
2
- [gem]: https://rubygems.org/gems/dry-files
3
- [actions]: https://github.com/dry-rb/dry-files/actions
4
-
5
- # dry-files [![Gem Version](https://badge.fury.io/rb/dry-files.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-files/workflows/ci/badge.svg)][actions]
1
+ <!--- This file is synced from hanakai-rb/repo-sync -->
6
2
 
7
- ## Links
3
+ [actions]: https://github.com/dry-rb/dry-files/actions
4
+ [chat]: https://discord.gg/naQApPAsZB
5
+ [forum]: https://discourse.hanakai.org
6
+ [rubygem]: https://rubygems.org/gems/dry-files
8
7
 
9
- * [User documentation](https://dry-rb.org/gems/dry-files)
10
- * [API documentation](http://rubydoc.info/gems/dry-files)
11
- * [Forum](https://discourse.dry-rb.org)
8
+ # dry-files [![Gem Version](https://badge.fury.io/rb/dry-files.svg)][rubygem] [![CI Status](https://github.com/dry-rb/dry-files/workflows/CI/badge.svg)][actions]
12
9
 
13
- ## Supported Ruby versions
10
+ [![Forum](https://img.shields.io/badge/Forum-dc360f?logo=discourse&logoColor=white)][forum]
11
+ [![Chat](https://img.shields.io/badge/Chat-717cf8?logo=discord&logoColor=white)][chat]
14
12
 
15
- This library officially supports the following Ruby versions:
13
+ ## Links
16
14
 
17
- * MRI `>= 3.0.0`
18
- * jruby `>= 9.4` (not tested on CI)
15
+ - [User documentation](https://dry-rb.org/gems/dry-files)
16
+ - [API documentation](http://rubydoc.info/gems/dry-files)
17
+ - [Forum](https://discourse.dry-rb.org)
19
18
 
20
19
  ## License
21
20
 
22
21
  See `LICENSE` file.
22
+
data/dry-files.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # this file is synced from dry-rb/template-gem project
3
+ # This file is synced from hanakai-rb/repo-sync. To update it, edit repo-sync.yml.
4
4
 
5
5
  lib = File.expand_path("lib", __dir__)
6
6
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -8,8 +8,8 @@ require "dry/files/version"
8
8
 
9
9
  Gem::Specification.new do |spec|
10
10
  spec.name = "dry-files"
11
- spec.authors = ["Luca Guidi"]
12
- spec.email = ["me@lucaguidi.com"]
11
+ spec.authors = ["Hanakai team"]
12
+ spec.email = ["info@hanakai.org"]
13
13
  spec.license = "MIT"
14
14
  spec.version = Dry::Files::VERSION.dup
15
15
 
@@ -17,18 +17,21 @@ Gem::Specification.new do |spec|
17
17
  spec.description = spec.summary
18
18
  spec.homepage = "https://dry-rb.org/gems/dry-files"
19
19
  spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-files.gemspec", "lib/**/*"]
20
- spec.bindir = "bin"
21
- spec.executables = []
20
+ spec.bindir = "exe"
21
+ spec.executables = Dir["exe/*"].map { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
24
+ spec.extra_rdoc_files = ["README.md", "CHANGELOG.md", "LICENSE"]
25
+
25
26
  spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-files/blob/main/CHANGELOG.md"
26
27
  spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-files"
27
28
  spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-files/issues"
29
+ spec.metadata["funding_uri"] = "https://github.com/sponsors/hanami"
28
30
 
29
- spec.required_ruby_version = ">= 2.7.0"
30
-
31
- # to update dependencies edit project.yml
31
+ spec.required_ruby_version = ">= 3.3"
32
32
 
33
- spec.add_development_dependency "rspec", "~> 3.10"
33
+ spec.add_development_dependency "bundler"
34
+ spec.add_development_dependency "rake"
35
+ spec.add_development_dependency "rspec"
34
36
  end
37
+
@@ -125,9 +125,14 @@ module Dry
125
125
  # @api private
126
126
  def write(path, *content)
127
127
  mkdir_p(path)
128
+ content = Array(content).flatten
128
129
 
129
130
  self.open(path, WRITE_MODE) do |f|
130
- f.write(Array(content).flatten.join)
131
+ if content.any? { |c| c.encoding == Encoding::BINARY || !c.valid_encoding? }
132
+ f.binmode
133
+ end
134
+
135
+ f.write(content.join)
131
136
  end
132
137
  end
133
138
 
@@ -378,8 +383,8 @@ module Dry
378
383
  # @api private
379
384
  def with_error_handling
380
385
  yield
381
- rescue SystemCallError => e
382
- raise IOError, e
386
+ rescue SystemCallError => exception
387
+ raise IOError, exception
383
388
  end
384
389
  end
385
390
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  class Files
5
- VERSION = "1.1.0"
5
+ VERSION = "1.2.0"
6
6
  end
7
7
  end
data/lib/dry/files.rb CHANGED
@@ -53,6 +53,20 @@ module Dry
53
53
  adapter.read(path)
54
54
  end
55
55
 
56
+ # Read file content into an array of lines
57
+ #
58
+ # @param path [String,Pathname] the path to file
59
+ #
60
+ # @return [Array] the lines of the file
61
+ #
62
+ # @raise [Dry::Files::IOError] in case of I/O error
63
+ #
64
+ # @since 1.2.0
65
+ # @api public
66
+ def readlines(path)
67
+ adapter.readlines(path)
68
+ end
69
+
56
70
  # Creates an empty file for the given path.
57
71
  # All the intermediate directories are created.
58
72
  # If the path already exists, it doesn't change the contents
@@ -901,7 +915,7 @@ module Dry
901
915
 
902
916
  # @since 0.1.0
903
917
  # @api private
904
- NEW_LINE = $/ # rubocop:disable Style/SpecialGlobalVars
918
+ NEW_LINE = $/
905
919
  private_constant :NEW_LINE
906
920
 
907
921
  # @since 0.3.0
@@ -961,8 +975,7 @@ module Dry
961
975
 
962
976
  # @since 0.3.0
963
977
  # @api private
964
- INLINE_BLOCK_DELIMITER = Delimiter.new("InlineBlockDelimiter",
965
- INLINE_OPEN_BLOCK, INLINE_CLOSE_BLOCK)
978
+ INLINE_BLOCK_DELIMITER = Delimiter.new("InlineBlockDelimiter", INLINE_OPEN_BLOCK, INLINE_CLOSE_BLOCK)
966
979
  private_constant :INLINE_BLOCK_DELIMITER
967
980
 
968
981
  # @since 0.3.0
@@ -1010,7 +1023,7 @@ module Dry
1010
1023
 
1011
1024
  # @since 0.3.0
1012
1025
  # @api private
1013
- def closing_block_index(content, starting, path, target, delimiter, count_offset = 0) # rubocop:disable Metrics/ParameterLists
1026
+ def closing_block_index(content, starting, path, target, delimiter, count_offset = 0)
1014
1027
  blocks_count = content.count { |line| line.match?(delimiter.opening_matcher) } + count_offset
1015
1028
  matching_line = content.find do |line|
1016
1029
  blocks_count -= 1 if line.match?(delimiter.closing_matcher)
@@ -1024,6 +1037,12 @@ module Dry
1024
1037
  # @since 0.4.0
1025
1038
  # @api private
1026
1039
  def closing_class_index(content, starting, path, target, delimiter)
1040
+ # The class's own `end` is the first line back at the class's indentation. This also skips the
1041
+ # `end` of every method, inner class, and module, which counting `do` blocks can't tell apart.
1042
+ closing = /\A#{Regexp.escape(content.first[SPACE_MATCHER])}#{CLOSE_BLOCK}\b/
1043
+ ending = content.index { |line| line.match?(closing) }
1044
+ return ending + starting if ending
1045
+
1027
1046
  closing_block_index(content, starting, path, target, delimiter, 1)
1028
1047
  end
1029
1048
 
metadata CHANGED
@@ -1,35 +1,65 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-files
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Luca Guidi
8
- autorequire:
9
- bindir: bin
7
+ - Hanakai team
8
+ bindir: exe
10
9
  cert_chain: []
11
- date: 2023-10-18 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: bundler
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
13
40
  - !ruby/object:Gem::Dependency
14
41
  name: rspec
15
42
  requirement: !ruby/object:Gem::Requirement
16
43
  requirements:
17
- - - "~>"
44
+ - - ">="
18
45
  - !ruby/object:Gem::Version
19
- version: '3.10'
46
+ version: '0'
20
47
  type: :development
21
48
  prerelease: false
22
49
  version_requirements: !ruby/object:Gem::Requirement
23
50
  requirements:
24
- - - "~>"
51
+ - - ">="
25
52
  - !ruby/object:Gem::Version
26
- version: '3.10'
53
+ version: '0'
27
54
  description: file utilities
28
55
  email:
29
- - me@lucaguidi.com
56
+ - info@hanakai.org
30
57
  executables: []
31
58
  extensions: []
32
- extra_rdoc_files: []
59
+ extra_rdoc_files:
60
+ - CHANGELOG.md
61
+ - LICENSE
62
+ - README.md
33
63
  files:
34
64
  - CHANGELOG.md
35
65
  - LICENSE
@@ -48,11 +78,10 @@ homepage: https://dry-rb.org/gems/dry-files
48
78
  licenses:
49
79
  - MIT
50
80
  metadata:
51
- allowed_push_host: https://rubygems.org
52
81
  changelog_uri: https://github.com/dry-rb/dry-files/blob/main/CHANGELOG.md
53
82
  source_code_uri: https://github.com/dry-rb/dry-files
54
83
  bug_tracker_uri: https://github.com/dry-rb/dry-files/issues
55
- post_install_message:
84
+ funding_uri: https://github.com/sponsors/hanami
56
85
  rdoc_options: []
57
86
  require_paths:
58
87
  - lib
@@ -60,15 +89,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
89
  requirements:
61
90
  - - ">="
62
91
  - !ruby/object:Gem::Version
63
- version: 2.7.0
92
+ version: '3.3'
64
93
  required_rubygems_version: !ruby/object:Gem::Requirement
65
94
  requirements:
66
95
  - - ">="
67
96
  - !ruby/object:Gem::Version
68
97
  version: '0'
69
98
  requirements: []
70
- rubygems_version: 3.3.26
71
- signing_key:
99
+ rubygems_version: 3.6.9
72
100
  specification_version: 4
73
101
  summary: file utilities
74
102
  test_files: []