wikk_configuration 0.1.2 → 0.1.6

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
- SHA1:
3
- metadata.gz: 4487d7e6c0dd986e50ea7a8350b1b7acd94c3edd
4
- data.tar.gz: 7f14ad1c249a25ff06ee1ee8195bcde18db12262
2
+ SHA256:
3
+ metadata.gz: 76677da536b759d7852a22e510b35371571545dde7d26d01785cc5bd104579b5
4
+ data.tar.gz: 2f452902d13f9f06eda30b692bfe28524ef0daf353d6d3f9400d62db3b451491
5
5
  SHA512:
6
- metadata.gz: 9019fb2bc80c67ed5a4bcb16acc76840485062cd9150c3be64c1fb43571a5584d7242858413086c3a197dd91c14a1abab9490068de18ef380494a89667489315
7
- data.tar.gz: 98fba6d08a695bd77debc1cf6ed92ebb2ecbf134c636fe7ad339d11a14e96b38778cb8a1663a15a1543b507ac04eb5c74f3232230f2384af92e7757bd8445b59
6
+ metadata.gz: 99ec94a85ee398d27c15e78ba53a937be0f7ecb6e3487a008896ea287255e932b4ee281bbdb9e122e01444f44d51d9a40675710056e581bcc8c589816b565007
7
+ data.tar.gz: f1e96dfa26194610f1fce966728d255a8297f3c5767914493bf6de939a422e30a55758e23015842dea0172e5debdf5ccfc2e2e674a8898d84f07c279432dd489
data/History.txt CHANGED
@@ -1,3 +1,44 @@
1
+ === 0.1.6 / 2026-11-29
2
+ robertburrowes Sun Nov 29 10:23:36 2026 +1300
3
+ wrong email
4
+ robertburrowes Sun Nov 29 10:13:40 2026 +1300
5
+ Update Manifest and Rakefile. Clean up file permissions
6
+ robertburrowes Sun Nov 29 09:30:52 2026 +1300
7
+ set JSON allow comments and symbolize. changed scripts to rv. added minitests
8
+ robertburrowes Mon Nov 23 18:12:51 2026 +1300
9
+ Allow comments in json. Fix missing arg in respond_to_missing?
10
+ robertburrowes Tue Apr 18 17:49:15 2023 +1200
11
+ chmod
12
+ robertburrowes Mon Jun 13 16:33:33 2022 +1200
13
+ Added respond_to_missing?
14
+ robertburrowes Mon Jun 13 15:06:51 2022 +1200
15
+ Merge branch 'master' of github.com:wikarekare/configuration
16
+ robertburrowes Mon Jun 13 13:51:50 2022 +1200
17
+ rubocop
18
+ robertburrowes Mon Jun 13 13:49:34 2022 +1200
19
+ Rubocop'd. Scripts to bash
20
+ robertburrowes Mon Jun 13 12:29:01 2022 +1200
21
+ rubocop
22
+ robertburrowes Sun Oct 25 21:54:07 2020 +1300
23
+ yard comment tidy up
24
+ robertburrowes Sun Oct 25 17:58:31 2020 +1300
25
+ added \n to last line of file
26
+ robertburrowes Sun Oct 25 17:45:55 2020 +1300
27
+ Chdir to cd as Mac doesn't look to have chdir in sh
28
+ robertburrowes Sun Oct 25 13:57:45 2020 +1300
29
+ #{PROJECT} Doc release 0.1.3
30
+ robertburrowes Mon Apr 13 23:04:30 2020 +1200
31
+ Add wikk_json dependency.
32
+ robertburrowes Mon Apr 13 23:04:10 2020 +1200
33
+ Up version for changes to tests
34
+ robertburrowes Mon Apr 13 23:03:55 2020 +1200
35
+ Quality test dir files with __dir__
36
+ robertburrowes Sat Aug 27 21:33:50 2016 +1200
37
+ Added a save method.
38
+ robertburrowes Sat Jun 25 09:10:47 2016 +1200
39
+ Added attr_accessor :pjson and allowed ruby hash instead of filename in initialize
40
+ robertburrowes Sun Jun 19 13:35:41 2016 +1200
41
+ updated to 1.1
1
42
  robertburrowes Sun Jun 19 13:33:36 2016 +1200
2
43
  encapsualted in module WIKK
