sugar_utils 0.4.4 → 0.5.0

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
  SHA1:
3
- metadata.gz: b470d625c6383906e21070cde292ed14a90fd80e
4
- data.tar.gz: 455983e1fc7a18e0d6a2eea4f9cef67ed25a2804
3
+ metadata.gz: 8f9d52c1492ed959f2b33c945732bf36188e6fc1
4
+ data.tar.gz: b68e7a45954e73eeac4cfe214c5aec54e4602fd2
5
5
  SHA512:
6
- metadata.gz: cddd4ee3cabe8b6e76f93d4ac9c2be1be91d0a441d408f8234e07fddadd269d6a9ac257e527b8e9aba5203ae12d2157d40fa2107b15490968710010d413601f1
7
- data.tar.gz: 01b451f98527ac178922e6c1f0f9bf6bc493fa6632cd3633d87f6a245f644e9b8a7ea577052e8b3db2942b2f8968d51f67d48a10aaa3717c9281f861d9fc0042
6
+ metadata.gz: cdf2c594969a6c7c0b5279032c18a40b4ce4b6c2b27e86cd814e4f7aa15ded81d661d63890795c5414e27907eb2a4d95c903a22ce3f76803b2f63b41e55bd60b
7
+ data.tar.gz: 5434657b56c88ee11296ff25d9ee00e43207050da6345f6df4e34717edcb8fbe7bb7dcc492c1cad326cd85efd9fae02f37fe4fd71a7dfffe7162ed9930b5b96e
@@ -18,8 +18,5 @@ os:
18
18
  - linux
19
19
  - osx
20
20
  sudo: false
21
- addons:
22
- code_climate:
23
- repo_token: c250bc1551dd13a07efdd5bc8a594924f6f762f7be9762e79da0c8f065cf93dd
24
21
  after_success:
25
22
  - bundle exec codeclimate-test-reporter
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.5.0] - 2018-05-01
10
+ ### Changed
11
+ - bring back :perm as option to set the permissions in SugarUtils::File.write and SugarUtils::File.touch methods
12
+ - :mode option in SugarUtils::File.write is now to be used for setting the file mode (e.g. read/write, append, etc). It can still be used for setting the permissions if it is an integer value for backwards compatibility purposes, but this usage has been deprecated.
13
+
9
14
  ## [0.4.4] - 2018-01-31
10
15
  ### Changed
11
16
  - fixed a bug in SugarUtils::File.read_json which it would raise an exception
@@ -105,23 +105,26 @@ module SugarUtils
105
105
  # @param [Hash] options
106
106
  # @option options [String, Integer] :owner
107
107
  # @option options [String, Integer] :group
108
- # @option options [Integer] :mode
109
- # @option options [Integer] :perm @deprecated
108
+ # @option options [Integer] :mode @deprecated
109
+ # @option options [Integer] :perm
110
110
  # @option options [Integer] :mtime
111
111
  #
112
112
  # @return [void]
113
113
  def self.touch(filename, options = {})
114
114
  owner = options[:owner]
115
115
  group = options[:group]
116
- mode = options[:mode] || options[:perm]
116
+ perm = options[:perm]
117
117
  touch_options = options.select { |k| %i[mtime].include?(k) }
118
118
 
119
- deprecate_option(:touch, :perm, :mode, 2017, 8) if options.key?(:perm)
119
+ if options[:mode].is_a?(Integer)
120
+ perm = options[:mode]
121
+ deprecate_option(:touch, :mode, :perm, 2018, 7)
122
+ end
120
123
 
121
124
  FileUtils.mkdir_p(::File.dirname(filename))
122
125
  FileUtils.touch(filename, touch_options)
123
126
  FileUtils.chown(owner, group, filename)
124
- FileUtils.chmod(mode, filename) if mode
127
+ FileUtils.chmod(perm, filename) if perm
125
128
  end
126
129
 
127
130
  # @param [String] filename
@@ -131,8 +134,8 @@ module SugarUtils
131
134
  # @option options [Boolean] :flush (false)
132
135
  # @option options [String, Integer] :owner
133
136
  # @option options [String, Integer] :group
