rconfig 0.3.3 → 0.4.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.
Files changed (74) hide show
  1. data/.gitignore +17 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/ChangeLog +50 -0
  5. data/Credits +13 -0
  6. data/Gemfile +9 -0
  7. data/Gemfile.lock +30 -0
  8. data/LICENSE.txt +20 -0
  9. data/README.rdoc +0 -0
  10. data/Rakefile +11 -0
  11. data/demo/application.conf +3 -0
  12. data/demo/demo.conf +13 -0
  13. data/demo/demo.rb +14 -0
  14. data/demo/demo.xml +13 -0
  15. data/demo/demo.yml +12 -0
  16. data/doc/classes/ClassVariables.html +111 -0
  17. data/doc/classes/ConfigError.html +120 -0
  18. data/doc/classes/ConfigHash.html +354 -0
  19. data/doc/classes/Constants.html +226 -0
  20. data/doc/classes/Hash.html +269 -0
  21. data/doc/classes/InvalidConfigPathError.html +119 -0
  22. data/doc/classes/Object.html +220 -0
  23. data/doc/classes/PropertiesFileParser.html +282 -0
  24. data/doc/classes/RConfig.html +1745 -0
  25. data/doc/created.rid +1 -0
  26. data/doc/files/README_rdoc.html +271 -0
  27. data/doc/files/lib/rconfig/class_variables_rb.html +107 -0
  28. data/doc/files/lib/rconfig/config_hash_rb.html +114 -0
  29. data/doc/files/lib/rconfig/constants_rb.html +101 -0
  30. data/doc/files/lib/rconfig/core_ext/hash_rb.html +114 -0
  31. data/doc/files/lib/rconfig/core_ext/object_rb.html +101 -0
  32. data/doc/files/lib/rconfig/core_ext_rb.html +114 -0
  33. data/doc/files/lib/rconfig/exceptions_rb.html +110 -0
  34. data/doc/files/lib/rconfig/properties_file_parser_rb.html +146 -0
  35. data/doc/files/lib/rconfig/rconfig_rb.html +186 -0
  36. data/doc/files/lib/rconfig_rb.html +117 -0
  37. data/doc/fr_class_index.html +35 -0
  38. data/doc/fr_file_index.html +37 -0
  39. data/doc/fr_method_index.html +75 -0
  40. data/doc/index.html +24 -0
  41. data/doc/rdoc-style.css +208 -0
  42. data/lib/generators/rconfig/install_generator.rb +13 -0
  43. data/lib/generators/rconfig/templates/rconfig.rb +82 -0
  44. data/lib/rconfig.rb +98 -32
  45. data/lib/rconfig/callbacks.rb +46 -0
  46. data/lib/rconfig/cascade.rb +56 -0
  47. data/lib/rconfig/config.rb +78 -0
  48. data/lib/rconfig/constants.rb +58 -0
  49. data/lib/rconfig/core_ext/array.rb +3 -0
  50. data/lib/rconfig/core_ext/hash.rb +56 -57
  51. data/lib/rconfig/core_ext/nil.rb +5 -0
  52. data/lib/rconfig/core_ext/string.rb +3 -0
  53. data/lib/rconfig/core_methods.rb +276 -0
  54. data/lib/rconfig/exceptions.rb +21 -8
  55. data/lib/rconfig/load_paths.rb +55 -0
  56. data/lib/rconfig/logger.rb +86 -0
  57. data/lib/rconfig/properties_file.rb +138 -0
  58. data/lib/rconfig/reload.rb +75 -0
  59. data/lib/rconfig/settings.rb +93 -0
  60. data/lib/rconfig/utils.rb +175 -0
  61. data/lib/tasks/gem.rake +14 -0
  62. data/lib/tasks/rdoc.rake +11 -0
  63. data/lib/tasks/spec.rake +25 -0
  64. data/rconfig.gemspec +33 -0
  65. data/spec/core_ext/object_spec.rb +44 -0
  66. data/spec/rconfig_spec.rb +7 -0
  67. data/spec/spec.opts +4 -0
  68. data/spec/spec_helper.rb +16 -0
  69. metadata +128 -32
  70. data/lib/rconfig/config_hash.rb +0 -105
  71. data/lib/rconfig/core_ext.rb +0 -6
  72. data/lib/rconfig/properties_file_parser.rb +0 -80
  73. data/lib/rconfig/rconfig.rb +0 -871
  74. data/test/rconfig_test.rb +0 -381