3
44
  robertburrowes Sat Jun 18 17:11:10 2016 +1200
@@ -13,4 +54,4 @@ robertburrowes Sun Jan 10 19:33:55 2016 +1300
13
54
  robertburrowes Sun Jan 10 19:33:46 2016 +1300
14
55
  Reads json configuration and provides access to the configuration data
15
56
  Rob Burrowes Sun Jan 10 19:26:05 2016 +1300
16
- Initial commit
57
+ Initial commit
data/Manifest.txt CHANGED
@@ -3,5 +3,9 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  lib/wikk_configuration.rb
6
- test/manualtest.rb
7
- test/conf.json
6
+ test/conf/conf-with-comments.json
7
+ test/conf/conf.json
8
+ test/common_tests.rb
9
+ test/test_wikk_configuration_commented.rb
10
+ test/test_wikk_configuration_save.rb
11
+ test/test_wikk_configuration_uncommented.rb
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # wikk_configuration
2
2
 
3
- * http://rbur004.github.com/configuration/
4
- * Source https://github.com/wikarekare/configuration
5
- * Gem https://rubygems.org/gems/wikk_configuration
3
+ * Docs :: https://wikarekare.github.io/wikk_configuration/
4
+ * Source :: https://github.com/wikarekare/wikk_configuration
5
+ * Gem :: https://rubygems.org/gems/wikk_configuration
6
6
 
7
7
  ## DESCRIPTION:
8
8
 
data/Rakefile CHANGED
@@ -1,17 +1,30 @@
1
- #!/usr/local/bin/ruby
1
+ #!/usr/bin/env rv run ruby
2
2
  # -*- ruby -*-
3
3
 
4
- require 'rubygems'
4
+ # Hack to add back in has_rdoc until Hoe stops calling it.
5
+ # It got deprecated in Ruby 4.0, being obsolete for years
6
+ class Gem::Specification
7
+ def has_rdoc=(val); end
8
+ end
9
+ # hoe-yard is still calling exists?
10
+ unless File.respond_to?(:exists?)
11
+ File.singleton_class.alias_method :exists?, :exist?
12
+ end
5
13
  require 'hoe'
6
14
  Hoe.plugin :yard
7
15
 
8
- Hoe.spec 'wikk_configuration' do
16
+ Hoe.spec 'wikk_configuration' do
17
+ self.version = "0.1.6"
9
18
  self.readme_file = "README.md"
10
- self.developer( "Rob Burrowes","r.burrowes@auckland.ac.nz")
19
+ self.developer( "Rob Burrowes","rob@wikarekare.org")
20
+ self.homepage = 'https://github.com/wikarekare/wikk_configuration'
11
21
  remote_rdoc_dir = '' # Release to root
12
-
22
+
13
23
  self.yard_title = 'wikk_configuration'
14
24
  self.yard_options = ['--markup', 'markdown', '--protected']
25
+
26
+ self.dependency "wikk_json", "~> 0.1.0"
27
+ self.dependency "json", ">= 2.20.0"
15
28
  end
16
29
 
17
30
 
@@ -22,7 +35,7 @@ end
22
35
  #rake gem
23
36
 
24
37
  #create doc/
25
- #rake docs
38
+ #rake docs
26
39
  #In directory docs/
27
40
  #scp -r . rbur004@rubyforge.org:/var/www/gforge-projects/versioncheck/
28
41
 
@@ -1,56 +1,85 @@
1
1
  module WIKK
2
2
  require 'json'
3
+ require 'wikk_json' # gem version
3
4
 
4
- #Reads json configuration and provides access to the configuration data
5
- #as method calls.
6
- # @attr_accessor pjson [Hash] Raw hash created from reading the json file
5
+ # Reads json configuration and provides access to the configuration data
6
+ # as method calls.
7
+ # @attr_accessor pjson [Hash] Raw hash created from reading the json file
7
8
  class Configuration
8
- VERSION = '0.1.2'
9
-
9
+ VERSION = '0.1.6'
10
+
10
11
  attr_accessor :pjson
11
-
12
- #Creates an instance of Configuration from a json file
12
+
13
+ # Creates an instance of Configuration from a json file
14
+ #
13
15
  # @param [String|Hash] filename The Json file or a Ruby Hash, equivalent to the json
