wikk_configuration 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d42847eb805d60cdf0fb9ac2db0ab1f7a24c2a39
4
- data.tar.gz: 551238c64c629ffcf4c7fa3db80e25bf554de3e6
3
+ metadata.gz: 787c6bbe19f13b0cf0408094dcee74c3e294be25
4
+ data.tar.gz: 7ef971f09fbcc75da50230d76b554fa26842465e
5
5
  SHA512:
6
- metadata.gz: 6fd33de2da796b31db252c123ea34b65f507d63bf13ef45a216bada06d4cca7ed3cc9c8e8bc675f6c6384eb08abf50b4bfa939abb01f80a12d43072b04ed2b7e
7
- data.tar.gz: 428247fa5c65afdc61c1798b960416fd13f6b2cf5b5c01845e2f81d6dfa9390890640b1fdc7ed19290718536944b1316cc95dfd3cedbf4d59d1732485372735a
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
- # configuration
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
@@ -6,6 +6,7 @@ require 'hoe'
6
6
  Hoe.plugin :yard
7
7
 
8
8
  Hoe.spec 'wikk_configuration' do
9
+ self.readme_file = "README.md"
9
10
  self.developer( "Rob Burrowes","r.burrowes@auckland.ac.nz")
10
11
  remote_rdoc_dir = '' # Release to root
11
12
 
@@ -1,45 +1,47 @@
1
- require 'json'
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
- VERSION = '0.1.0'
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
- #Creates an instance of Configuration from a json file
9
- # @param [String] filename The Json file
10
- # @return [Configuration]
11
- def initialize(filename="#{File.dirname(__FILE__)}/../conf/config.json")
12
- json = File.read(filename)
13
- @pjson = JSON.parse(json)
14
- end
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
- #Provides a test for a method named after a json configuration item exists
17
- # @note We need to define respond_to? as well as method_missing to satisfy tests in some libraries.
18
- # @param symbol [Symbol,String] The method name we need to test exists
19
- # @param include_private [Boolean] Extend the test to private methods
20
- # @return [Boolean] true if the method exists
21
- def respond_to?(symbol, include_private = false)
22
- (@pjson[symbol.to_s] != nil) || super(symbol, include_private)
23
- end
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
- #Default handler to map json configuration names to method names
26
- # @note Be aware of the possibility of name conflicts between built in class methods an configuration items defined in the json file)
27
- # @param symbol [symbol,String] The method name that maps to a json configuration item
28
- # @param args [Array] Not used, but would hold arguments to the method call. Should be zero length for our methods.
29
- # @param block [Block] Not used, but would be a code block supplied to the method.
30
- # @return [Object] the data associated with the json name, (hence method name) in the configuration file.
31
- def method_missing(symbol , *args, &block)
32
- s = symbol.to_s
33
- if @pjson[s] != nil
34
- return @pjson[s]
35
- else
36
- super
37
- end
38
- end
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
- # @return [String] the configuration
41
- def to_s
42
- @pjson.to_s
43
- end
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
@@ -4,5 +4,7 @@
4
4
  "world": { "0": 0, "1": 1, "2": 2 },
5
5
  "boolean": true,
6
6
  "string": "string",
7
- "numeric": 1.2345
7
+ "numeric": 1.2345,
8
+ "deep": { "array": [ 0, 1, 2, 3 , 4 ], "hash": { "0": 0, "1": 1, "2": 2 } },
9
+ "deeper": { "hash": { "array": [ 0, 1, 2, 3 , 4 ] } }
8
10
  }
data/test/manualtest.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/local/bin/ruby
2
- #require_relative '../lib/wikk_configuration.rb' #For preinstall testing
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.0
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-18 00:00:00.000000000 Z
11
+ date: 2016-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hoe-yard