qonf 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +1 -0
- data/lib/qonf/version.rb +3 -0
- data/lib/qonf.rb +64 -0
- data/qonf.gemspec +25 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 591bc552b73f533e5f5b4b1bdf31797da741c2cc
|
4
|
+
data.tar.gz: 5a9adc0b572be57e28ae9e97c75a9a6d0517dae5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c3a456363433f117a4e866ec14bbe727e415b2866f12b86a120797a170526d831815cb43263dc1dd2b660c4dac476968d15d946b8f6dfdcb5bf81c527ee40596
|
7
|
+
data.tar.gz: 4238289d7180f232d3eb9770605f7bec6c989a6d663184df7cd27720cc5d276ab393afc39226ad5d21e2b4a937b2e949e0ef3859371b8406210dc44fefa3f606
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Geoff Hayes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Qonf
|
2
|
+
|
3
|
+
Versitle configuration management. Pull data from ENV or config files. Simplest use case:
|
4
|
+
|
5
|
+
config/qonf.json
|
6
|
+
```
|
7
|
+
{
|
8
|
+
"host": "http://google.com"
|
9
|
+
}
|
10
|
+
```
|
11
|
+
|
12
|
+
Qonf.host # "http://google.com"
|
13
|
+
|
14
|
+
Additionally, you could make a file config/redis.yml
|
15
|
+
|
16
|
+
```
|
17
|
+
development:
|
18
|
+
host: localhost
|
19
|
+
```
|
20
|
+
|
21
|
+
Qonf.get(:redis,:host) # "localhost"
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
Add this line to your application's Gemfile:
|
26
|
+
|
27
|
+
gem 'qonf'
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ bundle
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
$ gem install qonf
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
TODO: Write usage instructions here
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/qonf/version.rb
ADDED
data/lib/qonf.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require "qonf/version"
|
2
|
+
|
3
|
+
# A simple module to get information quickly out of config files
|
4
|
+
module Qonf
|
5
|
+
@@cache = {} # note, we're caching the config in memory
|
6
|
+
@@environments = Dir.glob("./config/environments/*.rb").map { |filename| File.basename(filename, ".rb") } # for extraction
|
7
|
+
|
8
|
+
# Qonf.name -> Qonf.get(:qonf, [:name]) for quick short-hand
|
9
|
+
def self.method_missing(method)
|
10
|
+
self.get(:qonf, method)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.[](item)
|
14
|
+
Figaro.env[item.to_s.upcase] || self.get(:qonf, item.to_s.downcase)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get(config, route=[])
|
18
|
+
route = [route] if route.is_a?(Symbol) || route.is_a?(String)
|
19
|
+
raise "Invalid config" unless config =~ /^\w+$/
|
20
|
+
config = config.to_sym
|
21
|
+
|
22
|
+
if !Rails.env.development? && @@cache[config.to_sym] # don't cache in development
|
23
|
+
|
24
|
+
else
|
25
|
+
base_path = "#{Rails.root}/config/#{config}"
|
26
|
+
|
27
|
+
formats = {
|
28
|
+
yml: ->(f){ YAML.load(f) },
|
29
|
+
json: ->(f){ JSON(f.read) }
|
30
|
+
}
|
31
|
+
|
32
|
+
formats.each do |ext,parser|
|
33
|
+
if File.exists?("#{base_path}.#{ext}")
|
34
|
+
cache = parser.call(File.open("#{base_path}.#{ext}"))
|
35
|
+
raise "Invalid Qonf; must be hash" unless cache.is_a?(Hash)
|
36
|
+
cache = cache.deep_symbolize_keys! # Let's do this as symbols
|
37
|
+
cache.deep_merge!(cache.delete(Rails.env.to_sym)) if cache.has_key?(Rails.env.to_sym) # Now merge anything under current env
|
38
|
+
@@environments.each { |env| cache.delete(env.to_sym) } # And remove any other env keys
|
39
|
+
|
40
|
+
@@cache[config.to_sym] = cache # Store
|
41
|
+
|
42
|
+
break # And exit
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
raise "Unable to find config for #{config} in #{Rails.root}/config/*.{#{formats.keys.join(',')}}" if @@cache[config.to_sym].nil?
|
47
|
+
end
|
48
|
+
|
49
|
+
return get_route(@@cache[config.to_sym], route)
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.reset!
|
53
|
+
@@cache = {} # Clear the cache
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def self.get_route(hash, route)
|
59
|
+
return hash if route.nil? || route.length == 0
|
60
|
+
raise "Unable to get route (#{route}) in Qonf, please check config file" unless hash.is_a?(Hash)
|
61
|
+
# TODO: Do we want to accept _ for -?
|
62
|
+
return Qonf.get_route(hash[route.shift.to_sym], route) # Recursive, yo!
|
63
|
+
end
|
64
|
+
end
|
data/qonf.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'qonf/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "qonf"
|
8
|
+
spec.version = Qonf::VERSION
|
9
|
+
spec.authors = ["Geoff Hayes"]
|
10
|
+
spec.email = ["hayesgm@gmail.com"]
|
11
|
+
spec.description = %q{Qonf is a simple configuration management tool}
|
12
|
+
spec.summary = %q{Simplest use case, add config/qonf.json or config/qonf.yaml and call Qonf.key to pull key from config file. And much more.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'figaro'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: qonf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Geoff Hayes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: figaro
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Qonf is a simple configuration management tool
|
56
|
+
email:
|
57
|
+
- hayesgm@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/qonf.rb
|
68
|
+
- lib/qonf/version.rb
|
69
|
+
- qonf.gemspec
|
70
|
+
homepage: ''
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.1.11
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Simplest use case, add config/qonf.json or config/qonf.yaml and call Qonf.key
|
94
|
+
to pull key from config file. And much more.
|
95
|
+
test_files: []
|