14
16
  # @return [Configuration]
15
- def initialize(filename="#{File.dirname(__FILE__)}/../conf/config.json")
16
- if filename.class == Hash
17
+ def initialize(filename)
18
+ if filename.instance_of?(Hash)
19
+ @filename = nil
17
20
  @pjson = filename
18
21
  else
22
+ @filename = filename
19
23
  json = File.read(filename)
20
- @pjson = JSON.parse(json)
24
+ @pjson = JSON.parse(json, allow_comments: true, symbolize_names: true)
21
25
  end
22
26
  end
23
-
24
- #Provides a test for a method named after a json configuration item exists
27
+
28
+ # Provides a test for a method named after a json configuration item exists
29
+ #
25
30
  # @note We need to define respond_to? as well as method_missing to satisfy tests in some libraries.
26
31
  # @param symbol [Symbol,String] The method name we need to test exists
27
32
  # @param include_private [Boolean] Extend the test to private methods
28
33
  # @return [Boolean] true if the method exists
29
34
  def respond_to?(symbol, include_private = false)
30
- (@pjson[s = symbol.to_s] != nil) || (s[-1,1] == '=' && @pjson[s[0..-2]] != nil) || super(symbol, include_private)
35
+ (@pjson[symbol] != nil) || (@pjson[symbol.to_s.gsub('=', '').to_sym] != nil) || super(symbol, include_private)
36
+ end
37
+
38
+ # Also need to respond to missing for calls we accept
39
+ def respond_to_missing?(symbol, include_private = false)
40
+ (@pjson[symbol] != nil) || (@pjson[symbol.to_s.gsub('=', '').to_sym] != nil) || super(symbol, include_private)
41
+ end
42
+
43
+ def [](key)
44
+ @pjson[key.to_sym]
31
45
  end
32
46
 
33
- #Default handler to map json configuration names to method names
47
+ def []=(key, value)
48
+ @pjson[key.to_sym] = value
49
+ end
50
+
51
+ # Default handler to map json configuration names to method names
52
+ #
34
53
  # @note Be aware of the possibility of name conflicts between built in class methods an configuration items defined in the json file)
35
54
  # @param symbol [symbol,String] The method name that maps to a json configuration item
36
55
  # @param args [Array] Not used, but would hold arguments to the method call. Should be zero length for our methods.
37
- # @param block [Block] Not used, but would be a code block supplied to the method.
56
+ # @param block [Block] Not used, but would be a code block supplied to the method.
38
57
  # @return [Object] the data associated with the json name, (hence method name) in the configuration file.
39
- def method_missing(symbol , *args, &block)
40
- s = symbol.to_s
41
- if @pjson[s] != nil
42
- return @pjson[s]
43
- elsif s[-1,1] == "="
44
- @pjson[s[0..-2]] = args[0]
58
+ def method_missing(symbol, *args, &block)
59
+ if @pjson[symbol.to_sym] != nil
60
+ return @pjson[symbol.to_sym]
61
+ elsif @pjson[(s = symbol.to_s.gsub('=', '').to_sym) ]
62
+ @pjson[s] = args[0]
45
63
  else
46
64
  super
47
- end
65
+ end
48
66
  end
49
-
67
+
68
+ # Write Json config file. Either over the original, or a new file.
69
+ #
70
+ # @param filename [String] overrides @filename, if creating a new file.
71
+ def save(filename = nil)
72
+ filename ||= @filename
73
+ if filename != nil
74
+ File.write(filename, @pjson.to_j)
75
+ end
76
+ end
77
+
78
+ # Config to string
79
+ #
50
80
  # @return [String] the configuration
51
81
  def to_s
52
82
  @pjson.to_s
53
83
  end
54
-
55
84
  end
56
85
  end
