dry-files 1.0.1 → 1.1.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: aeceff289982d160ec9a1687677a09ce2d204b4ee1c1f724361ebca4afbf2a5e
4
- data.tar.gz: b667c59ffa7e9b74f0a4fb2a63f1b8a8e1e4018f2ee150c310fd0e9fb1f82612
3
+ metadata.gz: 73391c6f7e4e115941911686c45307707e68fa4ba0f4be5a7cebba14d7eeb042
4
+ data.tar.gz: dcd71ad5b06891df556f0146f2520e4b981024afa06291016e56b194a4f1fb2e
5
5
  SHA512:
6
- metadata.gz: 4faeaa5354a10101957a33a1434ec943c872d06c5dc4ccffceec78cb905c70e322ce579537ec612de5f0796db4d6e85ddeabbb92269c9e17eed4cf8e1ced336a
7
- data.tar.gz: 510106844dbb56009e77c8c1570c8d83e55257d7f22cbbd5d4d351eae9ebe1dec76d4736049e84bc647467d222313922acf745b6ee1443284e632afdd263d2bd
6
+ metadata.gz: 392bfc69636d993cd92e8462079079ad000ef6ebe60467eee72d30f9e2726fc04705f05ada482cfe0147320abab56afd91b6b782b25e9f3a042c563590d589fd
7
+ data.tar.gz: 7c3a4723b89339db36f532f7579f6574c593864e6a79cecfc5cc382280d421338fdd2700c1edffb6fb83b5d917102a2c5be63306f2833c555d5250f0a8d9c1da
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
+ ## 1.1.0 2023-10-18
4
+
5
+
6
+ ### Added
7
+
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)
10
+
11
+
12
+ [Compare v1.0.2...v1.1.0](https://github.com/dry-rb/dry-files/compare/v1.0.2...v1.1.0)
13
+
14
+ ## 1.0.2 2023-10-03
15
+
16
+
17
+ ### Fixed
18
+
19
+ - Ensure `Dry::Files#inject_line_at_block_bottom` to not match false positive closing blocks (@jodosha in #17)
20
+
21
+
22
+ [Compare v1.0.1...v1.0.2](https://github.com/dry-rb/dry-files/compare/v1.0.1...v1.0.2)
23
+
3
24
  ## 1.0.1 2022-11-21
4
25
 
5
26
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2022 dry-rb team
3
+ Copyright (c) 2015-2023 dry-rb 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,29 +1,21 @@
1
1
  <!--- this file is synced from dry-rb/template-gem project -->
2
2
  [gem]: https://rubygems.org/gems/dry-files
3
3
  [actions]: https://github.com/dry-rb/dry-files/actions
4
- [codacy]: https://www.codacy.com/gh/dry-rb/dry-files
5
- [chat]: https://dry-rb.zulipchat.com
6
- [inchpages]: http://inch-ci.org/github/dry-rb/dry-files
7
4
 
8
- # dry-files [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
9
-
10
- [![Gem Version](https://badge.fury.io/rb/dry-files.svg)][gem]
11
- [![CI Status](https://github.com/dry-rb/dry-files/workflows/ci/badge.svg)][actions]
12
- [![Codacy Badge](https://api.codacy.com/project/badge/Grade/71200ee8d70b412c9e21c20b8b3b3688)][codacy]
13
- [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/71200ee8d70b412c9e21c20b8b3b3688)][codacy]
14
- [![Inline docs](http://inch-ci.org/github/dry-rb/dry-files.svg?branch=main)][inchpages]
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]
15
6
 
16
7
  ## Links
17
8
 
18
9
  * [User documentation](https://dry-rb.org/gems/dry-files)
19
10
  * [API documentation](http://rubydoc.info/gems/dry-files)
11
+ * [Forum](https://discourse.dry-rb.org)
20
12
 
21
13
  ## Supported Ruby versions
22
14
 
23
15
  This library officially supports the following Ruby versions:
24
16
 
25
- * MRI `>= 2.7.0`
26
- * jruby `>= 9.3` (postponed until 2.7 is supported)
17
+ * MRI `>= 3.0.0`
18
+ * jruby `>= 9.4` (not tested on CI)
27
19
 
28
20
  ## License
29
21
 
@@ -131,6 +131,25 @@ module Dry
131
131
  end
132
132
  end
133
133
 
134
+ # Sets UNIX permissions of the file at the given path.
135
+ #
136
+ # Accepts permissions in numeric mode only, best provided as octal numbers matching the
137
+ # standard UNIX octal permission modes, such as `0o544` for a file writeable by its owner and
138
+ # readable by others, or `0o755` for a file writeable by its owner and executable by everyone.
139
+ #
140
+ # @param path [String,Pathname] the path to the file
141
+ # @param mode [Integer] the UNIX permissions mode
142
+ #
143
+ # @raise [Dry::Files::IOError] in case of I/O error
144
+ #
145
+ # @since 1.1.0
146
+ # @api private
147
+ def chmod(path, mode)
148
+ with_error_handling do
149
+ file_utils.chmod(mode, path)
150
+ end
151
+ end
152
+
134
153
  # Returns a new string formed by joining the strings using Operating
135
154
  # System path separator
136
155
  #
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  class Files
5
- VERSION = "1.0.1"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
data/lib/dry/files.rb CHANGED
@@ -82,6 +82,25 @@ module Dry
82
82
  adapter.write(path, *content)
83
83
  end
84
84
 
85
+ # Sets UNIX permissions of the file at the given path.
86
+ #
87
+ # Accepts permissions in numeric mode only, best provided as octal numbers matching the
88
+ # standard UNIX octal permission modes, such as `0o544` for a file writeable by its owner and
89
+ # readable by others, or `0o755` for a file writeable by its owner and executable by everyone.
90
+ #
91
+ # @param path [String,Pathname] the path to the file
92
+ # @param mode [Integer] the UNIX permissions mode
93
+ #
94
+ # @raise [Dry::Files::IOError] in case of I/O error
95
+ #
96
+ # @since 1.1.0
97
+ # @api public
98
+ def chmod(path, mode)
99
+ raise Dry::Files::Error, "mode should be an integer (e.g. 0o755)" unless mode.is_a?(Integer)
100
+
101
+ adapter.chmod(path, mode)
102
+ end
103
+
85
104
  # Returns a new string formed by joining the strings using Operating
86
105
  # System path separator
87
106
  #
@@ -841,6 +860,11 @@ module Dry
841
860
  # @since 0.3.0
842
861
  # @api private
843
862
  class Delimiter
863
+ # @since 1.0.2
864
+ # @api private
865
+ SPACE_MATCHER_GENERAL = /[[:space:]]*/
866
+ private_constant :SPACE_MATCHER_GENERAL
867
+
844
868
  # @since 0.3.0
845
869
  # @api private
846
870
  attr_reader :opening, :closing
@@ -853,6 +877,26 @@ module Dry
853
877
  @closing = closing
854
878
  freeze
855
879
  end
880
+
881
+ # @since 1.0.2
882
+ # @api private
883
+ def opening_matcher
884
+ matcher(opening)
885
+ end
886
+
887
+ # @since 1.0.2
888
+ # @api private
889
+ def closing_matcher
890
+ matcher(closing)
891
+ end
892
+
893
+ private
894
+
895
+ # @since 1.0.2
896
+ # @api private
897
+ def matcher(delimiter)
898
+ /#{SPACE_MATCHER_GENERAL}\b#{delimiter}\b(?:#{SPACE_MATCHER_GENERAL}|#{NEW_LINE_MATCHER})/
899
+ end
856
900
  end
857
901
 
858
902
  # @since 0.1.0
@@ -862,12 +906,12 @@ module Dry
862
906
 
863
907
  # @since 0.3.0
864
908
  # @api private
865
- NEW_LINE_MATCHER = /#{NEW_LINE}\z/.freeze
909
+ NEW_LINE_MATCHER = /#{NEW_LINE}\z/
866
910
  private_constant :NEW_LINE_MATCHER
867
911
 
868
912
  # @since 0.3.0
869
913
  # @api private
870
- EMPTY_LINE = /\A\z/.freeze
914
+ EMPTY_LINE = /\A\z/
871
915
  private_constant :EMPTY_LINE
872
916
 
873
917
  # @since 0.1.0
@@ -887,7 +931,7 @@ module Dry
887
931
 
888
932
  # @since 0.1.0
889
933
  # @api private
890
- SPACE_MATCHER = /\A[[:space:]]*/.freeze
934
+ SPACE_MATCHER = /\A[[:space:]]*/
891
935
  private_constant :SPACE_MATCHER
892
936
 
893
937
  # @since 0.3.0
@@ -967,9 +1011,9 @@ module Dry
967
1011
  # @since 0.3.0
968
1012
  # @api private
969
1013
  def closing_block_index(content, starting, path, target, delimiter, count_offset = 0) # rubocop:disable Metrics/ParameterLists
970
- blocks_count = content.count { |line| line.match?(delimiter.opening) } + count_offset
1014
+ blocks_count = content.count { |line| line.match?(delimiter.opening_matcher) } + count_offset
971
1015
  matching_line = content.find do |line|
972
- blocks_count -= 1 if line.match?(delimiter.closing)
1016
+ blocks_count -= 1 if line.match?(delimiter.closing_matcher)
973
1017
  line if blocks_count.zero?
974
1018
  end
975
1019
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-files
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-21 00:00:00.000000000 Z
11
+ date: 2023-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []
70
- rubygems_version: 3.1.6
70
+ rubygems_version: 3.3.26
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: file utilities