konfiguration 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 +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE +27 -0
- data/README.md +53 -0
- data/Rakefile +2 -0
- data/konfiguration.gemspec +22 -0
- data/lib/konfiguration.rb +60 -0
- data/lib/konfiguration/version.rb +3 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 97f73b75f0faae1940691df08561fb15bb19a0b3
|
4
|
+
data.tar.gz: d9782c5c5985f629c00429591b6295fe787a79d7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 79e321bbcb3f0c8df9d200736d70d3e8e26bd614b5ec3249e46e889f52ba6452947bfe710d8fa7a9fc1ec043b869332103559d329b566c4a3cafe51b3bfe7837
|
7
|
+
data.tar.gz: 5aac39df380b0cdcfd09a56a05d2f45a8eed418b2135d91f979ee26942e3ead3e43134c71fcdc619174fa82d6a7e762b89ed8607677ca6aae91c687e4d9b0210
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
The Azure License
|
2
|
+
|
3
|
+
Copyright (c) 2014 Kenneth Ballenegger
|
4
|
+
|
5
|
+
Attribute to Kenneth Ballenegger - http://kswizz.com/
|
6
|
+
|
7
|
+
You (the licensee) are hereby granted permission, free of charge, to deal in
|
8
|
+
this software or source code (this "Software") without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish, distribute,
|
10
|
+
and/or sublicense this Software, subject to the following conditions:
|
11
|
+
|
12
|
+
You must give attribution to the party mentioned above, by name and by
|
13
|
+
hyperlink, in the about box, credits document and/or documentation of any
|
14
|
+
derivative work using a substantial portion of this Software.
|
15
|
+
|
16
|
+
You may not use the name of the copyright holder(s) to endorse or promote
|
17
|
+
products derived from this Software without specific prior written permission.
|
18
|
+
|
19
|
+
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24
|
+
OUT OF OR IN CONNECTION WITH THIS SOFTWARE OR THE USE OR OTHER DEALINGS IN THIS
|
25
|
+
SOFTWARE.
|
26
|
+
|
27
|
+
http://license.azuretalon.com/
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Konfiguration
|
2
|
+
|
3
|
+
Konfiguration makes it easy to load YAML-formatted configuration files.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'konfiguration'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install konfiguration
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
The system looks for two external pieces of information in order to function:
|
22
|
+
|
23
|
+
1. `$app_path` must be set to the expanded path of the root of the app.
|
24
|
+
2. `ENV['env']` is the current environment, e.g., `live`, `dev`, etc. (Defaults
|
25
|
+
to `dev`).
|
26
|
+
|
27
|
+
The configuration system is based on several environment-specfic YAML files, in
|
28
|
+
the app's `config` subdirectory.
|
29
|
+
|
30
|
+
The directory structure looks like this:
|
31
|
+
|
32
|
+
config
|
33
|
+
/dev
|
34
|
+
/a-file-here-will-override-the-shared-version.yml
|
35
|
+
/live
|
36
|
+
/the-environment-is-pulled-from-the-kenji-env.yml
|
37
|
+
/shared
|
38
|
+
/a-file-that-is-shared-across-env.yml
|
39
|
+
|
40
|
+
Configuration can be fetched like this:
|
41
|
+
|
42
|
+
Konfiguration.foo :bar, :baz
|
43
|
+
|
44
|
+
In this case, it will fetch the configuration file `foo.yml`, and drill down
|
45
|
+
within that file to the key `bar.baz`.
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
1. Fork it ( https://github.com/kballenegger/konfiguration/fork )
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'konfiguration/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'konfiguration'
|
8
|
+
spec.version = Konfiguration::VERSION
|
9
|
+
spec.authors = ['Kenneth Ballenegger']
|
10
|
+
spec.email = ['kenneth@ballenegger.com']
|
11
|
+
spec.summary = %q{Konfiguration makes it easy to load YAML-formatted configuration files.}
|
12
|
+
spec.description = %q{Konfiguration makes it easy to load YAML-formatted configuration files.}
|
13
|
+
spec.homepage = 'https://github.com/kballenegger/konfiguration'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
21
|
+
spec.add_development_dependency 'rake'
|
22
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'konfiguration/version'
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
# The configuration system is based on several environment-specfic YAML files,
|
6
|
+
# in the app's `config` subdirectory.
|
7
|
+
#
|
8
|
+
# The directory structure looks like this:
|
9
|
+
# config
|
10
|
+
# /dev
|
11
|
+
# /a-file-here-will-override-the-shared-version.yml
|
12
|
+
# /live
|
13
|
+
# /the-environment-is-pulled-from-the-kenji-env.yml
|
14
|
+
# /shared
|
15
|
+
# /a-file-that-is-shared-across-env.yml
|
16
|
+
#
|
17
|
+
# Configuration can be fetched like this:
|
18
|
+
#
|
19
|
+
# Konfiguration.foo :bar, :baz
|
20
|
+
#
|
21
|
+
# In this case, it will fetch the configuration file `foo.yml`, and drill down
|
22
|
+
# within that file to the key `bar.baz`.
|
23
|
+
|
24
|
+
|
25
|
+
class Konfiguration
|
26
|
+
class << self
|
27
|
+
|
28
|
+
# We use method missing to capture the configuration to fetch.
|
29
|
+
#
|
30
|
+
def method_missing(method, *args)
|
31
|
+
config(method, *args)
|
32
|
+
end
|
33
|
+
|
34
|
+
class KonfigurationError < StandardError; end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def config(f, *path)
|
39
|
+
env = ENV['env'] == 'live' ? 'live' : 'dev' # TODO: dirty
|
40
|
+
env_file = "#{env}/#{f.to_s}"
|
41
|
+
shared_file = "shared/#{f.to_s}"
|
42
|
+
path.map!(&:to_s)
|
43
|
+
|
44
|
+
value = Cache[env_file] || Cache[shared_file]
|
45
|
+
path.each do |e|
|
46
|
+
unless value.is_a?(Hash) && value.key?(e)
|
47
|
+
raise KonfigurationError.new 'Cannot find requested configuration path.'
|
48
|
+
end
|
49
|
+
value = value[e]
|
50
|
+
end
|
51
|
+
value
|
52
|
+
end
|
53
|
+
|
54
|
+
# Preloaded cache, at startup. :)
|
55
|
+
Cache = Hash[Dir["#{$app_path}/config/*/*.yml"].map do |f|
|
56
|
+
file = /([^\/]+\/[^\/]+)\.yml$/.match(f)[1]
|
57
|
+
[file, YAML.load_file("#{$app_path}/config/#{file}.yml")]
|
58
|
+
end]
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: konfiguration
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kenneth Ballenegger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Konfiguration makes it easy to load YAML-formatted configuration files.
|
42
|
+
email:
|
43
|
+
- kenneth@ballenegger.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- konfiguration.gemspec
|
54
|
+
- lib/konfiguration.rb
|
55
|
+
- lib/konfiguration/version.rb
|
56
|
+
homepage: https://github.com/kballenegger/konfiguration
|
57
|
+
licenses: []
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.2.2
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Konfiguration makes it easy to load YAML-formatted configuration files.
|
79
|
+
test_files: []
|
80
|
+
has_rdoc:
|