confrb 1.9 → 2.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/lib/confrb.rb +10 -5
- 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: e345e91efad30f4fe4594b4b0b0e988308c65d9026b2de09b035cca1acaa451a
|
4
|
+
data.tar.gz: fd327ed9c9ca082c896610772c88190afcec7eaf9e9566b40a91d18f4c200d35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cea6e2b29b83d2b13f5cfff4dbbb5587537befee706d33eb17075d1ee8a8a260aaeb99d53ee864537de870e477396e99b869f1919cef10f389c0298dc259a1f
|
7
|
+
data.tar.gz: 37fdcfef81fce837ba2dc0f694d809ec57620d1089cea28a4b280b44c4a2abc4793d1e7d434c9c33d78ab9b4391daad614ff8b7c34d0b71749807b3cb33c63d7
|
data/lib/confrb.rb
CHANGED
@@ -38,10 +38,13 @@ class Confrb
|
|
38
38
|
# as JSON Default: false
|
39
39
|
# @option opts [boolean] :yaml If true, serialize content
|
40
40
|
# as YAML Default: false (json: true takes precedence)
|
41
|
+
# @option opts [boolean] :newline If true, prepends a newline to the beginning of the content. Default: false
|
41
42
|
# @return path to configuration file created.
|
42
43
|
def mkcfg(cfgname, content='', opts = {})
|
43
44
|
as_json = opts.fetch(:json, false)
|
44
45
|
as_yaml = opts.fetch(:yaml, false)
|
46
|
+
newline = opts.fetch(:newline, false)
|
47
|
+
content = "\n" + content if newline = true
|
45
48
|
dotdir = "." + @db
|
46
49
|
cfgpath = File.join(dotdir, cfgname)
|
47
50
|
FileUtils.touch(cfgpath)
|
@@ -121,7 +124,7 @@ class Confrb
|
|
121
124
|
|
122
125
|
##
|
123
126
|
# Create/append to a config file and write data to it. Can
|
124
|
-
# serialize data as yaml or json, or write a string.
|
127
|
+
# serialize data as yaml or json, or write a string. Writes a newline at the beginning.
|
125
128
|
# @param [String] cfgname Name of config file to write to
|
126
129
|
# @param [String] content The content to write, defaults to an empty string.
|
127
130
|
# @param [Hash] opts Optional param hash
|
@@ -129,22 +132,24 @@ class Confrb
|
|
129
132
|
# as JSON Default: false
|
130
133
|
# @option opts [boolean] :yaml If true, serialize content
|
131
134
|
# as YAML Default: false (json: true takes precedence)
|
135
|
+
# @option opts [boolean] :newline If true, prepend a newline to content. Default: true
|
132
136
|
# @return path to configuration file created.
|
133
137
|
def writecfg(cfgname, content, opts = {})
|
134
138
|
as_json = opts.fetch(:json, false)
|
135
139
|
as_yaml = opts.fetch(:yaml, false)
|
140
|
+
newline = opts.fetch(:newline, true)
|
136
141
|
dotdir = "." + @db
|
137
142
|
cfgpath = File.join(dotdir, cfgname)
|
138
143
|
FileUtils.touch(cfgpath)
|
144
|
+
content = "\n" + content if newline == true
|
139
145
|
if as_json == true
|
140
146
|
content = content.to_json
|
141
|
-
content
|
142
|
-
IO.write(cfgpath, "\n" + content, mode: "a")
|
147
|
+
IO.write(cfgpath, content, mode: "a")
|
143
148
|
elsif as_yaml == true
|
144
149
|
content = content.to_yaml
|
145
|
-
IO.write(cfgpath,
|
150
|
+
IO.write(cfgpath, content, mode: "a")
|
146
151
|
else
|
147
|
-
IO.write(cfgpath,
|
152
|
+
IO.write(cfgpath, content, mode: "a")
|
148
153
|
end
|
149
154
|
end
|
150
155
|
end
|