@@ -0,0 +1,14 @@
1
+
2
+ namespace :gem do
3
+
4
+ desc 'Clean-up old gem version(s).'
5
+ task :clean do
6
+ sh "rm -f *.gem"
7
+ end
8
+
9
+ desc 'Build gem'
10
+ task :build => [:clean] do
11
+ sh "gem build rconfig.gemspec"
12
+ end
13
+ end
14
+
@@ -0,0 +1,11 @@
1
+ namespace :rdoc do
2
+
3
+ Rake::RDocTask.new(:build) do |rdoc|
4
+ rdoc.rdoc_dir = "doc"
5
+ rdoc.main = "README.rdoc"
6
+ rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
7
+ rdoc.options << "--all"
8
+ end
9
+
10
+ end
11
+
@@ -0,0 +1,25 @@
1
+
2
+ require 'spec/rake/spectask'
3
+
4
+ desc "Run all specifications"
5
+ Spec::Rake::SpecTask.new(:spec) do |t|
6
+ t.libs << "lib"
7
+ t.spec_opts = ["--color", "--require", "spec/spec_helper.rb"]
8
+ end
9
+
10
+ namespace :spec do
11
+
12
+ desc "Run all specifications verbosely"
13
+ Spec::Rake::SpecTask.new(:verbose) do |t|
14
+ t.libs << "lib"
15
+ t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
16
+ end
17
+
18
+ desc "Run specific specification verbosely (specify SPEC)"
19
+ Spec::Rake::SpecTask.new(:select) do |t|
20
+ t.libs << "lib"
21
+ t.spec_files = [ENV["SPEC"]]
22
+ t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
23
+ end
24
+
25
+ end
data/rconfig.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ $:.push File.expand_path("../lib", __FILE__)
6
+ require "rconfig"
7
+
8
+ Gem::Specification.new do |s|
9
+
10
+ # Metadata
11
+ s.name = 'rconfig'
12
+ s.version = RConfig::VERSION
13
+ s.authors = ['Rahmal Conda']
14
+ s.email = ['rahmal@gmail.com']
15
+ s.homepage = 'http://www.rahmalconda.com'
16
+ s.description = %q{Configuration management library for Ruby applications.}
17
+ s.summary = %q{The complete solution for Ruby Configuration Management. RConfig is a Ruby library that manages configuration within Ruby applications. It bridges the gap between yaml, xml, and key/value based properties files, by providing a centralized solution to handle application configuration from one location. It provides the simplicity of hash-based access, that Rubyists have come to know and love, supporting your configuration style of choice, while providing many new features, and an elegant API.}
18
+ s.licenses = ['MIT']
19
+
20
+ # Manifest
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+
26
+ # Dependencies
27
+ s.add_dependency 'activesupport', '~> 3.0'
28
+
29
+ s.add_development_dependency 'rspec', '~> 2.3.0'
30
+ s.add_development_dependency 'bundler', '~> 1.0.0'
31
+ s.add_development_dependency 'jeweler', '~> 1.6.4'
32
+ end
33
+
@@ -0,0 +1,44 @@
1
+
2
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
3
+
4
+ describe Object do
5
+
6
+ describe "#try" do
7
+
8
+ it "should return nil if method doesn't exist" do
9
+ obj = Object.new
10
+ lambda {obj.try(:bad_method)}.should_not raise_error
11
+ obj.try(:bad_method).should be_nil
12
+ end
13
+
14
+ it "should return the value from calling the method it exists" do
15
+ obj = Object.new
16
+ lambda {obj.try(:class)}.should_not raise_error
17
+ obj.try(:class).should_not be_nil
18
+ obj.try(:class).should equal Object
19
+ end
20
+
21
+ end
22
+
23
+ describe "#config" do
24
+
25
+ it "should return root config instance if no matching config file exists" do
26
+ class ObjectWithNoConfig; end
27
+ obj = ObjectWithNoConfig.new
28
+ lambda {obj.config}.should_not raise_error
29
+ obj.config.should_not be_nil
30
+ obj.config.should equal RConfig.instance
31
+ end
32
+
33
+ it "should class-specific config when matching config file exists" do
34
+ class MyClass; end
35
+ my_class = MyClass.new
36
+ lambda {my_class.config}.should_not raise_error
37
+ my_class.config.should_not be_nil
38
+ my_class.config.should equal $config.my_class
39
+ my_class.config.my_class_flag.should be_true
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "RConfig" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,16 @@
1
+ ROOT_DIR = File.expand_path(File.dirname(__FILE__))
2
+ CONF_DIR = File.join(ROOT_DIR, '..', 'test', 'config_files')
3
+
4
+ STDOUT.puts "ROOT_DIR: #{ROOT_DIR}"
5
+ STDOUT.puts "CONF_DIR: #{CONF_DIR}"
6
+
7
+ # Loads the rconfig library
8
+ $LOAD_PATH << File.join(ROOT_DIR, '..', 'lib')
9
+
10
+ require 'rconfig'
11
+
12
+ RConfig.initialize CONF_DIR, nil, true, true
13
+
14
+ # Requires supporting files in ./support/ and its subdirectories.
15
+ #Dir["#{ROOT_DIR}/support/**/*.rb"].each {|f| require f}
16
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rconfig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,54 +9,143 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-23 00:00:00.000000000Z
12
+ date: 2012-04-16 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &2152498960 !ruby/object:Gem::Requirement
16
+ requirement: &70096588990020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 2.2.2
21
+ version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152498960
25
- description: The complete solution for Ruby Configuration Management
26
- email: rahmal@gmail.com
24
+ version_requirements: *70096588990020
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70096588989460 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.3.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70096588989460
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70096588989000 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70096588989000
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &70096588988520 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.4
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70096588988520
58
+ description: Configuration management library for Ruby applications.
59
+ email:
60
+ - rahmal@gmail.com
27
61
  executables: []
