seielit-figaro 1.1.2
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 +7 -0
- data/.gitignore +6 -0
- data/.rspec +3 -0
- data/.travis.yml +30 -0
- data/CHANGELOG.md +122 -0
- data/CONTRIBUTING.md +48 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +22 -0
- data/README.md +350 -0
- data/Rakefile +6 -0
- data/bin/figaro +5 -0
- data/gemfiles/rails41.gemfile +12 -0
- data/gemfiles/rails42.gemfile +12 -0
- data/gemfiles/rails50.gemfile +13 -0
- data/gemfiles/rails51.gemfile +13 -0
- data/gemfiles/rails52.gemfile +14 -0
- data/gemfiles/rails60.gemfile +14 -0
- data/lib/figaro.rb +33 -0
- data/lib/figaro/application.rb +91 -0
- data/lib/figaro/cli.rb +42 -0
- data/lib/figaro/cli/heroku_set.rb +33 -0
- data/lib/figaro/cli/install.rb +32 -0
- data/lib/figaro/cli/install/application.yml +11 -0
- data/lib/figaro/cli/task.rb +33 -0
- data/lib/figaro/env.rb +45 -0
- data/lib/figaro/error.rb +17 -0
- data/lib/figaro/rails.rb +7 -0
- data/lib/figaro/rails/application.rb +21 -0
- data/lib/figaro/rails/railtie.rb +10 -0
- data/lib/figaro/rails/tasks.rake +6 -0
- data/lib/figaro/settings.rb +124 -0
- data/seielit-figaro.gemspec +23 -0
- data/spec/figaro/application_spec.rb +262 -0
- data/spec/figaro/cli/heroku_set_spec.rb +67 -0
- data/spec/figaro/cli/install_spec.rb +49 -0
- data/spec/figaro/env_spec.rb +195 -0
- data/spec/figaro/rails/application_spec.rb +47 -0
- data/spec/figaro/settings_spec.rb +109 -0
- data/spec/figaro_spec.rb +106 -0
- data/spec/rails_spec.rb +50 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/support/aruba.rb +19 -0
- data/spec/support/bin/heroku +5 -0
- data/spec/support/command_helpers.rb +17 -0
- data/spec/support/command_interceptor.rb +33 -0
- data/spec/support/reset.rb +13 -0
- metadata +145 -0
data/spec/figaro_spec.rb
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
describe Figaro do
|
|
2
|
+
describe 'require' do
|
|
3
|
+
it 'does not load Rails' do
|
|
4
|
+
require 'figaro'
|
|
5
|
+
expect(defined?(Rails)).to be nil
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe ".env" do
|
|
10
|
+
it "falls through to Figaro::ENV" do
|
|
11
|
+
expect(Figaro.env).to eq(Figaro::ENV)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe ".adapter" do
|
|
16
|
+
let(:adapter) { double(:adapter) }
|
|
17
|
+
|
|
18
|
+
it "defaults to the generic application adapter" do
|
|
19
|
+
expect(Figaro.adapter).to eq(Figaro::Application)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "is configurable" do
|
|
23
|
+
expect {
|
|
24
|
+
Figaro.adapter = adapter
|
|
25
|
+
}.to change {
|
|
26
|
+
Figaro.adapter
|
|
27
|
+
}.from(Figaro::Application).to(adapter)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe ".application" do
|
|
32
|
+
let(:adapter) { double(:adapter) }
|
|
33
|
+
let(:application) { double(:application) }
|
|
34
|
+
let(:custom_application) { double(:custom_application) }
|
|
35
|
+
|
|
36
|
+
before do
|
|
37
|
+
allow(Figaro).to receive(:adapter) { adapter }
|
|
38
|
+
allow(adapter).to receive(:new).with(no_args) { application }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "defaults to a new adapter application" do
|
|
42
|
+
expect(Figaro.application).to eq(application)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "is configurable" do
|
|
46
|
+
expect {
|
|
47
|
+
Figaro.application = custom_application
|
|
48
|
+
}.to change {
|
|
49
|
+
Figaro.application
|
|
50
|
+
}.from(application).to(custom_application)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
describe ".load" do
|
|
55
|
+
let(:application) { double(:application) }
|
|
56
|
+
|
|
57
|
+
before do
|
|
58
|
+
allow(Figaro).to receive(:application) { application }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "loads the application configuration" do
|
|
62
|
+
expect(application).to receive(:load).once.with(no_args)
|
|
63
|
+
|
|
64
|
+
Figaro.load
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe ".require_keys" do
|
|
69
|
+
before do
|
|
70
|
+
::ENV["foo"] = "bar"
|
|
71
|
+
::ENV["hello"] = "world"
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
context "when no keys are missing" do
|
|
75
|
+
it "does nothing" do
|
|
76
|
+
expect {
|
|
77
|
+
Figaro.require_keys("foo", "hello")
|
|
78
|
+
}.not_to raise_error
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "accepts an array" do
|
|
82
|
+
expect {
|
|
83
|
+
Figaro.require_keys(["foo", "hello"])
|
|
84
|
+
}.not_to raise_error
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
context "when keys are missing" do
|
|
89
|
+
it "raises an error for the missing keys" do
|
|
90
|
+
expect {
|
|
91
|
+
Figaro.require_keys("foo", "goodbye", "baz")
|
|
92
|
+
}.to raise_error(Figaro::MissingKeys) { |error|
|
|
93
|
+
expect(error.message).not_to include("foo")
|
|
94
|
+
expect(error.message).to include("goodbye")
|
|
95
|
+
expect(error.message).to include("baz")
|
|
96
|
+
}
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "accepts an array" do
|
|
100
|
+
expect {
|
|
101
|
+
Figaro.require_keys(["foo", "goodbye", "baz"])
|
|
102
|
+
}.to raise_error(Figaro::MissingKeys)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
data/spec/rails_spec.rb
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
describe Figaro::Rails do
|
|
2
|
+
before do
|
|
3
|
+
run_simple(<<-CMD)
|
|
4
|
+
rails new example \
|
|
5
|
+
--skip-gemfile \
|
|
6
|
+
--skip-bundle \
|
|
7
|
+
--skip-keeps \
|
|
8
|
+
--skip-sprockets \
|
|
9
|
+
--skip-javascript \
|
|
10
|
+
--skip-test-unit \
|
|
11
|
+
--no-rc \
|
|
12
|
+
--quiet
|
|
13
|
+
CMD
|
|
14
|
+
cd("example")
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe "initialization" do
|
|
18
|
+
before do
|
|
19
|
+
write_file("config/application.yml", "foo: bar")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "loads application.yml" do
|
|
23
|
+
run_simple("rails runner 'puts Figaro.env.foo'")
|
|
24
|
+
|
|
25
|
+
assert_partial_output("bar", all_stdout)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "happens before database initialization" do
|
|
29
|
+
write_file("config/database.yml", <<-EOF)
|
|
30
|
+
development:
|
|
31
|
+
adapter: sqlite3
|
|
32
|
+
database: db/<%= ENV["foo"] %>.sqlite3
|
|
33
|
+
EOF
|
|
34
|
+
|
|
35
|
+
run_simple("rake db:migrate")
|
|
36
|
+
|
|
37
|
+
check_file_presence(["db/bar.sqlite3"], true)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "happens before application configuration" do
|
|
41
|
+
insert_into_file_after("config/application.rb", /< Rails::Application$/, <<-EOL)
|
|
42
|
+
config.foo = ENV["foo"]
|
|
43
|
+
EOL
|
|
44
|
+
|
|
45
|
+
run_simple("rails runner 'puts Rails.application.config.foo'")
|
|
46
|
+
|
|
47
|
+
assert_partial_output("bar", all_stdout)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require "bundler"
|
|
2
|
+
Bundler.setup
|
|
3
|
+
|
|
4
|
+
if ENV["CODECLIMATE_REPO_TOKEN"]
|
|
5
|
+
require "codeclimate-test-reporter"
|
|
6
|
+
CodeClimate::TestReporter.start
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
require "figaro"
|
|
10
|
+
|
|
11
|
+
Bundler.require(:test)
|
|
12
|
+
|
|
13
|
+
Dir[File.expand_path("../support/*.rb", __FILE__)].each { |f| require f }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require "aruba/api"
|
|
2
|
+
|
|
3
|
+
module ArubaHelpers
|
|
4
|
+
def insert_into_file_after(file, pattern, addition)
|
|
5
|
+
content = prep_for_fs_check { IO.read(file) }
|
|
6
|
+
content.sub!(pattern, "\\0\n#{addition}")
|
|
7
|
+
overwrite_file(file, content)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
RSpec.configure do |config|
|
|
12
|
+
config.include(Aruba::Api)
|
|
13
|
+
config.include(ArubaHelpers)
|
|
14
|
+
|
|
15
|
+
config.before do
|
|
16
|
+
@aruba_timeout_seconds = 60
|
|
17
|
+
FileUtils.rm_rf(current_dir)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module CommandHelpers
|
|
2
|
+
def commands
|
|
3
|
+
CommandInterceptor.commands
|
|
4
|
+
end
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
RSpec.configure do |config|
|
|
8
|
+
config.include(CommandHelpers)
|
|
9
|
+
|
|
10
|
+
config.before(:suite) do
|
|
11
|
+
CommandInterceptor.setup
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
config.before do
|
|
15
|
+
CommandInterceptor.reset
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require "fileutils"
|
|
2
|
+
require "ostruct"
|
|
3
|
+
require "yaml"
|
|
4
|
+
|
|
5
|
+
module CommandInterceptor
|
|
6
|
+
class Command < OpenStruct
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
BIN_PATH = File.expand_path("../bin", __FILE__)
|
|
10
|
+
LOG_PATH = File.expand_path("../../../tmp/commands.yml", __FILE__)
|
|
11
|
+
|
|
12
|
+
def self.setup
|
|
13
|
+
ENV["PATH"] = "#{BIN_PATH}:#{ENV["PATH"]}"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.intercept(name)
|
|
17
|
+
FileUtils.mkdir_p(File.dirname(LOG_PATH))
|
|
18
|
+
FileUtils.touch(LOG_PATH)
|
|
19
|
+
|
|
20
|
+
command = { "env" => ENV.to_hash, "name" => name, "args" => ARGV }
|
|
21
|
+
commands = self.commands << command
|
|
22
|
+
|
|
23
|
+
File.write(LOG_PATH, YAML.dump(commands))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.commands
|
|
27
|
+
(File.exist?(LOG_PATH) && YAML.load_file(LOG_PATH) || []).map { |c| Command.new(c) }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.reset
|
|
31
|
+
FileUtils.rm_f(LOG_PATH)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
RSpec.configure do |config|
|
|
2
|
+
config.before(:suite) do
|
|
3
|
+
$original_env_keys = ::ENV.keys
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
config.before do
|
|
7
|
+
Figaro.adapter = nil
|
|
8
|
+
Figaro.application = nil
|
|
9
|
+
|
|
10
|
+
# Restore the original state of ENV for each test
|
|
11
|
+
::ENV.keep_if { |k, _| $original_env_keys.include?(k) }
|
|
12
|
+
end
|
|
13
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: seielit-figaro
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.1.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Steve Richert
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-08-27 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: thor
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.14'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.14'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
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: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '10.4'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '10.4'
|
|
55
|
+
description: Simple, Heroku-friendly Rails app configuration using ENV and a single
|
|
56
|
+
YAML file (fork of https://github.com/laserlemon/figaro)
|
|
57
|
+
email: steve.richert@gmail.com
|
|
58
|
+
executables:
|
|
59
|
+
- figaro
|
|
60
|
+
extensions: []
|
|
61
|
+
extra_rdoc_files: []
|
|
62
|
+
files:
|
|
63
|
+
- ".gitignore"
|
|
64
|
+
- ".rspec"
|
|
65
|
+
- ".travis.yml"
|
|
66
|
+
- CHANGELOG.md
|
|
67
|
+
- CONTRIBUTING.md
|
|
68
|
+
- Gemfile
|
|
69
|
+
- LICENSE.txt
|
|
70
|
+
- README.md
|
|
71
|
+
- Rakefile
|
|
72
|
+
- bin/figaro
|
|
73
|
+
- gemfiles/rails41.gemfile
|
|
74
|
+
- gemfiles/rails42.gemfile
|
|
75
|
+
- gemfiles/rails50.gemfile
|
|
76
|
+
- gemfiles/rails51.gemfile
|
|
77
|
+
- gemfiles/rails52.gemfile
|
|
78
|
+
- gemfiles/rails60.gemfile
|
|
79
|
+
- lib/figaro.rb
|
|
80
|
+
- lib/figaro/application.rb
|
|
81
|
+
- lib/figaro/cli.rb
|
|
82
|
+
- lib/figaro/cli/heroku_set.rb
|
|
83
|
+
- lib/figaro/cli/install.rb
|
|
84
|
+
- lib/figaro/cli/install/application.yml
|
|
85
|
+
- lib/figaro/cli/task.rb
|
|
86
|
+
- lib/figaro/env.rb
|
|
87
|
+
- lib/figaro/error.rb
|
|
88
|
+
- lib/figaro/rails.rb
|
|
89
|
+
- lib/figaro/rails/application.rb
|
|
90
|
+
- lib/figaro/rails/railtie.rb
|
|
91
|
+
- lib/figaro/rails/tasks.rake
|
|
92
|
+
- lib/figaro/settings.rb
|
|
93
|
+
- seielit-figaro.gemspec
|
|
94
|
+
- spec/figaro/application_spec.rb
|
|
95
|
+
- spec/figaro/cli/heroku_set_spec.rb
|
|
96
|
+
- spec/figaro/cli/install_spec.rb
|
|
97
|
+
- spec/figaro/env_spec.rb
|
|
98
|
+
- spec/figaro/rails/application_spec.rb
|
|
99
|
+
- spec/figaro/settings_spec.rb
|
|
100
|
+
- spec/figaro_spec.rb
|
|
101
|
+
- spec/rails_spec.rb
|
|
102
|
+
- spec/spec_helper.rb
|
|
103
|
+
- spec/support/aruba.rb
|
|
104
|
+
- spec/support/bin/heroku
|
|
105
|
+
- spec/support/command_helpers.rb
|
|
106
|
+
- spec/support/command_interceptor.rb
|
|
107
|
+
- spec/support/reset.rb
|
|
108
|
+
homepage: https://github.com/seielit/figaro
|
|
109
|
+
licenses:
|
|
110
|
+
- MIT
|
|
111
|
+
metadata: {}
|
|
112
|
+
post_install_message:
|
|
113
|
+
rdoc_options: []
|
|
114
|
+
require_paths:
|
|
115
|
+
- lib
|
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
|
+
requirements:
|
|
118
|
+
- - ">="
|
|
119
|
+
- !ruby/object:Gem::Version
|
|
120
|
+
version: '0'
|
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
|
+
requirements:
|
|
123
|
+
- - ">="
|
|
124
|
+
- !ruby/object:Gem::Version
|
|
125
|
+
version: '0'
|
|
126
|
+
requirements: []
|
|
127
|
+
rubygems_version: 3.0.3
|
|
128
|
+
signing_key:
|
|
129
|
+
specification_version: 4
|
|
130
|
+
summary: Simple Rails app configuration
|
|
131
|
+
test_files:
|
|
132
|
+
- spec/figaro/application_spec.rb
|
|
133
|
+
- spec/figaro/cli/heroku_set_spec.rb
|
|
134
|
+
- spec/figaro/cli/install_spec.rb
|
|
135
|
+
- spec/figaro/env_spec.rb
|
|
136
|
+
- spec/figaro/rails/application_spec.rb
|
|
137
|
+
- spec/figaro/settings_spec.rb
|
|
138
|
+
- spec/figaro_spec.rb
|
|
139
|
+
- spec/rails_spec.rb
|
|
140
|
+
- spec/spec_helper.rb
|
|
141
|
+
- spec/support/aruba.rb
|
|
142
|
+
- spec/support/bin/heroku
|
|
143
|
+
- spec/support/command_helpers.rb
|
|
144
|
+
- spec/support/command_interceptor.rb
|
|
145
|
+
- spec/support/reset.rb
|