envconfig 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/.rspec +1 -0
- data/.travis.yml +9 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +67 -0
- data/Rakefile +32 -0
- data/envconfig-rails.gemspec +19 -0
- data/envconfig.gemspec +23 -0
- data/lib/envconfig/provider.rb +65 -0
- data/lib/envconfig/railtie.rb +22 -0
- data/lib/envconfig/service.rb +31 -0
- data/lib/envconfig/smtp.rb +84 -0
- data/lib/envconfig/version.rb +3 -0
- data/lib/envconfig-rails.rb +3 -0
- data/lib/envconfig.rb +28 -0
- data/spec/provider_resolver_spec.rb +46 -0
- data/spec/root_spec.rb +29 -0
- data/spec/smtp_spec.rb +91 -0
- data/spec/spec_helper.rb +1 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fff31b686ded3d76596b2b14c6ebd4237e596d34
|
4
|
+
data.tar.gz: 2ef7f44560eaae47bd7c3e83f2f6a58d2fd2f733
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7db87aea796a5b24fed2e68ca338e65c3ea0788f266b0fbd6213900eb7b85e99a02701907f32ae07ad87e89571334055274dc2040facc4c0425bbd2598542a03
|
7
|
+
data.tar.gz: 14ce9eb3c94e044c61bc57c058c7cef00d5c3605b514adfe14fe773a36069a3ce7391d6493e4e23c9571a34c7c00dd2b9f8c51cf415f8a32d389aef6f1112b09
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Paul Annesley
|
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,67 @@
|
|
1
|
+
# envconfig
|
2
|
+
|
3
|
+
Connect your Rails app to backing services via ENV vars such as those
|
4
|
+
provided by [Broadstack][broadstack] or [Heroku Addons][heroku_addons].
|
5
|
+
|
6
|
+
envconfig gathers ENV configuration from known add-on providers, exposes them
|
7
|
+
as a consistent configuration interface, and configures your Rails application
|
8
|
+
via initializers.
|
9
|
+
|
10
|
+
For example if your ENV contains the follow:
|
11
|
+
|
12
|
+
```
|
13
|
+
POSTMARK_SMTP_SERVER="smtp.example.org"
|
14
|
+
POSTMARK_API_KEY="bcca0a78abbaed6533f3c8017b804bda"
|
15
|
+
```
|
16
|
+
|
17
|
+
Then envconfig's SMTP configuration will look like this:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
Envconfig.load(ENV).smtp.to_h # =>
|
21
|
+
{
|
22
|
+
"address" => "smtp.example.org",
|
23
|
+
"port" => 25,
|
24
|
+
"username" => "bcca0a78abbaed6533f3c8017b804bda",
|
25
|
+
"password" => "bcca0a78abbaed6533f3c8017b804bda",
|
26
|
+
}
|
27
|
+
```
|
28
|
+
|
29
|
+
And `ActionMailer` will be auto-configured accordingly.
|
30
|
+
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
Add `gem "envconfig"` to your Gemfile and run `bundle`,
|
35
|
+
or `gem install envconfig`.
|
36
|
+
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
Add `envconfig-rails` to your `Gemfile` and go.
|
41
|
+
|
42
|
+
If you're not using Rails, add the base `envconfig` gem, and access the
|
43
|
+
normalized configuration directly.
|
44
|
+
|
45
|
+
|
46
|
+
## Supported Add-ons
|
47
|
+
|
48
|
+
### SMTP
|
49
|
+
|
50
|
+
* Postmark ([Broadstack](https://broadstack.com/addons/postmark), [Heroku](https://addons.heroku.com/postmark))
|
51
|
+
* Mandrill ([Heroku](https://addons.heroku.com/mandrill))
|
52
|
+
* SendGrid ([Heroku](https://addons.heroku.com/sendgrid))
|
53
|
+
* Custom (`SMTP_HOST`, `SMTP_PORT`, `SMTP_USERNAME`, `SMTP_PASSWORD` in `ENV`)
|
54
|
+
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
1. Fork it
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
5. Create new Pull Request
|
63
|
+
|
64
|
+
|
65
|
+
[backing_services]: http://12factor.net/backing-services
|
66
|
+
[broadstack]: https://broadstack.com
|
67
|
+
[heroku_addons]: https://addons.heroku.com/
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# This entire Rakefile (at time of writing), and the general model
|
2
|
+
# of multiple gemspecs in one project, was lifted from bkeepers/dotenv.
|
3
|
+
# See: https://github.com/bkeepers/dotenv/blob/master/Rakefile
|
4
|
+
|
5
|
+
require "bundler/gem_helper"
|
6
|
+
|
7
|
+
namespace "envconfig" do
|
8
|
+
Bundler::GemHelper.install_tasks :name => "envconfig"
|
9
|
+
end
|
10
|
+
|
11
|
+
namespace "envconfig-rails" do
|
12
|
+
class EnvconfigRailsGemHelper < Bundler::GemHelper
|
13
|
+
def guard_already_tagged; end # noop
|
14
|
+
def tag_version; end # noop
|
15
|
+
end
|
16
|
+
|
17
|
+
EnvconfigRailsGemHelper.install_tasks :name => "envconfig-rails"
|
18
|
+
end
|
19
|
+
|
20
|
+
task :build => ["envconfig:build", "envconfig-rails:build"]
|
21
|
+
task :install => ["envconfig:install", "envconfig-rails:install"]
|
22
|
+
task :release => ["envconfig:release", "envconfig-rails:release"]
|
23
|
+
|
24
|
+
require "rspec/core/rake_task"
|
25
|
+
|
26
|
+
desc "Run all specs"
|
27
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
28
|
+
t.rspec_opts = %w[--color]
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
task :default => :spec
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'envconfig/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "envconfig-rails"
|
8
|
+
spec.version = Envconfig::VERSION
|
9
|
+
spec.authors = ["Paul Annesley"]
|
10
|
+
spec.email = ["paul@annesley.cc"]
|
11
|
+
spec.summary = %q{Auto-configure Rails from ENV vars via envconfig.}
|
12
|
+
spec.homepage = "https://github.com/broadstack/envconfig"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = ["lib/envconfig-rails.rb"]
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_dependency "envconfig", Envconfig::VERSION
|
19
|
+
end
|
data/envconfig.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'envconfig/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "envconfig"
|
8
|
+
spec.version = Envconfig::VERSION
|
9
|
+
spec.authors = ["Paul Annesley"]
|
10
|
+
spec.email = ["paul@annesley.cc"]
|
11
|
+
spec.summary = %q{Connect your app to backing services via Broadstack/Heroku-style ENV vars.}
|
12
|
+
spec.homepage = "https://github.com/broadstack/envconfig"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
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.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Envconfig
|
2
|
+
module Provider
|
3
|
+
|
4
|
+
def self.find(env, providers)
|
5
|
+
providers.map { |k| k.new(env) }.detect(&:valid?) ||
|
6
|
+
NullProvider.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(env)
|
10
|
+
@env = env
|
11
|
+
end
|
12
|
+
|
13
|
+
# A mapping of configuration keys to environment keys.
|
14
|
+
# e.g.
|
15
|
+
# {
|
16
|
+
# address: "PROVIDER_HOSTNAME",
|
17
|
+
# password: "PROVIDER_API_KEY",
|
18
|
+
# }
|
19
|
+
def mapping
|
20
|
+
raise "Mapping must be implemented by subclass."
|
21
|
+
end
|
22
|
+
|
23
|
+
# Static configuration which doesn't vary by environment.
|
24
|
+
# e.g. hostname / port.
|
25
|
+
def static
|
26
|
+
{}
|
27
|
+
end
|
28
|
+
|
29
|
+
def name
|
30
|
+
self.class.name.split("::").last
|
31
|
+
end
|
32
|
+
|
33
|
+
# Whether the environment is valid for this provider.
|
34
|
+
def valid?
|
35
|
+
env_keys.all? { |k| env.key?(k) }
|
36
|
+
end
|
37
|
+
|
38
|
+
# Which ENV keys are used by this provider.
|
39
|
+
def env_keys
|
40
|
+
mapping.values
|
41
|
+
end
|
42
|
+
|
43
|
+
# The configuration derived from the environment for this provider.
|
44
|
+
def config
|
45
|
+
static.merge(dynamic)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
attr_reader :env
|
51
|
+
|
52
|
+
def dynamic
|
53
|
+
mapping.inject({}) do |result, (result_key, env_key)|
|
54
|
+
result[result_key] = env[env_key] if env.key?(env_key)
|
55
|
+
result
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class NullProvider
|
60
|
+
def config; {} end
|
61
|
+
def name; nil; end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "envconfig"
|
2
|
+
|
3
|
+
module Envconfig
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
|
6
|
+
envconfig = Envconfig.load(ENV)
|
7
|
+
|
8
|
+
initializer "envconfig.smtp" do |app|
|
9
|
+
if envconfig.smtp?
|
10
|
+
envconfig_log "Using #{envconfig.smtp.provider.name} for SMTP"
|
11
|
+
app.config.action_mailer.smtp_settings = envconfig.smtp.to_h
|
12
|
+
else
|
13
|
+
envconfig_log "SMTP not configured"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def envconfig_log(message)
|
18
|
+
Rails.logger.info("Envconfig: #{message}")
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Envconfig
|
2
|
+
module Service
|
3
|
+
|
4
|
+
def initialize(env)
|
5
|
+
@env = env
|
6
|
+
end
|
7
|
+
|
8
|
+
# The configuration for the service, as a Hash.
|
9
|
+
def to_h
|
10
|
+
config
|
11
|
+
end
|
12
|
+
|
13
|
+
# A single key from the configuration.
|
14
|
+
def [](key)
|
15
|
+
config[key]
|
16
|
+
end
|
17
|
+
|
18
|
+
def provider
|
19
|
+
@_provider ||= Provider.find(env, self.class.providers)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :env
|
25
|
+
|
26
|
+
def config
|
27
|
+
@_config ||= provider.config
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Envconfig
|
2
|
+
class Smtp
|
3
|
+
|
4
|
+
include Service
|
5
|
+
|
6
|
+
def self.providers
|
7
|
+
[
|
8
|
+
Custom,
|
9
|
+
Mandrill,
|
10
|
+
Postmark,
|
11
|
+
Sendgrid,
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
15
|
+
# A custom configuration, for local or self-managed SMTP servers.
|
16
|
+
class Custom
|
17
|
+
include Provider
|
18
|
+
def valid?
|
19
|
+
mapping.values.any? { |k| env.key?(k) } #any? instead of #all?
|
20
|
+
end
|
21
|
+
def mapping
|
22
|
+
{
|
23
|
+
address: "SMTP_HOST",
|
24
|
+
port: "SMTP_PORT",
|
25
|
+
user_name: "SMTP_USERNAME",
|
26
|
+
password: "SMTP_PASSWORD",
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Mandrill
|
32
|
+
include Provider
|
33
|
+
def mapping
|
34
|
+
{
|
35
|
+
user_name: "MANDRILL_USERNAME",
|
36
|
+
password: "MANDRILL_APIKEY",
|
37
|
+
}
|
38
|
+
end
|
39
|
+
def static
|
40
|
+
{
|
41
|
+
address: "smtp.mandrillapp.com",
|
42
|
+
port: "25",
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class Postmark
|
48
|
+
include Provider
|
49
|
+
def mapping
|
50
|
+
{
|
51
|
+
address: "POSTMARK_SMTP_SERVER",
|
52
|
+
user_name: "POSTMARK_API_KEY",
|
53
|
+
password: "POSTMARK_API_KEY",
|
54
|
+
}
|
55
|
+
end
|
56
|
+
def static
|
57
|
+
{
|
58
|
+
port: "25",
|
59
|
+
authentication: :plain,
|
60
|
+
}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class Sendgrid
|
65
|
+
include Provider
|
66
|
+
def name; "SendGrid" end
|
67
|
+
def mapping
|
68
|
+
{
|
69
|
+
user_name: "SENDGRID_USERNAME",
|
70
|
+
password: "SENDGRID_PASSWORD",
|
71
|
+
}
|
72
|
+
end
|
73
|
+
def static
|
74
|
+
{
|
75
|
+
address: "smtp.sendgrid.net",
|
76
|
+
port: "587",
|
77
|
+
authentication: :plain,
|
78
|
+
enable_starttls_auto: true
|
79
|
+
}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
data/lib/envconfig.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "envconfig/provider"
|
2
|
+
require "envconfig/service"
|
3
|
+
require "envconfig/smtp"
|
4
|
+
require "envconfig/version"
|
5
|
+
|
6
|
+
module Envconfig
|
7
|
+
|
8
|
+
def self.load(env)
|
9
|
+
Root.new(env)
|
10
|
+
end
|
11
|
+
|
12
|
+
class Root
|
13
|
+
|
14
|
+
def initialize(env)
|
15
|
+
@env = env
|
16
|
+
end
|
17
|
+
|
18
|
+
def smtp
|
19
|
+
@_smtp ||= ::Envconfig::Smtp.new(@env)
|
20
|
+
end
|
21
|
+
|
22
|
+
def smtp?
|
23
|
+
smtp.to_h.any?
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Envconfig
|
4
|
+
describe "finding a provider" do
|
5
|
+
|
6
|
+
let(:env) { {} }
|
7
|
+
let(:providers) { [] }
|
8
|
+
|
9
|
+
subject(:provider) do
|
10
|
+
Provider.find(env, providers)
|
11
|
+
end
|
12
|
+
|
13
|
+
context "with assorted providers" do
|
14
|
+
class InvalidProvider
|
15
|
+
def initialize(env); end
|
16
|
+
def valid?; false end
|
17
|
+
end
|
18
|
+
class ValidProvider < InvalidProvider
|
19
|
+
def valid?; true; end
|
20
|
+
def config; {key: "value"}; end
|
21
|
+
end
|
22
|
+
class ValidProviderB < ValidProvider
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:providers) do
|
26
|
+
[InvalidProvider, ValidProvider, ValidProviderB]
|
27
|
+
end
|
28
|
+
|
29
|
+
it "resolves to an instance of ValidProvider" do
|
30
|
+
expect(provider.class).to eq(ValidProvider)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "provides ValidProvider's config" do
|
34
|
+
expect(provider.config).to eq(key: "value")
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when no providers are valid" do
|
40
|
+
it "resolves to a null-provider with empty config" do
|
41
|
+
expect(provider.config).to eq({})
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/spec/root_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Envconfig::Root do
|
4
|
+
|
5
|
+
let(:env) { {} }
|
6
|
+
subject(:root) { Envconfig.load(env) }
|
7
|
+
|
8
|
+
context "with nothing in ENV" do
|
9
|
+
|
10
|
+
describe "#smtp?" do
|
11
|
+
it "is false" do
|
12
|
+
expect(root.smtp?).to eq(false)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#smtp" do
|
17
|
+
[:to_h, :provider, :[]].each do |m|
|
18
|
+
it "responds to :#{m}" do
|
19
|
+
expect(root.smtp.respond_to?(m)).to eq(true)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
it "has an empty #to_h result" do
|
23
|
+
expect(root.smtp.to_h).to eq({})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/spec/smtp_spec.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "SMTP configuration" do
|
4
|
+
|
5
|
+
let(:env) { {} }
|
6
|
+
subject(:config) { Envconfig.load(env).smtp }
|
7
|
+
|
8
|
+
context "with nothing relevant in ENV" do
|
9
|
+
it "returns nil for keys" do
|
10
|
+
[:address, :port, :user_name, :password].each do |k|
|
11
|
+
expect(config[k]).to eq(nil)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
it "responds to #to_h with empty hash" do
|
15
|
+
expect(config.to_h).to eq({})
|
16
|
+
end
|
17
|
+
it "has nil provider name" do
|
18
|
+
expect(config.provider.name).to eq(nil)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with Mandrill in ENV" do
|
23
|
+
before {
|
24
|
+
env["MANDRILL_USERNAME"] = "mandrilluser"
|
25
|
+
env["MANDRILL_APIKEY"] = "mandrillkey"
|
26
|
+
}
|
27
|
+
it "sets address, port, user_name, password" do
|
28
|
+
expect(config.to_h).to eq(
|
29
|
+
address: "smtp.mandrillapp.com",
|
30
|
+
port: "25",
|
31
|
+
user_name: "mandrilluser",
|
32
|
+
password: "mandrillkey",
|
33
|
+
)
|
34
|
+
end
|
35
|
+
it "identifies as Mandrill" do
|
36
|
+
expect(config.provider.name).to eq("Mandrill")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "with Postmark in ENV" do
|
41
|
+
before {
|
42
|
+
env["POSTMARK_SMTP_SERVER"] = "postmark.example.org"
|
43
|
+
env["POSTMARK_API_KEY"] = "b6ebafbec9a31661f6247f21ff4a68d9"
|
44
|
+
}
|
45
|
+
it "sets address, user_name, password" do
|
46
|
+
expect(config.to_h).to eq(
|
47
|
+
address: "postmark.example.org",
|
48
|
+
user_name: "b6ebafbec9a31661f6247f21ff4a68d9",
|
49
|
+
password: "b6ebafbec9a31661f6247f21ff4a68d9",
|
50
|
+
port: "25",
|
51
|
+
authentication: :plain,
|
52
|
+
)
|
53
|
+
end
|
54
|
+
it "identifies as Postmark" do
|
55
|
+
expect(config.provider.name).to eq("Postmark")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "with SendGrid in ENV" do
|
60
|
+
before {
|
61
|
+
env["SENDGRID_USERNAME"] = "sendgriduser"
|
62
|
+
env["SENDGRID_PASSWORD"] = "sendgridpassword"
|
63
|
+
}
|
64
|
+
it "sets address, user_name, password" do
|
65
|
+
expect(config.to_h).to eq(
|
66
|
+
user_name: "sendgriduser",
|
67
|
+
password: "sendgridpassword",
|
68
|
+
address: "smtp.sendgrid.net",
|
69
|
+
port: "587",
|
70
|
+
authentication: :plain,
|
71
|
+
enable_starttls_auto: true
|
72
|
+
)
|
73
|
+
end
|
74
|
+
it "identifies as SendGrid" do
|
75
|
+
expect(config.provider.name).to eq("SendGrid")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "with only SMTP_PORT=2525 in env" do
|
80
|
+
before { env["SMTP_PORT"] = "2525" }
|
81
|
+
it "has port 2525" do
|
82
|
+
expect(config[:port]).to eq("2525")
|
83
|
+
end
|
84
|
+
it "only has port 2525" do
|
85
|
+
expect(config.to_h).to eq(
|
86
|
+
port: "2525",
|
87
|
+
)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "envconfig"
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: envconfig
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Annesley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-15 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
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:
|
56
|
+
email:
|
57
|
+
- paul@annesley.cc
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- .travis.yml
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- envconfig-rails.gemspec
|
70
|
+
- envconfig.gemspec
|
71
|
+
- lib/envconfig-rails.rb
|
72
|
+
- lib/envconfig.rb
|
73
|
+
- lib/envconfig/provider.rb
|
74
|
+
- lib/envconfig/railtie.rb
|
75
|
+
- lib/envconfig/service.rb
|
76
|
+
- lib/envconfig/smtp.rb
|
77
|
+
- lib/envconfig/version.rb
|
78
|
+
- spec/provider_resolver_spec.rb
|
79
|
+
- spec/root_spec.rb
|
80
|
+
- spec/smtp_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
homepage: https://github.com/broadstack/envconfig
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.1.2
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Connect your app to backing services via Broadstack/Heroku-style ENV vars.
|
106
|
+
test_files:
|
107
|
+
- spec/provider_resolver_spec.rb
|
108
|
+
- spec/root_spec.rb
|
109
|
+
- spec/smtp_spec.rb
|
110
|
+
- spec/spec_helper.rb
|
111
|
+
has_rdoc:
|