@@ -0,0 +1,65 @@
1
+ module CommonTests
2
+ # Test accessor methods exist
3
+ [ :base_directory, :hello, :world, :a_boolean, :a_string, :a_numeric, :deep, :deeper ].each do |m|
4
+ define_method("test_#{m.name}") do
5
+ assert_respond_to @config_loaded, m
6
+ end
7
+ end
8
+
9
+ # Test the setter methods exist
10
+ [ :base_directory=, :hello=, :world=, :a_boolean=, :a_string=, :a_numeric=, :deep=, :deeper= ].each do |m|
11
+ define_method("test_#{m.name}") do
12
+ assert_respond_to @config_loaded, m
13
+ end
14
+ end
15
+
16
+ # Test what we loaded is the same as the test data
17
+ [ :base_directory, :hello, :world, :a_boolean, :a_string, :a_numeric, :deep, :deeper ].each do |m|
18
+ define_method("test_accessor_#{m.name}") do
19
+ assert_equal @config_original[m], @config_loaded.send(m)
20
+ end
21
+ end
22
+
23
+ # Test classes are correct
24
+ [ :base_directory, :hello, :world, :a_boolean, :a_string, :a_numeric, :deep, :deeper ].each do |m|
25
+ define_method("test_class_#{m.name}") do
26
+ assert_instance_of @config_original[m].class, @config_loaded.send(m)
27
+ end
28
+ end
29
+
30
+ def test_set_base_directory
31
+ # Test a change to a loaded string
32
+ new_directory = '/somewhere/else'
33
+ @config_loaded.base_directory = new_directory
34
+ assert_equal new_directory, @config_loaded.base_directory
35
+ end
36
+
37
+ def test_set_boolean
38
+ # Test a change to a loaded boolean
39
+ new_boolean = !@config_original[:a_boolean]
40
+ @config_loaded.a_boolean = new_boolean
41
+ assert_equal new_boolean, @config_loaded.a_boolean
42
+ end
43
+
44
+ def test_set_numeric
45
+ # Test a change to a loaded a numeric
46
+ new_numeric = @config_original[:a_numeric] + 101
47
+ @config_loaded.a_numeric = new_numeric
48
+ assert_equal new_numeric, @config_loaded.a_numeric
49
+ end
50
+
51
+ private def base_config
52
+ # The json we load should produce this.
53
+ original_config = {
54
+ base_directory: '/usr/local/random',
55
+ hello: [ 0, 1, 2, 3, 4 ],
56
+ world: { '0': 0, '1': 1, '2': 2 },
57
+ a_boolean: true,
58
+ a_string: 'string',
59
+ a_numeric: 1.2345,
60
+ deep: { array: [ 0, 1, 2, 3, 4 ], hash: { '0': 0, '1': 1, '2': 2 } },
61
+ deeper: { hash: { array: [ 0, 1, 2, 3, 4 ] } }
62
+ }
63
+ return Marshal.load(Marshal.dump(original_config))
64
+ end
65
+ end
@@ -0,0 +1,12 @@
1
+ // Config file starts with a comment line
2
+ { // Have a comment after the {
3
+ "base_directory": "/usr/local/random",
4
+ "hello": [ 0, 1, 2, 3 , 4 ], // Have a comment on a line
5
+ "world": { "0": 0, "1": 1, "2": 2 },
6
+ "a_boolean": true,
7
+ "a_string": "string",
8
+ "a_numeric": 1.2345,
9
+ "deep": { "array": [ 0, 1, 2, 3 , 4 ], "hash": { "0": 0, "1": 1, "2": 2 } },
10
+ "deeper": { "hash": { "array": [ 0, 1, 2, 3 , 4 ] } }
11
+ } // Have a comment after the }
12
+ // Have a trailing comment
@@ -2,9 +2,9 @@
2
2
  "base_directory": "/usr/local/random",
3
3
  "hello": [ 0, 1, 2, 3 , 4 ],
4
4
  "world": { "0": 0, "1": 1, "2": 2 },
5
- "boolean": true,
6
- "string": "string",
7
- "numeric": 1.2345,
5
+ "a_boolean": true,
6
+ "a_string": "string",
7
+ "a_numeric": 1.2345,
8
8
  "deep": { "array": [ 0, 1, 2, 3 , 4 ], "hash": { "0": 0, "1": 1, "2": 2 } },
9
9
  "deeper": { "hash": { "array": [ 0, 1, 2, 3 , 4 ] } }