28
62
  extensions: []
29
- extra_rdoc_files:
30
- - README.rdoc
63
+ extra_rdoc_files: []
31
64
  files:
32
- - lib/rconfig/config_hash.rb
65
+ - .gitignore
66
+ - .rspec
67
+ - .rvmrc
68
+ - ChangeLog
69
+ - Credits
70
+ - Gemfile
71
+ - Gemfile.lock
72
+ - LICENSE.txt
73
+ - README.rdoc
74
+ - Rakefile
75
+ - demo/application.conf
76
+ - demo/demo.conf
77
+ - demo/demo.rb
78
+ - demo/demo.xml
79
+ - demo/demo.yml
80
+ - doc/classes/ClassVariables.html
81
+ - doc/classes/ConfigError.html
82
+ - doc/classes/ConfigHash.html
83
+ - doc/classes/Constants.html
84
+ - doc/classes/Hash.html
85
+ - doc/classes/InvalidConfigPathError.html
86
+ - doc/classes/Object.html
87
+ - doc/classes/PropertiesFileParser.html
88
+ - doc/classes/RConfig.html
89
+ - doc/created.rid
90
+ - doc/files/README_rdoc.html
91
+ - doc/files/lib/rconfig/class_variables_rb.html
92
+ - doc/files/lib/rconfig/config_hash_rb.html
93
+ - doc/files/lib/rconfig/constants_rb.html
94
+ - doc/files/lib/rconfig/core_ext/hash_rb.html
95
+ - doc/files/lib/rconfig/core_ext/object_rb.html
96
+ - doc/files/lib/rconfig/core_ext_rb.html
97
+ - doc/files/lib/rconfig/exceptions_rb.html
98
+ - doc/files/lib/rconfig/properties_file_parser_rb.html
99
+ - doc/files/lib/rconfig/rconfig_rb.html
100
+ - doc/files/lib/rconfig_rb.html
101
+ - doc/fr_class_index.html
102
+ - doc/fr_file_index.html
103
+ - doc/fr_method_index.html
104
+ - doc/index.html
105
+ - doc/rdoc-style.css
106
+ - lib/generators/rconfig/install_generator.rb
107
+ - lib/generators/rconfig/templates/rconfig.rb
108
+ - lib/rconfig.rb
109
+ - lib/rconfig/callbacks.rb
110
+ - lib/rconfig/cascade.rb
111
+ - lib/rconfig/config.rb
112
+ - lib/rconfig/constants.rb
113
+ - lib/rconfig/core_ext/array.rb
33
114
  - lib/rconfig/core_ext/hash.rb
