planck 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b15bc70b57a5cb6c992a3d81533cb493502f4232e0253bc039bb784295d4931a
4
+ data.tar.gz: 409c60c794182379d8d2189320e69d712824b3edd317c4050bda3cd5fed21c72
5
+ SHA512:
6
+ metadata.gz: 01f9661af3f537f8d26833d7a1696f76966b896c4a019fb7595573f9a714f5ef6a6bf3bd623611b73aae8bf10111942e3a27810b472ef0414458d96989a74a97
7
+ data.tar.gz: 9a5c1f995ad2969842ad731dfe9cb4c659f2d782de49de71bccdf1dc858851b55fa493a67ce98dea315637a17c115fab083ce6f57f7ec8602445d2cd9df3127b
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-09-19
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Matheus Richard
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # Planck
2
+
3
+ Atomic file writes for Ruby.
4
+
5
+ ## Why?
6
+
7
+ A naive file write:
8
+
9
+ ```ruby
10
+ File.write("secrets.json", json)
11
+ ```
12
+
13
+ is **not atomic**. If your process crashes midway, or if another process reads the file while it’s being written, you can end up with truncated or corrupted data.
14
+
15
+ `Planck.atomic_write` solves this. It
16
+
17
+ 1. Writes the data to a hidden tempfile in the same directory.
18
+ 2. Flushes (`fsync`) to ensure the contents are on disk.
19
+ 3. Renames the tempfile into place (`rename` is atomic on POSIX).
20
+ 4. Flushes the parent directory entry (`fsync` again) to make the rename durable even in the event of a power loss.
21
+
22
+ As a result, readers always see either the old file or the fully written new one — never an in-between state.
23
+
24
+ ## Installation
25
+
26
+ Install the gem and add to the application's Gemfile by executing:
27
+
28
+ ```bash
29
+ bundle add planck
30
+ ```
31
+
32
+ If bundler is not being used to manage dependencies, install the gem by executing:
33
+
34
+ ```bash
35
+ gem install planck
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ```ruby
41
+ require "planck"
42
+
43
+ # Safely replace or create a file with 0600 permissions by default
44
+ Planck.atomic_write("secrets.json", '{"token":"abc123"}')
45
+
46
+ # Preserve existing file permissions (mode) when overwriting
47
+ Planck.atomic_write("config.yml", "new settings", preserve_mode: true)
48
+
49
+ ```
50
+
51
+ ## Development
52
+
53
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
54
+
55
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/thoughtbot/planck.
60
+
61
+ ## License
62
+
63
+ Open source templates are Copyright (c) thoughtbot, inc. It contains free
64
+ software that may be redistributed under the terms specified in the
65
+ [LICENSE](https://github.com/thoughtbot/planck/blob/main/LICENSE.txt)
66
+ file.
67
+
68
+ ## Code of Conduct
69
+
70
+ Everyone interacting in the DataCustoms project's codebases, issue trackers,
71
+ chat rooms and mailing lists is expected to follow the [code of
72
+ conduct](https://github.com/thoughtbot/planck/blob/main/CODE_OF_CONDUCT.md).
73
+
74
+ <!-- START /templates/footer.md -->
75
+
76
+ ## About thoughtbot
77
+
78
+ ![thoughtbot](https://thoughtbot.com/thoughtbot-logo-for-readmes.svg)
79
+
80
+ This repo is maintained and funded by thoughtbot, inc. The names and logos for
81
+ thoughtbot are trademarks of thoughtbot, inc.
82
+
83
+ We love open source software! See [our other projects][community]. We are
84
+ [available for hire][hire].
85
+
86
+ [community]: https://thoughtbot.com/community?utm_source=github&utm_medium=readme&utm_campaign=planck
87
+ [hire]: https://thoughtbot.com/hire-us?utm_source=github&utm_medium=readme&utm_campaign=planck
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
9
+ task build: :spec
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Planck
4
+ VERSION = "0.1.0"
5
+ end
data/lib/planck.rb ADDED
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tempfile"
4
+
5
+ module Planck
6
+ def self.atomic_write(path, contents, preserve_mode: false)
7
+ dir = File.dirname(path)
8
+ stat = (preserve_mode && File.exist?(path)) ? File.stat(path) : nil
9
+
10
+ Tempfile.open(".#{File.basename(path)}", dir) do |tmp|
11
+ tmp.write(contents)
12
+ tmp.flush
13
+ tmp.fsync
14
+ tmp.close
15
+
16
+ if stat
17
+ begin
18
+ File.chmod(stat.mode, tmp.path)
19
+ rescue Errno::EPERM, Errno::EACCES
20
+ # If we lack privileges, proceed without preserving.
21
+ end
22
+ end
23
+
24
+ File.rename(tmp.path, path)
25
+ File.open(dir, File::RDONLY) { |d| d.fsync }
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: planck
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matheus Richard
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: |
13
+ Planck provides atomic file writes for Ruby. When you call
14
+ `Planck.atomic_write`, your file is either fully replaced or not touched at
15
+ all — never left in a half-written state."
16
+ email:
17
+ - matheusrichardt@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - CHANGELOG.md
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/planck.rb
27
+ - lib/planck/version.rb
28
+ homepage: https://github.com/thoughtbot/planck
29
+ licenses:
30
+ - MIT
31
+ metadata:
32
+ homepage_uri: https://github.com/thoughtbot/planck
33
+ source_code_uri: https://github.com/thoughtbot/planck
34
+ changelog_uri: https://github.com/thoughtbot/planck/blob/main/CHANGELOG.md
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 3.2.0
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubygems_version: 3.6.9
50
+ specification_version: 4
51
+ summary: Atomic file writes for Ruby
52
+ test_files: []