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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/confrb.rb +32 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59dcfb3a452a7606bb6e576974c1737e5045937ccadacdc5c118877834f30952
4
- data.tar.gz: 32c66d6bf4fa2cddc422c7b8ed0c5a3b8de46fdd97ae6acee8183a528bce6515
3
+ metadata.gz: 39cea4513710fa1d095a863d9b2b189909ed920d794f38c6609d7cfba3b89cac
4
+ data.tar.gz: 1bc7b1543c1c93a3e779f2aec41a3293b805f1d939cd7225c181ad15cb08214b
5
5
  SHA512:
6
- metadata.gz: 3440bb1335052a4324c6444ae17c248880f30cda32846a10dbb0d87724e7676f86ef9b3cdafaf4f9ed88d2dc55c4f620abb9d2c498363926bd33c05884bfbb1e
7
- data.tar.gz: 951e5ac8ff096b37bed1aa9f49116f1d4ea77bcc019845106a1c3494212a8c97af1c7bbe4ab7219b13e7e9f43188d0b17a2bb35292be9ece89862c07443eeb6a
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
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.3'
4
+ version: '1.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gurjus Bhasin