dry-files 1.0.2 → 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: 3b415a307ce621ab6601397d6cf2a772ef390210e1591b99f5ab40ccedac6108
4
- data.tar.gz: c63b4c80401dccba0c095fa5a26d1b25c4e50d00f71978037e22b481a384c7db
3
+ metadata.gz: 05354c104f2aa90d07d74b8059a31ebd655238e07cf940ac367a067a7dab541f
4
+ data.tar.gz: 0dc658366d6dd0f3ffb208145fc440115a790a4e5373dcdfb975aa29130c0fda
5
5
  SHA512:
6
- metadata.gz: c4b93220b78ec92f7224d9d033d5055b0be5f5f34fc9e187227e3d5c8198f9b9f1e02316295525d04a47709dc3614c40d30e9d43d68f6bbaaaf69f27f442f47c
7
- data.tar.gz: 7cf2972a9be4e35dfc2babaa8bfd3ad8f0ee5646c69b397eb6a334baba97c906d17e7a28177229814eacb99b84839062bdda0a2f5972778f8f498f911ede3d61
6
+ metadata.gz: b5983db3e5c15966b053194679dce7c694f79979ac7d4d4f78c0cc4ed86bcaf5916e2096d01fdfe3d5f6bbf7e12d558bd4dd8b4cf7c329b6bc65d5f856570761
7
+ data.tar.gz: ea880d184e8f862b878c8ee0c70da149a33d692eecc8906b4ccd878240f0a0735e3c34a81b5c63be7cd1bebe37dab8e0969a5cc8493d6a3a3291f373ca8f00ef
data/CHANGELOG.md CHANGED
@@ -1,55 +1,88 @@
1
- <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
1
+ # Changelog
2
2
 
3
- ## 1.0.2 2023-10-03
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]
8
+
9
+ ### Added
10
+
11
+ ### Changed
12
+
13
+ ### Deprecated
14
+
15
+ ### Removed
5
16
 
6
17
  ### Fixed
7
18
 
8
- - Ensure Dry::Files#inject_line_at_block_bottom to not match false positive closing blocks (@jodosha in #17)
19
+ ### Security
9
20
 
21
+ [Unreleased]: https://github.com/dry-rb/dry-files/compare/v1.2.0...main
10
22
 
