config_reader 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/PostInstall.txt +7 -0
- data/README.txt +48 -0
- data/lib/config_reader/version.rb +9 -0
- data/lib/config_reader.rb +73 -0
- metadata +79 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 FIXME full name
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/PostInstall.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= config_reader
|
2
|
+
|
3
|
+
* FIX (url)
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
FIX (describe your package)
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIX (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* FIX (sudo gem install, anything else)
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2008 FIXME full name
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
begin
|
3
|
+
require 'erb'
|
4
|
+
rescue LoadError
|
5
|
+
puts "ERB not found, you won't be able to use ERB in your config"
|
6
|
+
end
|
7
|
+
|
8
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
9
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
10
|
+
|
11
|
+
class ConfigReader
|
12
|
+
@config_file = nil
|
13
|
+
@config = nil
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def config
|
17
|
+
@config = nil unless defined?(@config)
|
18
|
+
@config ||= reload
|
19
|
+
end
|
20
|
+
|
21
|
+
def config_file=(file)
|
22
|
+
@config_file = file
|
23
|
+
end
|
24
|
+
|
25
|
+
def reload
|
26
|
+
raise 'No config file set' unless @config_file
|
27
|
+
|
28
|
+
if defined?(ERB)
|
29
|
+
conf = YAML.load(ERB.new(File.open(find_config).read).result)
|
30
|
+
else
|
31
|
+
conf = YAML.load(File.open(find_config).read)
|
32
|
+
end
|
33
|
+
|
34
|
+
raise 'No config found' unless conf
|
35
|
+
|
36
|
+
if defined?(RAILS_ENV)
|
37
|
+
env = RAILS_ENV
|
38
|
+
elsif defined?(APP_ENV)
|
39
|
+
env = APP_ENV
|
40
|
+
end
|
41
|
+
|
42
|
+
_conf = conf['defaults']
|
43
|
+
_conf.merge(conf[env]) if conf[env]
|
44
|
+
_conf
|
45
|
+
end
|
46
|
+
|
47
|
+
def [](key)
|
48
|
+
config[key]
|
49
|
+
end
|
50
|
+
|
51
|
+
def find_config
|
52
|
+
%w( . config ).each do |dir|
|
53
|
+
config_file = File.join(dir, @config_file)
|
54
|
+
return config_file if File.exist?(config_file)
|
55
|
+
end
|
56
|
+
''
|
57
|
+
end
|
58
|
+
|
59
|
+
def method_missing(key)
|
60
|
+
config[key.to_s] || super
|
61
|
+
end
|
62
|
+
|
63
|
+
def inspect
|
64
|
+
puts config.inspect
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class Hash
|
70
|
+
def method_missing(key)
|
71
|
+
self[key.to_s] || super
|
72
|
+
end
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: config_reader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Moen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-06 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.7.0
|
24
|
+
version:
|
25
|
+
description: Configurations based on environment ala Rails
|
26
|
+
email:
|
27
|
+
- michael@underpantsgnome.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- History.txt
|
34
|
+
- License.txt
|
35
|
+
- PostInstall.txt
|
36
|
+
- README.txt
|
37
|
+
files:
|
38
|
+
- History.txt
|
39
|
+
- License.txt
|
40
|
+
- PostInstall.txt
|
41
|
+
- README.txt
|
42
|
+
- lib/config_reader.rb
|
43
|
+
- lib/config_reader/version.rb
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://underpantsgnome.rubyforge.org
|
46
|
+
post_install_message: |+
|
47
|
+
|
48
|
+
For more information on config_reader, see http://config_reader.rubyforge.org
|
49
|
+
|
50
|
+
NOTE: Change this information in PostInstall.txt
|
51
|
+
You can also delete it if you don't want it.
|
52
|
+
|
53
|
+
|
54
|
+
rdoc_options:
|
55
|
+
- --main
|
56
|
+
- README.txt
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project: underpantsgnome
|
74
|
+
rubygems_version: 1.2.0
|
75
|
+
signing_key:
|
76
|
+
specification_version: 2
|
77
|
+
summary: Configurations based on environment ala Rails
|
78
|
+
test_files: []
|
79
|
+
|