app_konfig 0.0.1 → 0.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 +4 -4
- data/.rspec +2 -0
- data/CHANGELOG.MD +6 -0
- data/README.md +11 -1
- data/app_konfig.gemspec +4 -3
- data/config/config.yml +15 -0
- data/config/secrets.yml +6 -0
- data/lib/app_konfig/config.rb +42 -0
- data/lib/app_konfig/version.rb +1 -1
- data/lib/app_konfig.rb +2 -36
- data/spec/app_konfig_spec.rb +43 -0
- data/spec/spec_helper.rb +9 -0
- metadata +31 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acc70f7bfa0cce596647ce885058b92dd7f213b9
|
4
|
+
data.tar.gz: c9dd25965b13dc90aacc2e9f1af645b6a8373e40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e095dd35cde544a0a8dbb1546b7ff02ed548940519c9c30e2ab466af512b2a4deccde90f84234e0293646e64a62295c174f18148ef074e5e787c2e6f6d9d0757
|
7
|
+
data.tar.gz: c8cce7af00dd510bcd93d33d042e862b5ab62c82032966ecf18c0f2964074f2ac2098fcc330e69cedf78f15e2f40fff58453b8b826036fcb6200025bb79b1cc2
|
data/.rspec
ADDED
data/CHANGELOG.MD
ADDED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# AppKonfig
|
2
2
|
|
3
|
-
Lightweight app configuration for Rails
|
3
|
+
Lightweight app configuration for Rails >= 3.0
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -21,14 +21,23 @@ In `config/config.yml`:
|
|
21
21
|
```yaml
|
22
22
|
development:
|
23
23
|
value: 1
|
24
|
+
proxy:
|
25
|
+
ip: 127.0.0.1
|
26
|
+
port: 8080
|
24
27
|
secret_key: DEV_TOKEN
|
25
28
|
|
26
29
|
test:
|
27
30
|
value: 2
|
31
|
+
proxy:
|
32
|
+
ip: 127.0.0.1
|
33
|
+
port: 8080
|
28
34
|
secret_key: TEST_TOKEN
|
29
35
|
|
30
36
|
production:
|
31
37
|
value: 3
|
38
|
+
proxy:
|
39
|
+
ip: 10.0.0.10
|
40
|
+
port: 8080
|
32
41
|
```
|
33
42
|
|
34
43
|
In `config/secrets.yml`: (optional, not included in version control)
|
@@ -40,6 +49,7 @@ production:
|
|
40
49
|
Anywhere in the app:
|
41
50
|
```ruby
|
42
51
|
AppConfig.value
|
52
|
+
AppConfig.proxy.ip
|
43
53
|
AppConfig.secret_key
|
44
54
|
```
|
45
55
|
|
data/app_konfig.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'app_konfig/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "app_konfig"
|
8
8
|
spec.version = AppKonfig::VERSION
|
9
|
-
spec.authors = ["Bartosz Kopiński"]
|
10
|
-
spec.email = ["bartosz@kopinski.pl"]
|
9
|
+
spec.authors = ["Bartosz Kopiński", "Radosław Piątek"]
|
10
|
+
spec.email = ["bartosz@kopinski.pl", "radek.nekath@gmail.com"]
|
11
11
|
spec.summary = "Lightweight app configuration for Rails"
|
12
12
|
spec.homepage = "https://github.com/netguru/app_konfig"
|
13
13
|
spec.license = "MIT"
|
@@ -17,7 +17,8 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency "activesupport", ">= 3.
|
20
|
+
spec.add_dependency "activesupport", ">= 3.0"
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.7"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
23
24
|
end
|
data/config/config.yml
ADDED
data/config/secrets.yml
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'active_support/core_ext/hash/deep_merge'
|
2
|
+
require 'yaml'
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
module AppKonfig
|
6
|
+
class Config < Hash
|
7
|
+
DEFAULT_ENV = 'development'
|
8
|
+
CONFIG_PATH = {
|
9
|
+
public: './config/config.yml',
|
10
|
+
secret: './config/secrets.yml',
|
11
|
+
}
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
super
|
15
|
+
deep_merge!(pub_config).deep_merge!(sec_config)
|
16
|
+
end
|
17
|
+
|
18
|
+
def method_missing(key)
|
19
|
+
key = key.to_s
|
20
|
+
return self[key] unless self[key].is_a?(Hash)
|
21
|
+
::AppKonfig::Config[self[key]]
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def pub_config
|
27
|
+
load_config(CONFIG_PATH[:public])
|
28
|
+
end
|
29
|
+
|
30
|
+
def sec_config
|
31
|
+
load_config(CONFIG_PATH[:secret]) rescue {}
|
32
|
+
end
|
33
|
+
|
34
|
+
def load_config(path)
|
35
|
+
YAML.load(ERB.new(File.read(path)).result).fetch(env)
|
36
|
+
end
|
37
|
+
|
38
|
+
def env
|
39
|
+
ENV.fetch('RAILS_ENV'){ DEFAULT_ENV }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/app_konfig/version.rb
CHANGED
data/lib/app_konfig.rb
CHANGED
@@ -1,38 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require "erb"
|
4
|
-
|
5
|
-
require "app_konfig/version"
|
6
|
-
|
7
|
-
module AppKonfig
|
8
|
-
class Config < ActiveSupport::OrderedOptions
|
9
|
-
DEFAULT_ENV = "development"
|
10
|
-
CONFIG_PATH = {
|
11
|
-
public: './config/config.yml',
|
12
|
-
secret: './config/secrets.yml',
|
13
|
-
}
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
super
|
17
|
-
deep_merge!(pub_config).deep_merge!(sec_config)
|
18
|
-
end
|
19
|
-
|
20
|
-
def pub_config
|
21
|
-
load_config(CONFIG_PATH[:public])
|
22
|
-
end
|
23
|
-
|
24
|
-
def sec_config
|
25
|
-
load_config(CONFIG_PATH[:secret]) rescue {}
|
26
|
-
end
|
27
|
-
|
28
|
-
def load_config path
|
29
|
-
YAML.load(ERB.new(File.read(path)).result).fetch(env)
|
30
|
-
end
|
31
|
-
|
32
|
-
def env
|
33
|
-
ENV.fetch("RAILS_ENV"){ DEFAULT_ENV }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
1
|
+
require 'app_konfig/version'
|
2
|
+
require 'app_konfig/config'
|
37
3
|
|
38
4
|
AppConfig = AppKonfig::Config.new
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'app_konfig/config'
|
3
|
+
|
4
|
+
RSpec.describe AppKonfig::Config do
|
5
|
+
it 'is a Hash' do
|
6
|
+
expect(subject).to be_a(Hash)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'loads config based on RAILS_ENV' do
|
10
|
+
allow(ENV).to receive(:fetch).and_return('test')
|
11
|
+
expect(subject.hostname).to eq('test.example.com')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'uses development config by default' do
|
15
|
+
expect(described_class::DEFAULT_ENV).to eq('development')
|
16
|
+
expect(subject.hostname).to eq('example.com')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'handles nested keys' do
|
20
|
+
expect(subject.proxy.port).to eq(3000)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'merges config from secrets file' do
|
24
|
+
allow(ENV).to receive(:fetch).and_return('production')
|
25
|
+
expect(subject.hostname).to eq('production.example.com')
|
26
|
+
expect(subject.array_key).to eq(['first_new', 'second_new', 'third_new'])
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'allows to embed ruby inside a config file' do
|
30
|
+
allow(ENV).to receive(:[]).with('SECRET_KEY').and_return('value_from_env')
|
31
|
+
expect(subject.secret_key).to eq('value_from_env')
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when secrets file is not found' do
|
35
|
+
it 'fails silently' do
|
36
|
+
stub_const('AppKonfig::Config::CONFIG_PATH', {
|
37
|
+
public: './config/config.yml',
|
38
|
+
secret: '',
|
39
|
+
})
|
40
|
+
expect{ subject }.not_to raise_error
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: app_konfig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bartosz Kopiński
|
8
|
+
- Radosław Piątek
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2015-
|
12
|
+
date: 2015-09-05 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: activesupport
|
@@ -16,14 +17,14 @@ dependencies:
|
|
16
17
|
requirements:
|
17
18
|
- - ">="
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3.
|
20
|
+
version: '3.0'
|
20
21
|
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
25
|
- - ">="
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version: '3.
|
27
|
+
version: '3.0'
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
29
|
name: bundler
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,22 +53,44 @@ dependencies:
|
|
52
53
|
- - "~>"
|
53
54
|
- !ruby/object:Gem::Version
|
54
55
|
version: '10.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.3'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.3'
|
55
70
|
description:
|
56
71
|
email:
|
57
72
|
- bartosz@kopinski.pl
|
73
|
+
- radek.nekath@gmail.com
|
58
74
|
executables: []
|
59
75
|
extensions: []
|
60
76
|
extra_rdoc_files: []
|
61
77
|
files:
|
62
78
|
- ".gitignore"
|
79
|
+
- ".rspec"
|
63
80
|
- ".ruby-version"
|
81
|
+
- CHANGELOG.MD
|
64
82
|
- Gemfile
|
65
83
|
- LICENSE.txt
|
66
84
|
- README.md
|
67
85
|
- Rakefile
|
68
86
|
- app_konfig.gemspec
|
87
|
+
- config/config.yml
|
88
|
+
- config/secrets.yml
|
69
89
|
- lib/app_konfig.rb
|
90
|
+
- lib/app_konfig/config.rb
|
70
91
|
- lib/app_konfig/version.rb
|
92
|
+
- spec/app_konfig_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
71
94
|
homepage: https://github.com/netguru/app_konfig
|
72
95
|
licenses:
|
73
96
|
- MIT
|
@@ -88,9 +111,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
111
|
version: '0'
|
89
112
|
requirements: []
|
90
113
|
rubyforge_project:
|
91
|
-
rubygems_version: 2.4.
|
114
|
+
rubygems_version: 2.4.6
|
92
115
|
signing_key:
|
93
116
|
specification_version: 4
|
94
117
|
summary: Lightweight app configuration for Rails
|
95
|
-
test_files:
|
96
|
-
|
118
|
+
test_files:
|
119
|
+
- spec/app_konfig_spec.rb
|
120
|
+
- spec/spec_helper.rb
|