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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e1beb7cc3fb94c0ee429c119367f0f178e94c82
4
- data.tar.gz: 1736fb7476e641fa00b1475e178b2cf906199db3
3
+ metadata.gz: acc70f7bfa0cce596647ce885058b92dd7f213b9
4
+ data.tar.gz: c9dd25965b13dc90aacc2e9f1af645b6a8373e40
5
5
  SHA512:
6
- metadata.gz: 5a31a9e27f8fa7df33a60cfac1401a3d6206246c471f55e67a92e5b56c156a5f4fe297002b93fe10bafe75116714d96deff052bfcdb9f2d58a6b5dea8a1a18d5
7
- data.tar.gz: 2d1056801936125a3171d254642d26bf8da547c7195376d5fbb6bd4db9229cab865c22799a9e65750818781c26f91064ca509f0d791201a7d85b00ec105a16f2
6
+ metadata.gz: e095dd35cde544a0a8dbb1546b7ff02ed548940519c9c30e2ab466af512b2a4deccde90f84234e0293646e64a62295c174f18148ef074e5e787c2e6f6d9d0757
7
+ data.tar.gz: c8cce7af00dd510bcd93d33d042e862b5ab62c82032966ecf18c0f2964074f2ac2098fcc330e69cedf78f15e2f40fff58453b8b826036fcb6200025bb79b1cc2
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/CHANGELOG.MD ADDED
@@ -0,0 +1,6 @@
1
+ 0.1.0
2
+
3
+ - Lessen rails dependency - minimal version is now 3.0 (@nekath)
4
+ - Add tests (@nekath)
5
+ - Keep config keys as strings (@nekath)
6
+ - Improve readme (@nekath)
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.2"
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
@@ -0,0 +1,15 @@
1
+ development:
2
+ proxy:
3
+ port: 3000
4
+ hostname: example.com
5
+ secret_key: <%= ENV["SECRET_KEY"] %>
6
+ array_key:
7
+ - first
8
+ - second
9
+ - third
10
+
11
+ test:
12
+ hostname: test.example.com
13
+
14
+ production:
15
+ hostname: ''
@@ -0,0 +1,6 @@
1
+ production:
2
+ hostname: 'production.example.com'
3
+ array_key:
4
+ - first_new
5
+ - second_new
6
+ - third_new
@@ -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
@@ -1,3 +1,3 @@
1
1
  module AppKonfig
2
- VERSION = "0.0.1"
2
+ VERSION = '0.1.0'.freeze
3
3
  end
data/lib/app_konfig.rb CHANGED
@@ -1,38 +1,4 @@
1
- require "active_support/ordered_options"
2
- require "yaml"
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
@@ -0,0 +1,9 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |expectations|
3
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
4
+ end
5
+
6
+ config.mock_with :rspec do |mocks|
7
+ mocks.verify_partial_doubles = true
8
+ end
9
+ end
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.1
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-03-03 00:00:00.000000000 Z
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.2'
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.2'
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.5
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
- has_rdoc:
118
+ test_files:
119
+ - spec/app_konfig_spec.rb
120
+ - spec/spec_helper.rb