confrb 0.7alpha → 0.8alpha
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/lib/confrb.rb +28 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 570aff3871d003b0724d94bc36327290c57e1472a0624a6186ed211611f10a15
|
4
|
+
data.tar.gz: 616dd3d6e98cf7ffef553b49ffb6787f0fd1c3402e35252f3ee05914032d79f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6aee7a4ac1ffbb6ea56b2c52c054d1d928300564bd189133319da419d07c3f6d74a83c76017dac52802e54273034af7295855e1919aeb3061be1cb6ba6c90eb9
|
7
|
+
data.tar.gz: b054b40ee7f45dcd862a658e8b776a6ec9b66625f18750ba95058c8ca1f710530bfaed76fcecc473654e8fad14702e1b727b2dafeeaf5b27025fe6d30b09b6d2
|
data/lib/confrb.rb
CHANGED
@@ -1,16 +1,29 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require 'json'
|
3
|
+
require 'yaml'
|
2
4
|
module BasicCfrb
|
3
|
-
extend self
|
5
|
+
extend self # Make sure this extends self so it can be used as a module!
|
6
|
+
|
4
7
|
def setup(name)
|
5
8
|
dotname = "." + name
|
6
9
|
FileUtils.mkdir_p(dotname)
|
7
10
|
end
|
8
11
|
|
9
|
-
def mkcfg(dir, cfgname, content)
|
12
|
+
def mkcfg(dir, cfgname, content, opts={})
|
13
|
+
as_json=opts.fetch(:json, false)
|
14
|
+
as_yaml=opts.fetch(:yaml, false)
|
10
15
|
dotdir = "." + dir
|
11
16
|
cfgpath = File.join(dotdir, cfgname)
|
12
17
|
FileUtils.touch(cfgpath)
|
13
|
-
|
18
|
+
if as_json == true
|
19
|
+
content = content.to_json
|
20
|
+
File.write(cfgpath, content)
|
21
|
+
elsif as_yaml == true
|
22
|
+
content = content.to_yaml
|
23
|
+
File.write(cfgpath, content)
|
24
|
+
else
|
25
|
+
File.write(cfgpath, content)
|
26
|
+
end
|
14
27
|
end
|
15
28
|
|
16
29
|
def mknested(dir, nesteddir)
|
@@ -18,9 +31,18 @@ module BasicCfrb
|
|
18
31
|
FileUtils.mkdir_p(File.join(dotdir, nesteddir))
|
19
32
|
end
|
20
33
|
|
21
|
-
def readcfg(dir, cfgname)
|
34
|
+
def readcfg(dir, cfgname, opts={})
|
22
35
|
dotdir = "." + dir
|
23
|
-
|
24
|
-
|
36
|
+
as_json=opts.fetch(:json, false)
|
37
|
+
as_yaml=opts.fetch(:yaml, false)
|
38
|
+
if as_json == true
|
39
|
+
content = File.read(File.join(dotdir, cfgname)).to_json
|
40
|
+
return content
|
41
|
+
elsif as_yaml == true
|
42
|
+
content = File.read(File.join(dotdir, cfgname)).yaml
|
43
|
+
return content
|
44
|
+
else
|
45
|
+
File.read(File.join(dotdir, cfgname))
|
46
|
+
end
|
25
47
|
end
|
26
48
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: confrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8alpha
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gurjus Bhasin
|
@@ -12,7 +12,7 @@ date: 2019-12-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
13
13
|
description: A Ruby Gem which allows you to store configuration files using hidden
|
14
14
|
directories. Plaintext, unencrypted. Useful for simple text adventure games, etc.
|
15
|
-
Docs at https://gitlab.com/Gsbhasin84/confrb
|
15
|
+
Docs and examples at https://gitlab.com/Gsbhasin84/confrb
|
16
16
|
email: gsbhasin84@gmail.com
|
17
17
|
executables: []
|
18
18
|
extensions: []
|