11
- [Compare v1.0.1...v1.0.2](https://github.com/dry-rb/dry-files/compare/v1.0.1...v1.0.2)
23
+ ## [1.2.0] - 2026-11-19
12
24
 
13
- ## 1.0.1 2022-11-21
25
+ ### Added
14
26
 
27
+ - Add `Dry::Files#readlines`. (@sandbergja in #23)
15
28
 
16
29
  ### Fixed
17
30
 
18
- - Do not introduce multiple newlines in `Dry::Files#append` (@timriley in #14)
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)
19
33
 
34
+ [1.2.0]: https://github.com/dry-rb/dry-files/compare/v1.1.0...v1.2.0
20
35
 
21
- [Compare v1.0.0...v1.0.1](https://github.com/dry-rb/dry-files/compare/v1.0.0...v1.0.1)
36
+ ## [1.1.0] - 2023-10-18
37
+
38
+ ### Added
22
39
 
23
- ## 1.0.0 2022-11-04
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)
24
42
 
43
+ [1.1.0]: https://github.com/dry-rb/dry-files/compare/v1.0.2...v1.1.0
44
+
45
+ ## [1.0.2] - 2023-10-03
46
+
47
+ ### Fixed
48
+
49
+ - Ensure `Dry::Files#inject_line_at_block_bottom` to not match false positive closing blocks (@jodosha in #17)
50
+
51
+ [1.0.2]: https://github.com/dry-rb/dry-files/compare/v1.0.1...v1.0.2
52
+
53
+ ## [1.0.1] - 2022-11-21
54
+
55
+ ### Fixed
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
25
62
 
26
63
  ### Changed
27
64
 
28
65
  - Bumped version to 1.0.0 (@solnic)
29
66
 
30
- [Compare v0.3.0...v1.0.0](https://github.com/dry-rb/dry-files/compare/v0.3.0...v1.0.0)
31
-
32
- ## 0.3.0 2022-09-19
67
+ [1.0.0]: https://github.com/dry-rb/dry-files/compare/v0.3.0...v1.0.0
33
68
 
69
+ ## [0.3.0] - 2022-09-19
34
70
 
35
71
  ### Added
36
72
 
37
73
  - Support for `inject_line_at_class_bottom` (via #13) (@jodosha)
38
74
 
75
+ [0.3.0]: https://github.com/dry-rb/dry-files/compare/v0.2.0...v0.3.0
39
76
 
40
- [Compare v0.2.0...v0.3.0](https://github.com/dry-rb/dry-files/compare/v0.2.0...v0.3.0)
41
-
42
- ## 0.2.0 2022-07-10
43
-
77
+ ## [0.2.0] - 2022-07-10
44
78
 
45
79
  ### Added
46
80
 
47
81
  - Dry::Files#append to create intermediate directory and touch destination file (via #8) (@jodosha)
48
82
 
83
+ [0.2.0]: https://github.com/dry-rb/dry-files/compare/v0.1.0...v0.2.0
49
84
 
50
- [Compare v0.1.0...v0.2.0](https://github.com/dry-rb/dry-files/compare/v0.1.0...v0.2.0)
51
-
52
- ## 0.1.0 2021-05-04
85
+ ## 0.1.0 - 2021-05-04
53
86
 
54
87
  Initial release
55
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,33 @@ 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)
136
+ end
137
+ end
138
+
139
+ # Sets UNIX permissions of the file at the given path.
140
+ #
141
+ # Accepts permissions in numeric mode only, best provided as octal numbers matching the
142
+ # standard UNIX octal permission modes, such as `0o544` for a file writeable by its owner and
143
+ # readable by others, or `0o755` for a file writeable by its owner and executable by everyone.
144
+ #
145
+ # @param path [String,Pathname] the path to the file
146
+ # @param mode [Integer] the UNIX permissions mode
147
+ #
148
+ # @raise [Dry::Files::IOError] in case of I/O error
149
+ #
150
+ # @since 1.1.0
151
+ # @api private
152
+ def chmod(path, mode)
153
+ with_error_handling do
154
+ file_utils.chmod(mode, path)
131
155
  end
132
156
  end
133
157
 
@@ -359,8 +383,8 @@ module Dry
359
383
  # @api private
360
384
  def with_error_handling
361
385
  yield
362
- rescue SystemCallError => e
363
- raise IOError, e
386
+ rescue SystemCallError => exception
387
+ raise IOError, exception
364
388
  end
365
389
  end
366
390
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  class Files
5
- VERSION = "1.0.2"
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
@@ -82,6 +96,25 @@ module Dry
82
96
  adapter.write(path, *content)
83
97
  end
84
98
 
99
+ # Sets UNIX permissions of the file at the given path.
100
+ #
101
+ # Accepts permissions in numeric mode only, best provided as octal numbers matching the
102
+ # standard UNIX octal permission modes, such as `0o544` for a file writeable by its owner and
103
+ # readable by others, or `0o755` for a file writeable by its owner and executable by everyone.
104
+ #
105
+ # @param path [String,Pathname] the path to the file
106
+ # @param mode [Integer] the UNIX permissions mode
107
+ #
108
+ # @raise [Dry::Files::IOError] in case of I/O error
109
+ #
110
+ # @since 1.1.0
111
+ # @api public
112
+ def chmod(path, mode)
113
+ raise Dry::Files::Error, "mode should be an integer (e.g. 0o755)" unless mode.is_a?(Integer)
114
+
115
+ adapter.chmod(path, mode)
116
+ end
117
+
85
118
  # Returns a new string formed by joining the strings using Operating
86
119
  # System path separator
87
120
  #
@@ -882,7 +915,7 @@ module Dry
882
915
 
883
916
  # @since 0.1.0
884
917
  # @api private
885
- NEW_LINE = $/ # rubocop:disable Style/SpecialGlobalVars
918
+ NEW_LINE = $/
886
919
  private_constant :NEW_LINE
887
920
 
888
921
  # @since 0.3.0
@@ -942,8 +975,7 @@ module Dry
942
975
 
943
976
  # @since 0.3.0
944
977
  # @api private
945
- INLINE_BLOCK_DELIMITER = Delimiter.new("InlineBlockDelimiter",
946
- INLINE_OPEN_BLOCK, INLINE_CLOSE_BLOCK)
978
+ INLINE_BLOCK_DELIMITER = Delimiter.new("InlineBlockDelimiter", INLINE_OPEN_BLOCK, INLINE_CLOSE_BLOCK)
947
979
  private_constant :INLINE_BLOCK_DELIMITER
948
980
 
949
981
  # @since 0.3.0
@@ -991,7 +1023,7 @@ module Dry
991
1023
 
992
1024
  # @since 0.3.0
993
1025
  # @api private
994
- 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)
995
1027
  blocks_count = content.count { |line| line.match?(delimiter.opening_matcher) } + count_offset
996
1028
  matching_line = content.find do |line|
997
1029
  blocks_count -= 1 if line.match?(delimiter.closing_matcher)
@@ -1005,6 +1037,12 @@ module Dry
1005
1037
  # @since 0.4.0
1006
1038
  # @api private
1007
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
+
1008
1046
  closing_block_index(content, starting, path, target, delimiter, 1)
1009
1047
  end
1010
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.0.2
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-03 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: []