34
- - lib/rconfig/core_ext.rb
115
+ - lib/rconfig/core_ext/nil.rb
116
+ - lib/rconfig/core_ext/string.rb
117
+ - lib/rconfig/core_methods.rb
35
118
  - lib/rconfig/exceptions.rb
36
- - lib/rconfig/properties_file_parser.rb
37
- - lib/rconfig/rconfig.rb
38
- - lib/rconfig.rb
39
- - README.rdoc
40
- - test/rconfig_test.rb
119
+ - lib/rconfig/load_paths.rb
120
+ - lib/rconfig/logger.rb
121
+ - lib/rconfig/properties_file.rb
122
+ - lib/rconfig/reload.rb
123
+ - lib/rconfig/settings.rb
124
+ - lib/rconfig/utils.rb
125
+ - lib/tasks/gem.rake
126
+ - lib/tasks/rdoc.rake
127
+ - lib/tasks/spec.rake
128
+ - rconfig.gemspec
129
+ - spec/core_ext/object_spec.rb
130
+ - spec/rconfig_spec.rb
131
+ - spec/spec.opts
132
+ - spec/spec_helper.rb
41
133
  homepage: http://www.rahmalconda.com
42
- licenses: []
134
+ licenses:
135
+ - MIT
43
136
  post_install_message:
44
- rdoc_options:
45
- - --line-numbers
46
- - --inline-source
47
- - --title
48
- - RConfig
49
- - --main
50
- - README.rdoc
137
+ rdoc_options: []
51
138
  require_paths:
52
139
  - lib
53
- - tasks
54
140
  required_ruby_version: !ruby/object:Gem::Requirement
55
141
  none: false
56
142
  requirements:
57
143
  - - ! '>='
58
144
  - !ruby/object:Gem::Version
59
145
  version: '0'
146
+ segments:
147
+ - 0
148
+ hash: -4346478752822958469
60
149
  required_rubygems_version: !ruby/object:Gem::Requirement
61
150
  none: false
62
151
  requirements:
@@ -64,12 +153,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
153
  - !ruby/object:Gem::Version
65
154
  version: '0'
66
155
  requirements: []
67
- rubyforge_project: rconda-rconfig
68
- rubygems_version: 1.8.6
156
+ rubyforge_project:
157
+ rubygems_version: 1.8.15
69
158
  signing_key:
70
159
  specification_version: 3
71
- summary: RConfig manages configuration within Ruby applications. It supports yaml,
72
- xml, and properties files, with hash based and dot notation access, while providing
73
- an elegant API.
160
+ summary: The complete solution for Ruby Configuration Management. RConfig is a Ruby
161
+ library that manages configuration within Ruby applications. It bridges the gap
162
+ between yaml, xml, and key/value based properties files, by providing a centralized
163
+ solution to handle application configuration from one location. It provides the
164
+ simplicity of hash-based access, that Rubyists have come to know and love, supporting
165
+ your configuration style of choice, while providing many new features, and an elegant
166
+ API.
74
167
  test_files:
