SafeFile 1.0.0 → 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 +4 -4
- data/README.md +33 -1
- data/lib/safefile.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9a7526fc0f29fc5762ce49b1a54909aade9232259e46282b1c5dd500e73cf926
|
|
4
|
+
data.tar.gz: 2e3849347fcce2da355c00db71e3f382e795a10abd49083c97093711886be11e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8029d1b179db70f93818588dc519be5bf30fab10235e4b09c98d1c82e95b128f01980d01ef0de58fc2559f0630786467a09b814a842ab412d55b88c89fd3c25c
|
|
7
|
+
data.tar.gz: f8de802c3977c2b6aebe633f57c52cd16708d059f6e2d7866553e2d601e494c9ac4674c0f9620829bd5d7fd96a36040b1a7b18c3464c15f3a4601c507053d677
|
data/README.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
1
|
# SafeFile
|
|
2
2
|
|
|
3
|
-
Strict file access library for Ruby
|
|
3
|
+
Strict file access library for Ruby
|
|
4
|
+
|
|
5
|
+
## Installing
|
|
6
|
+
> [!WARNING]
|
|
7
|
+
> When installing this Gem, **capitalization matters**, for some reason..
|
|
8
|
+
|
|
9
|
+
You can either use Gem
|
|
10
|
+
```sh
|
|
11
|
+
gem install SafeFile
|
|
12
|
+
```
|
|
13
|
+
or put it in your Gemfile
|
|
14
|
+
```gemfile
|
|
15
|
+
gem "SafeFile"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
It's really easy to use this. You can use it the same way you'd use the File Class. It currently only supports these actions: `SafeFile.read`, `SafeFile.open`, `SafeFile.write`, `SafeFile.foreach`.
|
|
20
|
+
|
|
21
|
+
### Adding safe directories
|
|
22
|
+
By default, the parent working directory is marked as safe. You may change this with the line below
|
|
23
|
+
```ruby
|
|
24
|
+
SafeFile.safe.allowPWD = false
|
|
25
|
+
```
|
|
26
|
+
If you'd like to add other safe directories you may use the `SafeFile.safe.append` method
|
|
27
|
+
```ruby
|
|
28
|
+
SafeFile.safe.append "/tmp/projectCache"
|
|
29
|
+
```
|
|
30
|
+
or remove a safe directory with
|
|
31
|
+
```ruby
|
|
32
|
+
SafeFile.safe.remove "/tmp/projectCache"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
If you need an example of everything, you may take a look at the test document located in the tests directory.
|
data/lib/safefile.rb
CHANGED
|
@@ -28,6 +28,16 @@ module SafeFile
|
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
def foreach file, &block
|
|
32
|
+
file = file.gsub "~/", "#{ENV["HOME"]}/"
|
|
33
|
+
|
|
34
|
+
if performCheck File.expand_path file
|
|
35
|
+
File.foreach file do |line|
|
|
36
|
+
block.call line
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
31
41
|
def safe
|
|
32
42
|
def append dir
|
|
33
43
|
dir = dir.gsub "~/", "#{ENV["HOME"]}/"
|