configmanager 0.0.2 → 0.0.3

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.
@@ -1,9 +1,9 @@
1
- #
2
- # 20 Jul 2012
3
- #
4
-
5
- module ConfigManager
6
-
7
- VERSION = "0.0.2"
8
-
1
+ #
2
+ # 20 Jul 2012
3
+ #
4
+
5
+ module ConfigManager
6
+
7
+ VERSION = "0.0.3"
8
+
9
9
  end
@@ -1,17 +1,17 @@
1
- # Comments are ignored. So are empty lines.
2
-
3
- # Commands start with '@' character.
4
- # The import command will import another file into this file. The path is resolved relative to this file.
5
- @import "test 2.properties"
6
-
7
- # A property has the following format
8
- # <key><:optional_type> = <value>
9
- test.sample_string = Test String
10
- test.sample_int:int = 1
11
- test.sample_float:float = 1.0
12
-
13
- # Arrays can be created by appending [] to a property. Arrays are split using the ',' character.
14
- test.sample_array[] = first, second, third
15
-
16
- # Arrays can also be provided with a type - each value is converted to that type.
17
- test.sample_int_array:int[] = 1, 2, 3
1
+ # Comments are ignored. So are empty lines.
2
+
3
+ # Commands start with '@' character.
4
+ # The import command will import another file into this file. The path is resolved relative to this file.
5
+ @import "test 2.properties"
6
+
7
+ # A property has the following format
8
+ # <key><:optional_type> = <value>
9
+ test.sample_string = Test String
10
+ test.sample_int:int = 1a
11
+ test.sample_float:float = 1.0
12
+
13
+ # Arrays can be created by appending [] to a property. Arrays are split using the ',' character.
14
+ test.sample_array[] = first, second, third
15
+
16
+ # Arrays can also be provided with a type - each value is converted to that type.
17
+ test.sample_int_array:int[] = 1, 2, 3
@@ -1,14 +1,14 @@
1
- # Comments are ignored. So are empty lines.
2
-
3
- # The import key has special meaning. It will import another file into this file.
4
- # The path is resolved relative to this file.
5
- import: 'test 2.yaml'
6
-
7
- # The format is same as any YAML file.
8
- test_yaml:
9
- sample_string: Test String
10
- sample_int: 1
11
- sample_float: 1.0
12
-
13
- sample_array: [first, second, third]
14
- sample_int_array: [1, 2, 3]
1
+ # Comments are ignored. So are empty lines.
2
+
3
+ # The import key has special meaning. It will import another file into this file.
4
+ # The path is resolved relative to this file.
5
+ import: 'test 2.yaml'
6
+
7
+ # The format is same as any YAML file.
8
+ test_yaml:
9
+ sample_string: Test String
10
+ sample_int: 1
11
+ sample_float: 1.0
12
+
13
+ sample_array: [first, second, third]
14
+ sample_int_array: [1, 2, 3]
@@ -1,9 +1,9 @@
1
- # This file imported by test 1.properties
2
-
3
- # Properties can reference other properties too. References are evaluated only when the
4
- # property's value is evaluated. The referenced property's type is not used - so this property will
5
- # evaluate as a String.
6
- test.sample_reference = ${test.sample_int}
7
-
8
- # References can be part of an array too.
9
- test.sample_reference_array[] = ${test.sample_string}, ${test.sample_int}, ${test.sample_float}
1
+ # This file imported by test 1.properties
2
+
3
+ # Properties can reference other properties too. References are evaluated only when the
4
+ # property's value is evaluated. The referenced property's type is not used - so this property will
5
+ # evaluate as a String.
6
+ test.sample_reference = ${test.sample_int}
7
+
8
+ # References can be part of an array too.
9
+ test.sample_reference_array[] = ${test.sample_string}, ${test.sample_int}, ${test.sample_float}
@@ -1,8 +1,8 @@
1
- # This file imported by test 1.yaml
2
-
3
- # Properties can reference other properties too. References are evaluated only when the
4
- # property's value is evaluated. The referenced property's type is not used - so this property will
5
- # evaluate as a String.
6
- test_yaml:
7
- sample_reference: ${test_yaml.sample_int}
8
- sample_reference_array: [${test_yaml.sample_string}, ${test_yaml.sample_int}, ${test_yaml.sample_float}]
1
+ # This file imported by test 1.yaml
2
+
3
+ # Properties can reference other properties too. References are evaluated only when the
4
+ # property's value is evaluated. The referenced property's type is not used - so this property will
5
+ # evaluate as a String.
6
+ test_yaml:
7
+ sample_reference: ${test_yaml.sample_int} - ${missing}
8
+ sample_reference_array: [${test_yaml.sample_string}, ${test_yaml.sample_int}, ${test_yaml.sample_float}]
@@ -1,26 +1,28 @@
1
- #
2
- # 20 Jul 2012
3
- #
4
-
5
- $LOAD_PATH << "."
6
-
7
- require "configmanager"
8
- require "configmanager/combined_configuration"
9
- require "configmanager/loaders"
10
-
11
- properties_configuration = ConfigManager.load_from_file("samples/test 1.properties", ConfigManager::JavaPropertiesLoader)
12
- yaml_configuration = ConfigManager.load_from_file("samples/test 1.yaml", ConfigManager::YAMLPropertiesLoader)
13
-
14
- test_configuration = ConfigManager::CombinedConfiguration.new()
15
- test_configuration.add_configuration("properties", properties_configuration)
16
- test_configuration.add_configuration("yaml", yaml_configuration)
17
-
18
- keys = ["sample_string", "sample_int", "sample_float", "sample_array", "sample_int_array", "sample_reference",
19
- "sample_reference_array"]
20
-
21
- puts ".properties"
22
- keys.each { |key| puts test_configuration["test.#{key}"].inspect }
23
-
24
- puts ""
25
- puts ".yaml"
26
- keys.each { |key| puts test_configuration["test_yaml.#{key}"].inspect }
1
+ #
2
+ # 20 Jul 2012
3
+ #
4
+
5
+ $LOAD_PATH << "."
6
+
7
+ require "configmanager"
8
+ require "configmanager/combined_configuration"
9
+ require "configmanager/loaders"
10
+
11
+ properties_configuration = ConfigManager.load_from_file("samples/test 1.properties", ConfigManager::JavaPropertiesLoader)
12
+ yaml_configuration = ConfigManager.load_from_file("samples/test 1.yaml", ConfigManager::YAMLPropertiesLoader)
13
+
14
+ test_configuration = ConfigManager::CombinedConfiguration.new(:tolerate_missing_references => true)
15
+ test_configuration.add_configuration("properties", properties_configuration)
16
+ test_configuration.add_configuration("yaml", yaml_configuration)
17
+
18
+ keys = ["sample_string", "sample_int", "sample_float", "sample_array", "sample_int_array", "sample_reference",
19
+ "sample_reference_array"]
20
+
21
+ upcase = Proc.new { |value| value.kind_of?(String) ? value.upcase : value }
22
+
23
+ puts ".properties"
24
+ keys.each { |key| puts "#{key} = #{test_configuration["test.#{key}"].inspect}" }
25
+
26
+ puts ""
27
+ puts ".yaml"
28
+ keys.each { |key| puts "#{key} = #{test_configuration["test_yaml.#{key}"].inspect}" }
metadata CHANGED
@@ -1,25 +1,48 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: configmanager
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Suraj Vijayakumar
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-07-20 00:00:00.000000000Z
13
- dependencies: []
14
- description: ConfigManager can load properties from YAML or Java style property files.
15
- Properties can have references to other properties that are resolved at run-time.
16
- Inspired, in part by Apache's configuration API.
17
- email:
17
+
18
+ date: 2012-07-24 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: options-arg
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 29
29
+ segments:
30
+ - 0
31
+ - 0
32
+ - 1
33
+ version: 0.0.1
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: ConfigManager can load properties from YAML or Java style property files. Properties can have references to other properties that are resolved at run-time. Inspired, in part by Apache's configuration API.
37
+ email:
18
38
  - vijayakumar.suraj@gmail.com
19
39
  executables: []
40
+
20
41
  extensions: []
42
+
21
43
  extra_rdoc_files: []
22
- files:
44
+
45
+ files:
23
46
  - lib/configmanager/combined_configuration.rb
24
47
  - lib/configmanager/configuration.rb
25
48
  - lib/configmanager/exceptions.rb
@@ -27,7 +50,6 @@ files:
27
50
  - lib/configmanager/loaders.rb
28
51
  - lib/configmanager/version.rb
29
52
  - lib/configmanager.rb
30
- - lib/options_arg.rb
31
53
  - lib/samples/test 1.properties
32
54
  - lib/samples/test 1.yaml
33
55
  - lib/samples/test 2.properties
@@ -35,27 +57,36 @@ files:
35
57
  - lib/test_configmanager.rb
36
58
  homepage:
37
59
  licenses: []
60
+
38
61
  post_install_message:
39
62
  rdoc_options: []
40
- require_paths:
63
+
64
+ require_paths:
41
65
  - lib
42
- required_ruby_version: !ruby/object:Gem::Requirement
66
+ required_ruby_version: !ruby/object:Gem::Requirement
43
67
  none: false
44
- requirements:
45
- - - ! '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
76
  none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
54
84
  requirements: []
85
+
55
86
  rubyforge_project:
56
- rubygems_version: 1.7.2
87
+ rubygems_version: 1.8.24
57
88
  signing_key:
58
89
  specification_version: 3
59
- summary: An easy configuration manager for managing an applications configuration
60
- files.
90
+ summary: An easy configuration manager for managing an applications configuration files.
61
91
  test_files: []
92
+
@@ -1,66 +0,0 @@
1
- #
2
- # 16 Jul 2012
3
- #
4
-
5
- # Provides a few methods to work with hashes.
6
- module Kernel
7
-
8
- # Raised if a required option has not been set.
9
- class OptionNotSetError < Exception
10
- end
11
-
12
- private
13
-
14
- # Get a value from the specified hash.
15
- #
16
- # @param [Hash] options the hash.
17
- # @param [Symbol] key the key whose value is required.
18
- # @param [TrueClass, FalseClass] required flag to indicate if it is an error if the key does not exist.
19
- # @param [Object] default the default value if the key does not exist. Only used if 'required' is false.
20
- #
21
- # @return [Object] the value from the hash, or the default value.
22
- def get_option(options, key, required = false, default = nil)
23
- if options.has_key?(key)
24
- options[key]
25
- elsif required
26
- raise OptionNotSetError.new("Option '#{key}' has not been set!")
27
- else
28
- default
29
- end
30
- end
31
-
32
- # Pops (delete) a value from the specified hash.
33
- #
34
- # @param [Hash] options the hash.
35
- # @param [Symbol] key the key whose value is required.
36
- # @param [TrueClass, FalseClass] required flag to indicate if it is an error if the key does not exist.
37
- # @param [Object] default the default value if the key does not exist. Only used if 'required' is false.
38
- #
39
- # @return [Object] the value from the hash, or the default value.
40
- def pop_option(options, key, required = false, default = nil)
41
- if options.has_key?(key)
42
- options.delete(key)
43
- elsif required
44
- raise OptionNotSetError.new("Option '#{key}' has not been set!")
45
- else
46
- default
47
- end
48
- end
49
-
50
- # Sets a value in the specified hash.
51
- #
52
- # @param [Hash] options the hash.
53
- # @param [Symbol] key the key whose value is to be set.
54
- # @param [Object] value the value to set.
55
- # @param [TrueClass, FalseClass] overwrite flag to indicate if existing values should be overwritten.
56
- #
57
- # @return [Object] the value in the hash at the end of the operation.
58
- def set_option(options, key, value, overwrite)
59
- if not options.has_key?(key) or overwrite
60
- options[key] = value
61
- end
62
- # Return whatever is in the hash now.
63
- options[key]
64
- end
65
-
66
- end