wikk_configuration 0.1.0 → 0.1.1
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/History.txt +8 -0
- data/README.md +23 -1
- data/Rakefile +1 -0
- data/lib/wikk_configuration.rb +40 -38
- data/test/conf.json +3 -1
- data/test/manualtest.rb +3 -2
- 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: 787c6bbe19f13b0cf0408094dcee74c3e294be25
|
4
|
+
data.tar.gz: 7ef971f09fbcc75da50230d76b554fa26842465e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 440bc4b32e6e439db0c608b04272229a3f7b6f89a50815b2d8a9eda0c9bdc22e4a4af2ad0603acbc493eeb8166147dcbd04f746f2c3df1ff46b62abdfca683bf
|
7
|
+
data.tar.gz: 5a3b08024476a983125783e85e89cb0bc7419066650a1ef5bd668da2594dd4447bf887312f8ea2cea26d328b984d60b0e9017a8cd810453c3ec404dcd8dc2fca
|
data/History.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
robertburrowes Sun Jun 19 13:33:36 2016 +1200
|
2
|
+
encapsualted in module WIKK
|
3
|
+
robertburrowes Sat Jun 18 17:11:10 2016 +1200
|
4
|
+
Added 2nd and 3rd level examples.
|
5
|
+
robertburrowes Sat Jun 18 17:10:42 2016 +1200
|
6
|
+
Better Synopsis
|
7
|
+
robertburrowes Sat Jun 18 16:57:38 2016 +1200
|
8
|
+
Turned configuration into wikk_configuration gem
|
1
9
|
robertburrowes Sun May 8 22:43:56 2016 +1200
|
2
10
|
Changed makefile into install.sh
|
3
11
|
robertburrowes Sun Jan 10 19:33:55 2016 +1300
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# wikk_configuration
|
2
2
|
|
3
3
|
* http://rbur004.github.com/configuration/
|
4
4
|
* Source https://github.com/wikarekare/configuration
|
@@ -15,6 +15,28 @@ Ruby class to read json configuration files, and present the top level values as
|
|
15
15
|
## SYNOPSIS:
|
16
16
|
|
17
17
|
require 'configuration'
|
18
|
+
include WIKK
|
19
|
+
@config = Configuration.new(config_file) #Where config_file is a json file.
|
20
|
+
|
21
|
+
eg. config_file with json types
|
22
|
+
{
|
23
|
+
"array": [ 0, 1, 2, 3 , 4 ],
|
24
|
+
"hash": { "0": 0, "1": 1, "2": 2 },
|
25
|
+
"boolean": true,
|
26
|
+
"string": "string",
|
27
|
+
"numeric": 1.2345
|
28
|
+
}
|
29
|
+
|
30
|
+
Results in Ruby variables of classes:
|
31
|
+
|
32
|
+
@config.array.class => Array
|
33
|
+
@config.hash.class => Hash
|
34
|
+
@config.boolean.class => TrueClass
|
35
|
+
@config.string.class => String
|
36
|
+
@config.numeric.class => Float
|
37
|
+
|
38
|
+
Only top level hash names are converted to methods.
|
39
|
+
Be careful not to use a hash key that would conflict with a local method in Class.
|
18
40
|
|
19
41
|
## REQUIREMENTS:
|
20
42
|
|
data/Rakefile
CHANGED
data/lib/wikk_configuration.rb
CHANGED
@@ -1,45 +1,47 @@
|
|
1
|
-
|
1
|
+
module WIKK
|
2
|
+
require 'json'
|
2
3
|
|
3
|
-
#Reads json configuration and provides access to the configuration data
|
4
|
-
#as method calls.
|
5
|
-
class Configuration
|
6
|
-
|
4
|
+
#Reads json configuration and provides access to the configuration data
|
5
|
+
#as method calls.
|
6
|
+
class Configuration
|
7
|
+
VERSION = '0.1.1'
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
#Creates an instance of Configuration from a json file
|
10
|
+
# @param [String] filename The Json file
|
11
|
+
# @return [Configuration]
|
12
|
+
def initialize(filename="#{File.dirname(__FILE__)}/../conf/config.json")
|
13
|
+
json = File.read(filename)
|
14
|
+
@pjson = JSON.parse(json)
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
#Provides a test for a method named after a json configuration item exists
|
18
|
+
# @note We need to define respond_to? as well as method_missing to satisfy tests in some libraries.
|
19
|
+
# @param symbol [Symbol,String] The method name we need to test exists
|
20
|
+
# @param include_private [Boolean] Extend the test to private methods
|
21
|
+
# @return [Boolean] true if the method exists
|
22
|
+
def respond_to?(symbol, include_private = false)
|
23
|
+
(@pjson[symbol.to_s] != nil) || super(symbol, include_private)
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
26
|
+
#Default handler to map json configuration names to method names
|
27
|
+
# @note Be aware of the possibility of name conflicts between built in class methods an configuration items defined in the json file)
|
28
|
+
# @param symbol [symbol,String] The method name that maps to a json configuration item
|
29
|
+
# @param args [Array] Not used, but would hold arguments to the method call. Should be zero length for our methods.
|
30
|
+
# @param block [Block] Not used, but would be a code block supplied to the method.
|
31
|
+
# @return [Object] the data associated with the json name, (hence method name) in the configuration file.
|
32
|
+
def method_missing(symbol , *args, &block)
|
33
|
+
s = symbol.to_s
|
34
|
+
if @pjson[s] != nil
|
35
|
+
return @pjson[s]
|
36
|
+
else
|
37
|
+
super
|
38
|
+
end
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
# @return [String] the configuration
|
42
|
+
def to_s
|
43
|
+
@pjson.to_s
|
44
|
+
end
|
44
45
|
|
46
|
+
end
|
45
47
|
end
|
data/test/conf.json
CHANGED
data/test/manualtest.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/local/bin/ruby
|
2
|
-
|
3
|
-
require 'wikk_configuration.rb' #For post install testing
|
2
|
+
require_relative '../lib/wikk_configuration.rb' #For preinstall testing
|
3
|
+
#require 'wikk_configuration.rb' #For post install testing
|
4
4
|
require 'pp'
|
5
|
+
include WIKK
|
5
6
|
|
6
7
|
#Provides a self test of this class, by reading the test configuration file.
|
7
8
|
# and attempting to access configuration items as methods.
|
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.1
|
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-
|
11
|
+
date: 2016-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hoe-yard
|