10
- }
10
+ }
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env rv run ruby
2
+ require_relative '../lib/wikk_configuration.rb' # For preinstall testing
3
+ # require 'wikk_configuration.rb' #For post install testing
4
+
5
+ require "minitest/autorun"
6
+ require_relative 'common_tests.rb'
7
+
8
+ class TestWikkConfigurationCommented < Minitest::Test
9
+ include CommonTests
10
+
11
+ def setup
12
+ @config_original = base_config
13
+ @config_loaded = WIKK::Configuration.new("#{__dir__}/conf/conf-with-comments.json")
14
+ end
15
+
16
+ def teardown
17
+ # Nothing to do
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env rv run ruby
2
+ require_relative '../lib/wikk_configuration.rb' # For preinstall testing
3
+ # require 'wikk_configuration.rb' #For post install testing
4
+
5
+ require "minitest/autorun"
6
+ require_relative 'common_tests.rb'
7
+
8
+ class TestWikkConfigurationSave < Minitest::Test
9
+ include CommonTests
10
+
11
+ # Create a config from the base_config
12
+ # Save it to a file
13
+ # Reload the file
14
+ # Test to see if it matches the original base_config
15
+ def setup
16
+ @config_original = base_config
17
+ new_config = WIKK::Configuration.new(base_config)
18
+ test_config_filename = "#{__dir__}/conf/conf_generated.out"
19
+ new_config.save(test_config_filename)
20
+ @config_loaded = WIKK::Configuration.new(test_config_filename)
21
+ end
22
+
23
+ def teardown
24
+ # Nothing to do
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env rv run ruby
2
+ require_relative '../lib/wikk_configuration.rb' # For preinstall testing
3
+ # require 'wikk_configuration.rb' #For post install testing
4
+
5
+ require "minitest/autorun"
6
+ require_relative 'common_tests.rb'
7
+
8
+ class TestWikkConfigurationUncommented < Minitest::Test
9
+ include CommonTests
10
+
11
+ def setup
12
+ @config_original = base_config
13
+ @config_loaded = WIKK::Configuration.new("#{__dir__}/conf/conf.json")
14
+ end
15
+
16
+ def teardown
17
+ # Nothing to do
18
+ end
19
+ end
metadata CHANGED
@@ -1,52 +1,82 @@
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.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Burrowes
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2016-06-24 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: wikk_json
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 0.1.0
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: 0.1.0
26
+ - !ruby/object:Gem::Dependency
27
+ name: json
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.20.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 2.20.0
13
40
  - !ruby/object:Gem::Dependency
14
41
  name: hoe-yard
15
42
  requirement: !ruby/object:Gem::Requirement
16
43
  requirements:
17
44
  - - ">="
18
45
  - !ruby/object:Gem::Version
19
- version: 0.1.2
46
+ version: 0.1.3
20
47
  type: :development
21
48
  prerelease: false
22
49
  version_requirements: !ruby/object:Gem::Requirement
23
50
  requirements:
24
51
  - - ">="
25
52
  - !ruby/object:Gem::Version
26
- version: 0.1.2
53
+ version: 0.1.3
27
54
  - !ruby/object:Gem::Dependency
28
55
  name: hoe
29
56
  requirement: !ruby/object:Gem::Requirement
30
57
  requirements:
31
58
  - - "~>"
32
59
  - !ruby/object:Gem::Version
33
- version: '3.15'
60
+ version: '4.7'
34
61
  type: :development
35
62
  prerelease: false
36
63
  version_requirements: !ruby/object:Gem::Requirement
37
64
  requirements:
38
65
  - - "~>"
39
66
  - !ruby/object:Gem::Version
40
- version: '3.15'
41
- description: Ruby class to read json configuration files, and present the top level
42
- values as method calls
67
+ version: '4.7'
68
+ description: |
69
+ Ruby class to read json configuration files, and present the top level values as method calls
70
+
71
+ ## Features/Problems:
72
+
73
+ ==== To Install:
43
74
  email:
44
- - r.burrowes@auckland.ac.nz
75
+ - rob@wikarekare.org
45
76
  executables: []
46
77
  extensions: []
47
78
  extra_rdoc_files:
48
79
  - History.txt
49
- - Manifest.txt
50
80
  - README.md
51
81
  files:
52
82
  - History.txt
@@ -54,13 +84,16 @@ files:
54
84
  - README.md
55
85
  - Rakefile
56
86
  - lib/wikk_configuration.rb
