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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/confrb.rb +10 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30725b1e35a0f6d3302899d61b5790b5924aa575856dfa64f1427f3dc7f6dfac
4
- data.tar.gz: c1add6c9c9d122dff3682caf0ed16631a968325db93c82ecdf0023cbb56ae220
3
+ metadata.gz: e345e91efad30f4fe4594b4b0b0e988308c65d9026b2de09b035cca1acaa451a
4
+ data.tar.gz: fd327ed9c9ca082c896610772c88190afcec7eaf9e9566b40a91d18f4c200d35
5
5
  SHA512:
6
- metadata.gz: d53d3c316ee9dbf06af8d9fdf95d39b62598cef369c3c9a3bceaa917c7ae508afd11bfa335b03651f48cb6801468f9a9dee30a2170aec6a04bc9d5edaca4bd5c
7
- data.tar.gz: 9acd96dd3bf750fb8f3b42ffff57d36c66fa030d9c5d4e78ad73366975b44f8cc7a9217345cd633085bed446da5f464d6dc286892c0276856c1119c51d22a9cc
6
+ metadata.gz: 8cea6e2b29b83d2b13f5cfff4dbbb5587537befee706d33eb17075d1ee8a8a260aaeb99d53ee864537de870e477396e99b869f1919cef10f389c0298dc259a1f
7
+ data.tar.gz: 37fdcfef81fce837ba2dc0f694d809ec57620d1089cea28a4b280b44c4a2abc4793d1e7d434c9c33d78ab9b4391daad614ff8b7c34d0b71749807b3cb33c63d7
@@ -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 = "\n" + 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, "\n" + content, mode: "a")
150
+ IO.write(cfgpath, content, mode: "a")
146
151
  else
147
- IO.write(cfgpath, "\n" + content, mode: "a")
152
+ IO.write(cfgpath, content, mode: "a")
148
153
  end
149
154
  end
150
155
  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: '1.9'
4
+ version: '2.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gurjus Bhasin