wikk_configuration 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d42847eb805d60cdf0fb9ac2db0ab1f7a24c2a39
4
+ data.tar.gz: 551238c64c629ffcf4c7fa3db80e25bf554de3e6
5
+ SHA512:
6
+ metadata.gz: 6fd33de2da796b31db252c123ea34b65f507d63bf13ef45a216bada06d4cca7ed3cc9c8e8bc675f6c6384eb08abf50b4bfa939abb01f80a12d43072b04ed2b7e
7
+ data.tar.gz: 428247fa5c65afdc61c1798b960416fd13f6b2cf5b5c01845e2f81d6dfa9390890640b1fdc7ed19290718536944b1316cc95dfd3cedbf4d59d1732485372735a
data/History.txt ADDED
@@ -0,0 +1,8 @@
1
+ robertburrowes Sun May 8 22:43:56 2016 +1200
2
+ Changed makefile into install.sh
3
+ robertburrowes Sun Jan 10 19:33:55 2016 +1300
4
+ Install only
5
+ robertburrowes Sun Jan 10 19:33:46 2016 +1300
6
+ Reads json configuration and provides access to the configuration data
7
+ Rob Burrowes Sun Jan 10 19:26:05 2016 +1300
8
+ Initial commit
data/Manifest.txt ADDED
@@ -0,0 +1,7 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ lib/wikk_configuration.rb
6
+ test/manualtest.rb
7
+ test/conf.json
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # configuration
2
+
3
+ * http://rbur004.github.com/configuration/
4
+ * Source https://github.com/wikarekare/configuration
5
+ * Gem https://rubygems.org/gems/wikk_configuration
6
+
7
+ ## DESCRIPTION:
8
+
9
+ Ruby class to read json configuration files, and present the top level values as method calls
10
+
11
+ ## FEATURES/PROBLEMS:
12
+
13
+
14
+
15
+ ## SYNOPSIS:
16
+
17
+ require 'configuration'
18
+
19
+ ## REQUIREMENTS:
20
+
21
+
22
+ ## INSTALL:
23
+
24
+ * sudo gem install wikk_configuration
25
+
26
+ ## LICENSE:
27
+
28
+ Copyright (c) 2016, wikarekare
29
+ All rights reserved.
30
+
31
+ Redistribution and use in source and binary forms, with or without
32
+ modification, are permitted provided that the following conditions are met:
33
+
34
+ * Redistributions of source code must retain the above copyright notice, this
35
+ list of conditions and the following disclaimer.
36
+
37
+ * Redistributions in binary form must reproduce the above copyright notice,
38
+ this list of conditions and the following disclaimer in the documentation
39
+ and/or other materials provided with the distribution.
40
+
41
+ * Neither the name of configuration nor the names of its
42
+ contributors may be used to endorse or promote products derived from
43
+ this software without specific prior written permission.
44
+
45
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
46
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
49
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
54
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/local/bin/ruby
2
+ # -*- ruby -*-
3
+
4
+ require 'rubygems'
5
+ require 'hoe'
6
+ Hoe.plugin :yard
7
+
8
+ Hoe.spec 'wikk_configuration' do
9
+ self.developer( "Rob Burrowes","r.burrowes@auckland.ac.nz")
10
+ remote_rdoc_dir = '' # Release to root
11
+
12
+ self.yard_title = 'wikk_configuration'
13
+ self.yard_options = ['--markup', 'markdown', '--protected']
14
+ end
15
+
16
+
17
+ #Validate manfest.txt
18
+ #rake check_manifest
19
+
20
+ #Local checking. Creates pkg/
21
+ #rake gem
22
+
23
+ #create doc/
24
+ #rake docs
25
+ #In directory docs/
26
+ #scp -r . rbur004@rubyforge.org:/var/www/gforge-projects/versioncheck/
27
+
28
+ #Copy up to rubygem.org
29
+ #rake release VERSION=1.0.1
@@ -0,0 +1,45 @@
1
+ require 'json'
2
+
3
+ #Reads json configuration and provides access to the configuration data
4
+ #as method calls.
5
+ class Configuration
6
+ VERSION = '0.1.0'
7
+
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
15
+
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
24
+
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
39
+
40
+ # @return [String] the configuration
41
+ def to_s
42
+ @pjson.to_s
43
+ end
44
+
45
+ end
data/test/conf.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "base_directory": "/usr/local/random",
3
+ "hello": [ 0, 1, 2, 3 , 4 ],
4
+ "world": { "0": 0, "1": 1, "2": 2 },
5
+ "boolean": true,
6
+ "string": "string",
7
+ "numeric": 1.2345
8
+ }
@@ -0,0 +1,45 @@
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
+
6
+ #Provides a self test of this class, by reading the test configuration file.
7
+ # and attempting to access configuration items as methods.
8
+ def test(config_file)
9
+ puts "creating config from '#{config_file}'"
10
+ config = Configuration.new(config_file)
11
+
12
+ puts "******Should be there*********"
13
+ puts "base_directories is defined? #{config.respond_to?(:base_directory)}"
14
+ puts "base_directories is: '#{config.base_directory}'"
15
+ puts "******Should NOT be there*********"
16
+ puts "not_there is defined? #{config.respond_to?(:not_there)}"
17
+ puts "******Array*********"
18
+ puts "hello is of class: #{config.hello.class}"
19
+ puts "config.hello[0] => #{config.hello[0]}"
20
+ puts "******Hash*********"
21
+ puts "world is of class: #{config.world.class}"
22
+ puts "config.world['1'] => #{config.world['1']}"
23
+ puts "******Boolean*********"
24
+ puts "boolean is of class: #{config.boolean.class}"
25
+ puts "config.boolean => #{config.boolean}"
26
+ puts "******String*********"
27
+ puts "string is of class: #{config.string.class}"
28
+ puts "config.string => #{config.string}"
29
+ puts "******Numeric*********"
30
+ puts "numeric is of class: #{config.numeric.class}"
31
+ puts "config.numeric => #{config.numeric}"
32
+ puts "****** Dump config using to_s *********"
33
+ pp config
34
+ end
35
+
36
+ puts "Start"
37
+ begin
38
+ test('conf.json')
39
+ rescue Exception => error
40
+ puts "Error: error"
41
+ end
42
+ puts "End"
43
+
44
+
45
+
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wikk_configuration
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rob Burrowes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hoe-yard
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.2
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: hoe
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !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
43
+ email:
44
+ - r.burrowes@auckland.ac.nz
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files:
48
+ - History.txt
49
+ - Manifest.txt
50
+ - README.md
51
+ files:
52
+ - History.txt
53
+ - Manifest.txt
54
+ - README.md
55
+ - Rakefile
56
+ - lib/wikk_configuration.rb
57
+ - test/conf.json
58
+ - test/manualtest.rb
59
+ homepage: http://rbur004.github.com/configuration/
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options:
65
+ - "--markup"
66
+ - markdown
67
+ - "--protected"
68
+ - "--title"
69
+ - wikk_configuration
70
+ - "--quiet"
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.5.1
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Ruby class to read json configuration files, and present the top level values
89
+ as method calls
90
+ test_files: []