57
- - test/conf.json
58
- - test/manualtest.rb
59
- homepage: http://rbur004.github.com/configuration/
87
+ - test/common_tests.rb
88
+ - test/conf/conf-with-comments.json
89
+ - test/conf/conf.json
90
+ - test/test_wikk_configuration_commented.rb
91
+ - test/test_wikk_configuration_save.rb
92
+ - test/test_wikk_configuration_uncommented.rb
93
+ homepage: https://github.com/wikarekare/wikk_configuration
60
94
  licenses:
61
95
  - MIT
62
96
  metadata: {}
63
- post_install_message:
64
97
  rdoc_options:
65
98
  - "--markup"
66
99
  - markdown
@@ -81,10 +114,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
114
  - !ruby/object:Gem::Version
82
115
  version: '0'
83
116
  requirements: []
84
- rubyforge_project:
85
- rubygems_version: 2.5.1
86
- signing_key:
117
+ rubygems_version: 4.0.20
87
118
  specification_version: 4
88
- summary: Ruby class to read json configuration files, and present the top level values
89
- as method calls
119
+ summary: 'Ruby class to read json configuration files, and present the top level values
120
+ as method calls ## Features/Problems: ==== To Install:'
90
121
  test_files: []
data/test/manualtest.rb DELETED
@@ -1,75 +0,0 @@
1
- #!/usr/local/bin/ruby
2
- require_relative '../lib/wikk_configuration.rb' #For preinstall testing
3
- #require 'wikk_configuration.rb' #For post install testing
4
- require 'pp'
5
- include WIKK
6
-
7
- #Provides a self test of this class, by reading the test configuration file.
8
- # and attempting to access configuration items as methods.
9
- def test(config_file)
10
- puts "creating config from '#{config_file}'"
11
- config = Configuration.new(config_file)
12
-
13
- puts "****** Dump config using to_s *********"
14
- pp config
15
- puts
16
- puts
17
- puts "******Should be there*********"
18
- puts "base_directories is defined? #{config.respond_to?(:base_directory)}"
19
- puts "base_directories= is defined? #{config.respond_to?(:base_directory=)}"
20
- puts "base_directories is: '#{config.base_directory}'"
21
- puts "******Should NOT be there*********"
22
- puts "not_there is defined? #{config.respond_to?(:not_there)}"
23
- puts "******Array*********"
24
- puts "hello is of class: #{config.hello.class}"
25
- puts "config.hello[0] => #{config.hello[0]}"
26
- puts "******Hash*********"
27
- puts "world is of class: #{config.world.class}"
28
- puts "config.world['1'] => #{config.world['1']}"
29
- puts "******Boolean*********"
30
- puts "boolean is of class: #{config.boolean.class}"
31
- puts "config.boolean => #{config.boolean}"
32
- puts "******String*********"
33
- puts "string is of class: #{config.string.class}"
34
- puts "config.string => #{config.string}"
35
- puts "******Numeric*********"
36
- puts "numeric is of class: #{config.numeric.class}"
37
- puts "config.numeric => #{config.numeric}"
38
- puts
39
- puts "******Alter Numeric value and fetch again*********"
40
- config.numeric = 1001
41
- puts "config.numeric => #{config.numeric}"
42
- puts config.pjson
43
- puts
44
- puts
45
- puts
46
- hash_source = { #Ruby equivalent of the json.
47
- "base_directory" => "/usr/local/random",
48
- "hello" => [ 0, 1, 2, 3 , 4 ],
49
- "world" => { "0" => 0, "1" => 1, "2" => 2 },
50
- "boolean" => true,
51
- "string" => "string",
52
- "numeric" => 1.2345,
53
- "deep" => { "array" => [ 0, 1, 2, 3 , 4 ], "hash" => { "0" => 0, "1" => 1, "2" => 2 } },
54
- "deeper" => { "hash" => { "array" => [ 0, 1, 2, 3 , 4 ] } }
55
- }
56
- puts "creating config from hash"
57
- config_hash_source = Configuration.new(hash_source)
58
- puts "****** Dump config using to_s *********"
59
- pp config
60
- puts "******Numeric from hashed source *********"
61
- puts "numeric is of class: #{config_hash_source.numeric.class}"
62
- puts "config_hash_source.numeric => #{config_hash_source.numeric}"
63
-
64
- end
65
-
66
- puts "Start"
67
- begin
68
- test('conf.json')
69
- rescue Exception => error
70
- puts "Error: error"
71
- end
72
- puts "End"
73
-
74
-
75
-