wikk_configuration 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4487d7e6c0dd986e50ea7a8350b1b7acd94c3edd
4
- data.tar.gz: 7f14ad1c249a25ff06ee1ee8195bcde18db12262
3
+ metadata.gz: c02507178052cf2a3e9e9da1fc11ca22f18e7dcb
4
+ data.tar.gz: c286f12e6fd69f80da96c69764458ee2d9fe3ede
5
5
  SHA512:
6
- metadata.gz: 9019fb2bc80c67ed5a4bcb16acc76840485062cd9150c3be64c1fb43571a5584d7242858413086c3a197dd91c14a1abab9490068de18ef380494a89667489315
7
- data.tar.gz: 98fba6d08a695bd77debc1cf6ed92ebb2ecbf134c636fe7ad339d11a14e96b38778cb8a1663a15a1543b507ac04eb5c74f3232230f2384af92e7757bd8445b59
6
+ metadata.gz: a64b7ab7de8d9dfa1fc0459c6a52dbeb037323340a9442e5153465cd3f914f38412c8b567cc5807c1d8a3d4be3961e606f258941fb586b291a5c8fb93d26b037
7
+ data.tar.gz: 6f31f3a8921c01537a89c6d0c38e2d958f6d6884be02af6f3c63a899b57686457d793deecca215fb178b565dc936fb70d4b17dc1d09f9a8bf2cc1a97c8eb3c62
@@ -1,21 +1,24 @@
1
1
  module WIKK
2
2
  require 'json'
3
+ require "wikk_json" #gem version
3
4
 
4
5
  #Reads json configuration and provides access to the configuration data
5
6
  #as method calls.
6
7
  # @attr_accessor pjson [Hash] Raw hash created from reading the json file
7
8
  class Configuration
8
- VERSION = '0.1.2'
9
+ VERSION = '0.1.3'
9
10
 
10
11
  attr_accessor :pjson
11
12
 
12
13
  #Creates an instance of Configuration from a json file
13
14
  # @param [String|Hash] filename The Json file or a Ruby Hash, equivalent to the json
14
15
  # @return [Configuration]
15
- def initialize(filename="#{File.dirname(__FILE__)}/../conf/config.json")
16
+ def initialize(filename="#{File.dirname(__FILE__)}/../conf/config.json")
16
17
  if filename.class == Hash
18
+ @filename = nil
17
19
  @pjson = filename
18
20
  else
21
+ @filename = filename
19
22
  json = File.read(filename)
20
23
  @pjson = JSON.parse(json)
21
24
  end
@@ -46,6 +49,17 @@ module WIKK
46
49
  super
47
50
  end
48
51
  end
52
+
53
+ #Write Json config file. Either over the original, or a new file.
54
+ # @param filename [String] overrides @filename, if creating a new file.
55
+ def save(filename = nil)
56
+ filename ||= @filename
57
+ if filename != nil
58
+ File.open(filename , "w+") do |fd|
59
+ fd.write(@pjson.to_j)
60
+ end
61
+ end
62
+ end
49
63
 
50
64
  # @return [String] the configuration
51
65
  def to_s
data/test/manualtest.rb CHANGED
@@ -63,12 +63,33 @@ def test(config_file)
63
63
 
64
64
  end
65
65
 
66
+ def test_save(config_file)
67
+ puts "test_save: creating config from '#{config_file}'"
68
+ config = Configuration.new(config_file)
69
+ config.save('conf_out')
70
+ end
71
+
66
72
  puts "Start"
67
73
  begin
68
74
  test('conf.json')
69
75
  rescue Exception => error
70
76
  puts "Error: error"
71
77
  end
78
+ begin
79
+ test_json = {
80
+ "base_directory": "/usr/local/random",
81
+ "hello": [ 0, 1, 2, 3 , 4 ],
82
+ "world": { "0": 0, "1": 1, "2": 2 },
83
+ "boolean": true,
84
+ "string": "string",
85
+ "numeric": 1.2345,
86
+ "deep": { "array": [ 0, 1, 2, 3 , 4 ], "hash": { "0": 0, "1": 1, "2": 2 } },
87
+ "deeper": { "hash": { "array": [ 0, 1, 2, 3 , 4 ] } }
88
+ }
89
+ test_save(test_json)
90
+ rescue Exception => error
91
+ puts "Error: error"
92
+ end
72
93
  puts "End"
73
94
 
74
95
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikk_configuration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Burrowes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-24 00:00:00.000000000 Z
11
+ date: 2016-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hoe-yard