anyway_config 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -1
- data/Rakefile +5 -1
- data/anyway_config.gemspec +2 -0
- data/lib/anyway/config.rb +12 -11
- data/lib/anyway/rails/config.rb +25 -0
- data/lib/anyway/version.rb +1 -1
- data/lib/anyway.rb +5 -1
- data/spec/anyway.yml +2 -0
- data/spec/config_spec.rb +0 -18
- data/spec/config_spec_norails.rb +43 -0
- data/spec/dummy.yml +0 -0
- data/spec/spec_helper.rb +1 -5
- data/spec/spec_norails_helper.rb +13 -0
- metadata +20 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19177bb68f7f250550ee553fb36c41f33fe181b7
|
4
|
+
data.tar.gz: f6fa6a2cb3f29c3434a0c8f660c97adc74a3f6d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1b58e60a43d24867f9a6e81a4ea032ac94b373592638b150001aa8e105e51dea2289bc84acd2edece19a1956f369c1ec522b62adcd81600b0001a8190e5a936
|
7
|
+
data.tar.gz: 164ea5df4fe0444e6f3e64df243c7602c2c0dbaf5615442c19246e20f75bedf3ba0a662028831eb11852f726109aa3e1fd5546570e3cee0889f3282551c1a8c7
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# Anyway Config
|
4
4
|
|
5
|
-
Rails plugin/application configuration using any source: YAML, _secrets_, environment.
|
5
|
+
Rails/Ruby plugin/application configuration using any source: YAML, _secrets_, environment.
|
6
6
|
|
7
7
|
|
8
8
|
Apps using Anyway Config:
|
@@ -98,6 +98,7 @@ Rails 4.2 introduces new feature: `Rails.application.config_for`. It looks very
|
|
98
98
|
| raise errors if file doesn't exist | yes | no |
|
99
99
|
|
100
100
|
But the main advantage of Anyway::Config is that it's supported in Rails >= 3.2, Ruby >= 1.9.3.
|
101
|
+
And it can be even used [without Rails](#using-without-rails)!
|
101
102
|
|
102
103
|
## How to set env vars
|
103
104
|
|
@@ -108,6 +109,10 @@ For example, if your module is called "MyCoolGem" then your env var "MYCOOLGEM_P
|
|
108
109
|
*Anyway Config* supports nested (_hashed_) environmental variables. Just separate keys with double-underscore.
|
109
110
|
For example, "MYCOOLGEM_OPTIONS__VERBOSE" is transformed to `config.options.verbose`.
|
110
111
|
|
112
|
+
## Using without Rails
|
113
|
+
|
114
|
+
AnywayConfig can be used without Rails too.
|
115
|
+
Environmental variables remain the same. To load config from YAML add special environment variable 'MYGEM_CONF' containing path to config. But you cannot use one file for different environments (unless you do it yourself).
|
111
116
|
|
112
117
|
## Contributing
|
113
118
|
|
data/Rakefile
CHANGED
data/anyway_config.gemspec
CHANGED
@@ -17,6 +17,8 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
s.required_ruby_version = '>= 1.9.3'
|
19
19
|
|
20
|
+
s.add_dependency "activesupport", ">= 3.2"
|
21
|
+
|
20
22
|
s.add_development_dependency 'pry'
|
21
23
|
s.add_development_dependency "simplecov", ">= 0.3.8"
|
22
24
|
s.add_development_dependency "rspec", "~> 3.0.0"
|
data/lib/anyway/config.rb
CHANGED
@@ -56,19 +56,20 @@ module Anyway
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def load_from_sources(config={}.with_indifferent_access)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
require 'yaml'
|
63
|
-
config.deep_merge! (YAML.load_file(config_path)[Rails.env] || {})
|
64
|
-
end
|
59
|
+
load_from_file(config)
|
60
|
+
load_from_env(config)
|
61
|
+
end
|
65
62
|
|
66
|
-
|
67
|
-
|
68
|
-
|
63
|
+
def load_from_file(config)
|
64
|
+
config_path = (Anyway.env.send(@config_name)||{}).delete(:conf)
|
65
|
+
if config_path and File.file?(config_path)
|
66
|
+
require 'yaml'
|
67
|
+
config.deep_merge! (YAML.load_file(config_path) || {})
|
69
68
|
end
|
70
|
-
|
71
|
-
|
69
|
+
config
|
70
|
+
end
|
71
|
+
|
72
|
+
def load_from_env(config)
|
72
73
|
config.deep_merge! (Anyway.env.send(@config_name) || {})
|
73
74
|
config
|
74
75
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Anyway
|
2
|
+
class Config
|
3
|
+
def load_from_sources(config={}.with_indifferent_access)
|
4
|
+
load_from_file(config)
|
5
|
+
load_from_secrets(config)
|
6
|
+
load_from_env(config)
|
7
|
+
end
|
8
|
+
|
9
|
+
def load_from_file(config)
|
10
|
+
config_path = Rails.root.join("config","#{@config_name}.yml")
|
11
|
+
if File.file? config_path
|
12
|
+
require 'yaml'
|
13
|
+
config.deep_merge! (YAML.load_file(config_path)[Rails.env] || {})
|
14
|
+
end
|
15
|
+
config
|
16
|
+
end
|
17
|
+
|
18
|
+
def load_from_secrets(config)
|
19
|
+
if Rails.application.respond_to?(:secrets)
|
20
|
+
config.deep_merge! (Rails.application.secrets.send(@config_name)||{})
|
21
|
+
end
|
22
|
+
config
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/anyway/version.rb
CHANGED
data/lib/anyway.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require 'active_support/core_ext/hash'
|
2
|
+
require 'active_support/core_ext/string'
|
3
|
+
require 'active_support/core_ext/object'
|
2
4
|
|
5
|
+
require "anyway/version"
|
3
6
|
module Anyway
|
4
7
|
require "anyway/config"
|
8
|
+
require "anyway/rails/config" if defined?(Rails)
|
5
9
|
require "anyway/env"
|
6
10
|
|
7
11
|
def self.env
|
data/spec/anyway.yml
ADDED
data/spec/config_spec.rb
CHANGED
@@ -79,24 +79,6 @@ describe Anyway::Config do
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
describe "config with default name" do
|
83
|
-
after(:each) { Anyway.env.clear }
|
84
|
-
specify { expect(Anyway::TestConfig.config_name).to eq "anyway" }
|
85
|
-
|
86
|
-
specify do
|
87
|
-
expect(test_conf).to respond_to(:test)
|
88
|
-
expect(test_conf).to respond_to(:api)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should work" do
|
92
|
-
ENV['ANYWAY_API__KEY'] = 'test1'
|
93
|
-
ENV['ANYWAY_TEST'] = 'test'
|
94
|
-
Anyway.env.reload
|
95
|
-
expect(test_conf.api[:key]).to eq "test1"
|
96
|
-
expect(test_conf.test).to eq "test"
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
82
|
describe "config for name" do
|
101
83
|
after(:each) { Anyway.env.clear }
|
102
84
|
it "should load data by config name" do
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_norails_helper'
|
2
|
+
|
3
|
+
describe Anyway::Config do
|
4
|
+
|
5
|
+
let(:conf) { Anyway::TestConfig.new }
|
6
|
+
|
7
|
+
describe "config without Rails" do
|
8
|
+
after(:each) { Anyway.env.clear }
|
9
|
+
specify { expect(Anyway::TestConfig.config_name).to eq "anyway" }
|
10
|
+
|
11
|
+
specify do
|
12
|
+
expect(conf).to respond_to(:test)
|
13
|
+
expect(conf).to respond_to(:api)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should work" do
|
17
|
+
ENV['ANYWAY_CONF'] = File.join(File.dirname(__FILE__),"anyway.yml")
|
18
|
+
ENV['ANYWAY_API__KEY'] = 'test1'
|
19
|
+
ENV['ANYWAY_TEST'] = 'test'
|
20
|
+
|
21
|
+
Anyway.env.reload
|
22
|
+
expect(conf.api[:key]).to eq "test1"
|
23
|
+
expect(conf.api[:endpoint]).to eq "localhost"
|
24
|
+
expect(conf.test).to eq "test"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should reload config" do
|
28
|
+
expect(conf.api[:key]).to eq ""
|
29
|
+
expect(conf.api[:endpoint]).to be_nil
|
30
|
+
expect(conf.test).to be_nil
|
31
|
+
|
32
|
+
ENV['ANYWAY_CONF'] = File.join(File.dirname(__FILE__),"anyway.yml")
|
33
|
+
ENV['ANYWAY_API__KEY'] = 'test1'
|
34
|
+
ENV['ANYWAY_TEST'] = 'test'
|
35
|
+
Anyway.env.reload
|
36
|
+
|
37
|
+
conf.reload
|
38
|
+
expect(conf.api[:key]).to eq "test1"
|
39
|
+
expect(conf.api[:endpoint]).to eq "localhost"
|
40
|
+
expect(conf.test).to eq "test"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/dummy.yml
ADDED
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -3,17 +3,13 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
3
|
|
4
4
|
ENV["RAILS_ENV"] ||= 'test'
|
5
5
|
|
6
|
-
# require 'simplecov'
|
7
|
-
# SimpleCov.root File.join(File.dirname(__FILE__), '..', 'lib')
|
8
|
-
# SimpleCov.start
|
9
|
-
|
10
6
|
require 'rspec'
|
11
7
|
require 'pry'
|
12
|
-
require 'anyway'
|
13
8
|
|
14
9
|
require 'rails/all'
|
15
10
|
require 'rspec/rails'
|
16
11
|
|
12
|
+
require 'anyway'
|
17
13
|
require "dummy/config/environment"
|
18
14
|
|
19
15
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
require 'rspec'
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
require 'anyway'
|
8
|
+
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.mock_with :rspec
|
13
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anyway_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vlad Dem
|
@@ -10,6 +10,20 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: pry
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,8 +101,12 @@ files:
|
|
87
101
|
- lib/anyway.rb
|
88
102
|
- lib/anyway/config.rb
|
89
103
|
- lib/anyway/env.rb
|
104
|
+
- lib/anyway/rails/config.rb
|
90
105
|
- lib/anyway/version.rb
|
106
|
+
- spec/anyway.yml
|
91
107
|
- spec/config_spec.rb
|
108
|
+
- spec/config_spec_norails.rb
|
109
|
+
- spec/dummy.yml
|
92
110
|
- spec/dummy/README.rdoc
|
93
111
|
- spec/dummy/Rakefile
|
94
112
|
- spec/dummy/app/assets/images/.keep
|
@@ -134,6 +152,7 @@ files:
|
|
134
152
|
- spec/dummy/public/favicon.ico
|
135
153
|
- spec/env_spec.rb
|
136
154
|
- spec/spec_helper.rb
|
155
|
+
- spec/spec_norails_helper.rb
|
137
156
|
- spec/support/cool_config.rb
|
138
157
|
- spec/support/test_config.rb
|
139
158
|
homepage: http://github.com/palkan/anyway_config
|