wikk_configuration 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wikk_configuration.rb +16 -2
- data/test/manualtest.rb +21 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c02507178052cf2a3e9e9da1fc11ca22f18e7dcb
|
4
|
+
data.tar.gz: c286f12e6fd69f80da96c69764458ee2d9fe3ede
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a64b7ab7de8d9dfa1fc0459c6a52dbeb037323340a9442e5153465cd3f914f38412c8b567cc5807c1d8a3d4be3961e606f258941fb586b291a5c8fb93d26b037
|
7
|
+
data.tar.gz: 6f31f3a8921c01537a89c6d0c38e2d958f6d6884be02af6f3c63a899b57686457d793deecca215fb178b565dc936fb70d4b17dc1d09f9a8bf2cc1a97c8eb3c62
|
data/lib/wikk_configuration.rb
CHANGED
@@ -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.
|
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.
|
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-
|
11
|
+
date: 2016-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hoe-yard
|