config-file-loader 0.1.0 → 0.1.1
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.
- data/CHANGELOG +3 -1
- data/README.markdown +75 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/init.rb +1 -0
- data/lib/config-file-loader.rb +1 -0
- data/lib/config_file_loader.rb +6 -1
- data/rails/init.rb +1 -0
- metadata +10 -7
- data/README.rdoc +0 -41
data/CHANGELOG
CHANGED
data/README.markdown
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# config-file-loader
|
2
|
+
|
3
|
+
Inspired/ ripped off from ryan bate's great railscast
|
4
|
+
|
5
|
+
[http://railscasts.com/episodes/85-yaml-configuration-file]()
|
6
|
+
|
7
|
+
## features
|
8
|
+
|
9
|
+
* configuration file is in yaml
|
10
|
+
* supports erb in yaml file
|
11
|
+
* assumes/adds yml extension
|
12
|
+
* assumes file is in RAILS_ROOT/config
|
13
|
+
* can override config file location per file (using an absolute or relative path) or globally
|
14
|
+
* allows custom override files, so for local developers or production per machine values
|
15
|
+
* different variable values for different "Rails" environments.
|
16
|
+
* works in Rails, but also in non rails-projects.
|
17
|
+
|
18
|
+
## planned features
|
19
|
+
|
20
|
+
* monitoring files and updating upon file changes using fsevents.
|
21
|
+
* database based config values
|
22
|
+
* memcache config values
|
23
|
+
* ui to see and edit variables (will save to db/memcache - probably not file)
|
24
|
+
|
25
|
+
## file format
|
26
|
+
|
27
|
+
supports aliases, erb, and any yaml construct.
|
28
|
+
|
29
|
+
defaults: &defaults
|
30
|
+
d1: v1
|
31
|
+
d2: v2
|
32
|
+
development:
|
33
|
+
<<: *defaults
|
34
|
+
attribute1: value1
|
35
|
+
attribute2:
|
36
|
+
attribute2a: value2a
|
37
|
+
attribute2b: value2b
|
38
|
+
attribute3: <%= ENV['USER'] %>
|
39
|
+
test:
|
40
|
+
<<: *defaults
|
41
|
+
attribute1: value1b
|
42
|
+
...
|
43
|
+
|
44
|
+
override file:
|
45
|
+
|
46
|
+
development:
|
47
|
+
attribute2:
|
48
|
+
attribute2a: replaced-value2a
|
49
|
+
|
50
|
+
If you are nesting hashes within a file, remember that yaml will replace the whole hash.
|
51
|
+
|
52
|
+
But a separate override file will merge in values. So in development, only attribute2a will be replaced.
|
53
|
+
|
54
|
+
## usage
|
55
|
+
|
56
|
+
APP_CONFIG = ConfigFileLoader.load(
|
57
|
+
'app_config.yml',
|
58
|
+
'app_config_local.yml',
|
59
|
+
'/opt/local/config/app_config_override.yml'
|
60
|
+
)
|
61
|
+
|
62
|
+
|
63
|
+
## Note on Patches/Pull Requests
|
64
|
+
|
65
|
+
* Fork the project.
|
66
|
+
* Make your feature addition or bug fix.
|
67
|
+
* Add tests for it. This is important so I don't break it in a
|
68
|
+
future version unintentionally.
|
69
|
+
* Commit, do not mess with rakefile, version, or history.
|
70
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
71
|
+
* Send me a pull request. Bonus points for topic branches.
|
72
|
+
|
73
|
+
## Copyright
|
74
|
+
|
75
|
+
Copyright (c) 2010 kbrock. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ begin
|
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "config-file-loader"
|
8
8
|
gem.summary = %Q{Load config files from disk}
|
9
|
-
gem.description = %Q{simple way to load erb yaml config files}
|
9
|
+
gem.description = %Q{simple way to load erb yaml config files. based upon http://railscasts.com/episodes/85-yaml-configuration-file}
|
10
10
|
gem.email = "keenan@thebrocks.net"
|
11
11
|
gem.homepage = "http://github.com/kbrock/config-file-loader"
|
12
12
|
gem.authors = ["kbrock"]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'config_file_loader'
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/config_file_loader'
|
data/lib/config_file_loader.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'erb'
|
2
2
|
require 'yaml'
|
3
|
+
require 'ostruct'
|
3
4
|
class ConfigFileLoader
|
4
5
|
|
5
6
|
## base directory for configuration
|
@@ -36,6 +37,10 @@ class ConfigFileLoader
|
|
36
37
|
load_files(*files)
|
37
38
|
end
|
38
39
|
|
40
|
+
def self.load_as_struct(*files)
|
41
|
+
OpenStruct.new(load_files(*files))
|
42
|
+
end
|
43
|
+
|
39
44
|
def self.load(*files, &block)
|
40
45
|
block=lambda() { |hash| self.deep_symbolize_keys(hash) } unless block_given?
|
41
46
|
load_files(*files,&block)
|
@@ -55,7 +60,7 @@ class ConfigFileLoader
|
|
55
60
|
def self.fix_name(name)
|
56
61
|
return unless name.is_a?(String)
|
57
62
|
#if it is not relative ('./file') or absolute ('/a/b/file') - tack on config directory
|
58
|
-
name = "#{self.base}/#{name}" unless ['.','/'].include?(name[0,1])
|
63
|
+
name = "#{self.base}/#{name}" unless ['.','/','~'].include?(name[0,1])
|
59
64
|
name+=".yml" unless name.include?('yml') || name.include?('cfg')
|
60
65
|
name
|
61
66
|
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'config_file_loader'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: config-file-loader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- kbrock
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-08-18 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
version: 1.2.9
|
35
35
|
type: :development
|
36
36
|
version_requirements: *id001
|
37
|
-
description: simple way to load erb yaml config files
|
37
|
+
description: simple way to load erb yaml config files. based upon http://railscasts.com/episodes/85-yaml-configuration-file
|
38
38
|
email: keenan@thebrocks.net
|
39
39
|
executables: []
|
40
40
|
|
@@ -42,16 +42,19 @@ extensions: []
|
|
42
42
|
|
43
43
|
extra_rdoc_files:
|
44
44
|
- LICENSE
|
45
|
-
- README.
|
45
|
+
- README.markdown
|
46
46
|
files:
|
47
47
|
- .document
|
48
48
|
- .gitignore
|
49
49
|
- CHANGELOG
|
50
50
|
- LICENSE
|
51
|
-
- README.
|
51
|
+
- README.markdown
|
52
52
|
- Rakefile
|
53
53
|
- VERSION
|
54
|
+
- init.rb
|
55
|
+
- lib/config-file-loader.rb
|
54
56
|
- lib/config_file_loader.rb
|
57
|
+
- rails/init.rb
|
55
58
|
- spec/config/a.yml
|
56
59
|
- spec/config/b.yml
|
57
60
|
- spec/config/dev_prod.yml
|
data/README.rdoc
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
= config-file-loader
|
2
|
-
|
3
|
-
http://railscasts.com/episodes/85-yaml-configuration-file
|
4
|
-
|
5
|
-
* assumes yaml files (which can contain erb) with the extension yml
|
6
|
-
* assumes yaml file is in config (unless an absolute path is given)
|
7
|
-
|
8
|
-
== file format
|
9
|
-
|
10
|
-
# development:
|
11
|
-
# attribute1: value1
|
12
|
-
# attribute2:
|
13
|
-
# attribute2a: value2a
|
14
|
-
# attribute2b: value2b
|
15
|
-
# attribute3: <%= ENV['USER'] %>
|
16
|
-
# test:
|
17
|
-
# attribute1: value1b
|
18
|
-
# ...
|
19
|
-
|
20
|
-
== usage
|
21
|
-
|
22
|
-
APP_CONFIG = ConfigFileLoader.load(
|
23
|
-
'app_config.yml',
|
24
|
-
'app_config_local.yml',
|
25
|
-
'/opt/local/config/app_config_override.yml'
|
26
|
-
)
|
27
|
-
|
28
|
-
|
29
|
-
== Note on Patches/Pull Requests
|
30
|
-
|
31
|
-
* Fork the project.
|
32
|
-
* Make your feature addition or bug fix.
|
33
|
-
* Add tests for it. This is important so I don't break it in a
|
34
|
-
future version unintentionally.
|
35
|
-
* Commit, do not mess with rakefile, version, or history.
|
36
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
37
|
-
* Send me a pull request. Bonus points for topic branches.
|
38
|
-
|
39
|
-
== Copyright
|
40
|
-
|
41
|
-
Copyright (c) 2010 kbrock. See LICENSE for details.
|