134
- # @option options [Integer] :mode (0o644)
135
- # @option options [Integer] :perm (0o644) @deprecated
137
+ # @option options [String] :mode (w+)
138
+ # @option options [Integer] :perm (0o644)
136
139
  #
137
140
  # @raise [SugarUtils::File::Error]
138
141
  #
@@ -141,15 +144,21 @@ module SugarUtils
141
144
  flush = options[:flush] || false
142
145
  owner = options[:owner]
143
146
  group = options[:group]
144
- mode = options[:mode] || options[:perm] || 0o644
147
+ perm = options[:perm] || 0o644
148
+ mode = 'w+'
149
+
150
+ if options[:mode].is_a?(Integer)
151
+ perm = options[:mode]
145
152
 
146
- deprecate_option(:touch, :perm, :mode, 2017, 8) if options.key?(:perm)
153
+ deprecate_option(:write, :mode, ' with an integer value; use perm instead', 2018, 7)
154
+ elsif !options[:mode].nil?
155
+ mode = options[:mode]
156
+ end
147
157
 
148
158
  FileUtils.mkdir_p(::File.dirname(filename))
149
- ::File.open(filename, ::File::RDWR | ::File::CREAT, mode) do |file|
159
+ ::File.open(filename, mode, perm) do |file|
150
160
  flock_exclusive(file, options)
151
161
 
152
- file.truncate(0) # Ensure file is empty before proceeding.
153
162
  file.puts(data.to_s)
154
163
 
155
164
  # Flush and fsync to be 100% sure we write this data out now because we
@@ -162,7 +171,7 @@ module SugarUtils
162
171
  end
163
172
 
164
173
  # Ensure that the permissions are correct if the file already existed.
165
- file.chmod(mode)
174
+ file.chmod(perm)
166
175
  end
167
176
  FileUtils.chown(owner, group, filename)
168
177
  rescue Timeout::Error
@@ -205,7 +214,14 @@ module SugarUtils
205
214
 
206
215
  msg = [
207
216
  "NOTE: #{target}#{method} option :#{option_name} is deprecated",
208
- option_repl == :none ? ' with no replacement' : "; use :#{option_repl} instead",
217
+ case option_repl
218
+ when :none
219
+ ' with no replacement'
220
+ when String
221
+ option_repl
222
+ else
223
+ "; use :#{option_repl} instead"
224
+ end,
209
225
  format('. It will be removed on or after %4d-%02d-01.', year, month),
210
226
  "\n#{target}#{method} called from #{location_of_external_caller}"
211
227
  ]
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module SugarUtils
5
- VERSION = '0.4.4'
5
+ VERSION = '0.5.0'
6
6
  end
@@ -171,7 +171,7 @@ describe SugarUtils::File do
171
171
  end
172
172
 
173
173
  context 'with deprecated options' do
174
- let(:options) { { perm: 0o600 } }
174
+ let(:options) { { mode: 0o600 } }
175
175
  before { subject }
176
176
  specify { expect(filename).to have_content(data) }
177
177
  specify { expect(filename).to have_file_permission(0o100600) }
@@ -179,7 +179,7 @@ describe SugarUtils::File do
179
179
 
180
180
  context 'without deprecated options' do
181
181
  let(:options) do
182
- { flush: true, owner: 'nobody', group: 'nogroup', mode: 0o600 }
182
+ { flush: true, owner: 'nobody', group: 'nogroup', mode: 'w', perm: 0o600 }
183
183
  end
184
184
  before do
185
185
  expect_any_instance_of(File).to receive(:flush)
@@ -201,6 +201,16 @@ describe SugarUtils::File do
201
201
  before { write(filename, 'foobar', 0o777) }
202
202
  context 'not locked' do
203
203
  it_behaves_like 'file is written'
204
+
205
+ context 'with append mode' do
206
+ let(:options) { { mode: 'a+' } }
207
+ before do
208
+ expect(described_class).to receive(:flock_exclusive)
209
+ .with(kind_of(File), options)
210
+ subject
211
+ end
212
+ specify { expect(filename).to have_content("foobar#{data}") }
213
+ end
204
214
  end
205
215
  end
206
216
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugar_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Sullivan Cant
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-31 00:00:00.000000000 Z
11
+ date: 2018-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json