confrb 1.3 → 1.4
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 +32 -1
- 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: 39cea4513710fa1d095a863d9b2b189909ed920d794f38c6609d7cfba3b89cac
|
4
|
+
data.tar.gz: 1bc7b1543c1c93a3e779f2aec41a3293b805f1d939cd7225c181ad15cb08214b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87cc3cb961ddadbc6970d88d1516d0f86a50467ccc4ba178f2d24614014eb4492dbd16ff61f00bb46e5e014efa169a8a2d3f41baf4e64357c47d78e53fae9f94
|
7
|
+
data.tar.gz: eab6f9b6fd989ad5fea2f77b812e64d9d5d203be3b42f3ce001c18b9b7d85fcc72bba281a3514993e0dd229434e28fa719719026ce1d8df26f1835d3142ac96c
|
data/lib/confrb.rb
CHANGED
@@ -29,7 +29,7 @@ module BasicCfrb
|
|
29
29
|
# false
|
30
30
|
# @option opts [boolean] :yaml If true, serialize content
|
31
31
|
# as YAML (ignored if content isn't a hash) Default #
|
32
|
-
# false (json: true takes precedence
|
32
|
+
# false (json: true takes precedence)
|
33
33
|
# @return path to configuration file created.
|
34
34
|
def mkcfg(dir, cfgname, content, opts={})
|
35
35
|
as_json=opts.fetch(:json, false) && content.is_a?(Hash)
|
@@ -117,4 +117,35 @@ module BasicCfrb
|
|
117
117
|
dotdir = File.join("." + dir, nested)
|
118
118
|
FileUtils.rm_rf(dotdir)
|
119
119
|
end
|
120
|
+
|
121
|
+
##
|
122
|
+
# Create/append to a config file. Can
|
123
|
+
# serialize a hash as yaml or json, or write a string
|
124
|
+
# @param [String] dir Path to store config file in
|
125
|
+
# @param [String] cfgname Name of config file to write to
|
126
|
+
# @param [Hash] opts Optional param hash
|
127
|
+
# @option opts [boolean] :json If true, serialize content
|
128
|
+
# as JSON (ignored if content isn't a hash) Default #
|
129
|
+
# false
|
130
|
+
# @option opts [boolean] :yaml If true, serialize content
|
131
|
+
# as YAML (ignored if content isn't a hash) Default #
|
132
|
+
# false (json: true takes precedence)
|
133
|
+
# @return path to configuration file created.
|
134
|
+
def writecfg(dir, cfgname, content, opts = {})
|
135
|
+
as_json = opts.fetch(:json, false) && content.is_a?(Hash)
|
136
|
+
as_yaml = opts.fetch(:yaml, false) && content.is_a?(Hash)
|
137
|
+
dotdir = "." + dir
|
138
|
+
cfgpath = File.join(dotdir, cfgname)
|
139
|
+
FileUtils.touch(cfgpath)
|
140
|
+
if as_json == true
|
141
|
+
content = content.to_json
|
142
|
+
content = "\n" + content
|
143
|
+
IO.write(cfgpath, "\n" + content, mode: 'a')
|
144
|
+
elsif as_yaml == true
|
145
|
+
content = content.to_yaml
|
146
|
+
IO.write(cfgpath, "\n" + content, mode: 'a')
|
147
|
+
else
|
148
|
+
IO.write(cfgpath, "\n" + content, mode: 'a')
|
149
|
+
end
|
150
|
+
end
|
120
151
|
end
|