SafeFile 1.0.0 → 1.1.1

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +33 -1
  3. data/lib/safefile.rb +14 -4
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6558e12a3e762649ebacd215e2bb1caac71b1c6e6a4559068cf01aaf8d9e6d6a
4
- data.tar.gz: 3822d2a657ad366bad578c20261db62e9757ab0f4d004a0153d8026f9d86d253
3
+ metadata.gz: 2c5b4739556a960feae63b3085d755ea3c5b91fc4f8383f37e49d8a0dc4fc47b
4
+ data.tar.gz: b2956d94f0aac7aff9faf05df00e4ebbfbbb3105fbc629b75ec0ab3da66814ca
5
5
  SHA512:
6
- metadata.gz: 34e1c8f4f354fe3077a64e17d5150c60a7bd0716409b2eb7b2fc6a7e206056020c2d2d362ea3f27cc85a754eac32c5450d33507c0f2fd9abc34b173c892e1a74
7
- data.tar.gz: dac3916a294ff24517d7650b1a16fca6b2707064903d5380c721f40ca1e22bbc0840a037a6f6d67cb4b871f83359b6a3982dcf049af4231a497d7601e19b404f
6
+ metadata.gz: 8db76adc1b38de212357768348639cc6707a9fc62239719a8def8d7fbbb1fd985c9a9096089a4753ce0a79974ad728179e2d9d334da2e591b7dac58c9f9ccecc
7
+ data.tar.gz: 8229f627f8f831aec1e1a6355a32e79cd574fbf4e9cce3de0707f50f9be46aabd87845441df64384fe43f6d624afb0ce5d6291e3558aca191203224b8b65cb82
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
@@ -4,7 +4,7 @@ module SafeFile
4
4
  @@safeDirs = Array.new
5
5
  @@allowPWD = true
6
6
 
7
- def open file
7
+ def self.open file
8
8
  file = file.gsub "~/", "#{ENV["HOME"]}/"
9
9
 
10
10
  if performCheck File.expand_path file
@@ -12,7 +12,7 @@ module SafeFile
12
12
  end
13
13
  end
14
14
 
15
- def read file
15
+ def self.read file
16
16
  file = file.gsub "~/", "#{ENV["HOME"]}/"
17
17
 
18
18
  if performCheck File.expand_path file
@@ -20,7 +20,7 @@ module SafeFile
20
20
  end
21
21
  end
22
22
 
23
- def write file, content
23
+ def self.write file, content
24
24
  file = file.gsub "~/", "#{ENV["HOME"]}/"
25
25
 
26
26
  if performCheck File.expand_path file
@@ -28,7 +28,17 @@ module SafeFile
28
28
  end
29
29
  end
30
30
 
31
- def safe
31
+ def self.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
+
41
+ def self.safe
32
42
  def append dir
33
43
  dir = dir.gsub "~/", "#{ENV["HOME"]}/"
34
44
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: SafeFile
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sky.Bit
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  requirements: []
54
- rubygems_version: 4.0.11
54
+ rubygems_version: 4.0.16
55
55
  specification_version: 4
56
56
  summary: Strict file access library for Ruby
57
57
  test_files: []