75
- - test/rconfig_test.rb
168
+ - spec/core_ext/object_spec.rb
169
+ - spec/rconfig_spec.rb
170
+ - spec/spec.opts
171
+ - spec/spec_helper.rb
@@ -1,105 +0,0 @@
1
- #++
2
- # Copyright (c) 2009 Rahmal Conda <rahmal@gmail.com>
3
- #
4
- # ConfigHash is a special class, derived from HashWithIndifferentAccess.
5
- # It was specifically created for handling config data or creating mock
6
- # objects from yaml files. It provides a dotted notation for accessing
7
- # embedded hash values, similar to the way one might traverse a object tree.
8
- #--
9
- class ConfigHash < HashWithIndifferentAccess
10
-
11
- # HashWithIndifferentAccess#dup always returns HashWithIndifferentAccess!
12
- def dup
13
- self.class.new(self)
14
- end
15
-
16
- ##
17
- # Dotted notation can be used with arguments (useful for creating mock objects)
18
- # in the YAML file the method name is a key, argument(s) form a nested key,
19
- # so that the correct value is retrieved and returned.
20
- #
21
- # For example loading to variable foo a yaml file that looks like:
22
- # customer:
23
- # id: 12345678
24
- # verified:
25
- # phone: verified
26
- # :address: info_not_available
27
- # ? [name, employer]
28
- # : not_verified
29
- #
30
- # Allows the following calls:
31
- # foo.customer.id => 12345678
32
- # foo.customer.verified.phone => verified
33
- # foo.customer.verified("phone") => verified
34
- # foo.customer.verified(:address) => info_not_available
35
- # foo.customer.verified("name", "employer") => not_verified
36
- #
37
- # Note that :address is specified as a symbol, where phone is just a string.
38
- # Depending on what kind of parameter the method being mocked out is going
39
- # to be called with, define in the YAML file either a string or a symbol.
40
- # This also works inside the composite array keys.
41
- def method_missing(method, *args)
42
- method = method.to_s
43
- # STDERR.puts "CHF#method_missing(#{method.inspect}, #{args.inspect}) on #{self.inspect}:#{self.class}" if method == 'dup'
44
- value = self[method]
45
- case args.size
46
- when 0
47
- # e.g.: RConfig.application.method
48
- ;
49
- when 1
50
- # e.g.: RConfig.application.method(one_arg)
51
- value = value.send(args[0])
52
- else
53
- # e.g.: RConfig.application.method(arg_one, args_two, ...)
54
- value = value[args]
55
- end
56
- # value = convert_value(value)
57
- value
58
- end
59
-
60
- ##
61
- # Why the &*#^@*^&$ isn't HashWithIndifferentAccess actually doing this?
62
- def [](key)
63
- key = key.to_s if key.kind_of?(Symbol)
64
- super(key)
65
- end
66
-
67
- # HashWithIndifferentAccess#default is broken!
68
- define_method(:default_Hash, Hash.instance_method(:default))
69
-
70
- ##
71
- # Allow hash.default => hash['default']
72
- # without breaking Hash's usage of default(key)
73
- @@no_key = [ :no_key ] # magically unique value.
74
- def default(key = @@no_key)
75
- key = key.to_s if key.is_a?(Symbol)
76
- key == @@no_key ? self['default'] : default_Hash(key == @@no_key ? nil : key)
77
- end
78
-
79
- ##
80
- # HashWithIndifferentAccess#update is broken!
81
- # Hash#update returns self,
82
- # BUT,
83
- # HashWithIndifferentAccess#update does not!
84
- #
85
- # { :a => 1 }.update({ :b => 2, :c => 3 })
86
- # => { :a => 1, :b => 2, :c => 3 }
87
- #
88
- # HashWithIndifferentAccess.new({ :a => 1 }).update({ :b => 2, :c => 3 })
89
- # => { :b => 2, :c => 3 } # WTF?
90
- #
91
- # Subclasses should *never* override methods and break their protocols!!!!
92
- def update(hash)
93
- super(hash)
94
- self
95
- end
96
-
97
- ##
98
- # Override WithIndifferentAccess#convert_value
99
- # return instances of this class for Hash values.
100
- def convert_value(value)
101
- # STDERR.puts "convert_value(#{value.inspect}:#{value.class})"
102
- value.class == Hash ? self.class.new(value).freeze : value
103
- end
104
-
105
- end # class ConfigHash