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/Rakefile
ADDED
data/bin/figaro
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec path: ".."
|
|
4
|
+
|
|
5
|
+
gem "rails", "~> 5.2.0"
|
|
6
|
+
gem 'listen'
|
|
7
|
+
|
|
8
|
+
group :test do
|
|
9
|
+
gem "aruba", "~> 0.6.2"
|
|
10
|
+
gem "codeclimate-test-reporter", require: false
|
|
11
|
+
gem "rspec", "~> 3.1"
|
|
12
|
+
gem "sqlite3", "~> 1.3.0"
|
|
13
|
+
gem 'bootsnap', '1.4.4'
|
|
14
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec path: ".."
|
|
4
|
+
|
|
5
|
+
gem "rails", "~> 6.0.0"
|
|
6
|
+
gem 'listen'
|
|
7
|
+
|
|
8
|
+
group :test do
|
|
9
|
+
gem "aruba", "~> 0.6.2"
|
|
10
|
+
gem "codeclimate-test-reporter", require: false
|
|
11
|
+
gem "rspec", "~> 3.1"
|
|
12
|
+
gem "sqlite3", "~> 1.4.0"
|
|
13
|
+
gem 'bootsnap', '1.4.4'
|
|
14
|
+
end
|
data/lib/figaro.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require "figaro/error"
|
|
2
|
+
require "figaro/env"
|
|
3
|
+
require "figaro/application"
|
|
4
|
+
require "figaro/settings"
|
|
5
|
+
|
|
6
|
+
module Figaro
|
|
7
|
+
extend self
|
|
8
|
+
|
|
9
|
+
attr_writer :adapter, :application
|
|
10
|
+
|
|
11
|
+
def env
|
|
12
|
+
Figaro::ENV
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def adapter
|
|
16
|
+
@adapter ||= Figaro::Application
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def application
|
|
20
|
+
@application ||= adapter.new
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def load
|
|
24
|
+
application.load
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def require_keys(*keys)
|
|
28
|
+
missing_keys = keys.flatten - ::ENV.keys
|
|
29
|
+
raise MissingKeys.new(missing_keys) if missing_keys.any?
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
require "figaro/rails"
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
require "erb"
|
|
2
|
+
require "yaml"
|
|
3
|
+
|
|
4
|
+
module Figaro
|
|
5
|
+
class Application
|
|
6
|
+
FIGARO_ENV_PREFIX = "_FIGARO_"
|
|
7
|
+
|
|
8
|
+
include Enumerable
|
|
9
|
+
|
|
10
|
+
def initialize(options = {})
|
|
11
|
+
@options = options.inject({}) { |m, (k, v)| m[k.to_sym] = v; m }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def path
|
|
15
|
+
@options.fetch(:path) { default_path }.to_s
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def path=(path)
|
|
19
|
+
@options[:path] = path
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def environment
|
|
23
|
+
environment = @options.fetch(:environment) { default_environment }
|
|
24
|
+
environment.nil? ? nil : environment.to_s
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def environment=(environment)
|
|
28
|
+
@options[:environment] = environment
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def configuration
|
|
32
|
+
global_configuration.merge(environment_configuration)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def load
|
|
36
|
+
each do |key, value|
|
|
37
|
+
skip?(key) ? key_skipped!(key) : set(key, value)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def each(&block)
|
|
42
|
+
configuration.each(&block)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def default_path
|
|
48
|
+
raise NotImplementedError
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def default_environment
|
|
52
|
+
nil
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def raw_configuration
|
|
56
|
+
(@parsed ||= Hash.new { |hash, path| hash[path] = parse(path) })[path]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def parse(path)
|
|
60
|
+
File.exist?(path) && YAML.load(ERB.new(File.read(path)).result) || {}
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def global_configuration
|
|
64
|
+
raw_configuration.reject { |_, value| value.is_a?(Hash) }
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def environment_configuration
|
|
68
|
+
raw_configuration[environment] || {}
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def set(key, value)
|
|
72
|
+
non_string_configuration!(key) unless key.is_a?(String)
|
|
73
|
+
non_string_configuration!(value) unless value.is_a?(String) || value.nil?
|
|
74
|
+
|
|
75
|
+
::ENV[key.to_s] = value.nil? ? nil : value.to_s
|
|
76
|
+
::ENV[FIGARO_ENV_PREFIX + key.to_s] = value.nil? ? nil: value.to_s
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def skip?(key)
|
|
80
|
+
::ENV.key?(key.to_s) && !::ENV.key?(FIGARO_ENV_PREFIX + key.to_s)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def non_string_configuration!(value)
|
|
84
|
+
warn "WARNING: Use strings for Figaro configuration. #{value.inspect} was converted to #{value.to_s.inspect}."
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def key_skipped!(key)
|
|
88
|
+
warn "WARNING: Skipping key #{key.inspect}. Already set in ENV."
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
data/lib/figaro/cli.rb
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require "thor"
|
|
2
|
+
|
|
3
|
+
module Figaro
|
|
4
|
+
class CLI < Thor
|
|
5
|
+
# figaro install
|
|
6
|
+
|
|
7
|
+
desc "install", "Install Figaro"
|
|
8
|
+
|
|
9
|
+
method_option "path",
|
|
10
|
+
aliases: ["-p"],
|
|
11
|
+
default: "config/application.yml",
|
|
12
|
+
desc: "Specify a configuration file path"
|
|
13
|
+
|
|
14
|
+
def install
|
|
15
|
+
require "figaro/cli/install"
|
|
16
|
+
Install.start
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# figaro heroku:set
|
|
20
|
+
|
|
21
|
+
desc "heroku:set", "Send Figaro configuration to Heroku"
|
|
22
|
+
|
|
23
|
+
method_option "app",
|
|
24
|
+
aliases: ["-a"],
|
|
25
|
+
desc: "Specify a Heroku app"
|
|
26
|
+
method_option "environment",
|
|
27
|
+
aliases: ["-e"],
|
|
28
|
+
desc: "Specify an application environment"
|
|
29
|
+
method_option "path",
|
|
30
|
+
aliases: ["-p"],
|
|
31
|
+
default: "config/application.yml",
|
|
32
|
+
desc: "Specify a configuration file path"
|
|
33
|
+
method_option "remote",
|
|
34
|
+
aliases: ["-r"],
|
|
35
|
+
desc: "Specify a Heroku git remote"
|
|
36
|
+
|
|
37
|
+
define_method "heroku:set" do
|
|
38
|
+
require "figaro/cli/heroku_set"
|
|
39
|
+
HerokuSet.run(options)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require "figaro/cli/task"
|
|
2
|
+
|
|
3
|
+
module Figaro
|
|
4
|
+
class CLI < Thor
|
|
5
|
+
class HerokuSet < Task
|
|
6
|
+
def run
|
|
7
|
+
system(configuration, command)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
def command
|
|
13
|
+
"heroku config:set #{vars} #{for_app} #{for_remote}"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def for_app
|
|
17
|
+
options[:app] ? "--app=#{options[:app]}" : nil
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def for_remote
|
|
21
|
+
options[:remote] ? "--remote=#{options[:remote]}" : nil
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def vars
|
|
25
|
+
configuration.keys.map { |k| var(k) }.join(" ")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def var(key)
|
|
29
|
+
Gem.win_platform? ? %(#{key}="%#{key}%") : %(#{key}="$#{key}")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require "thor/group"
|
|
2
|
+
|
|
3
|
+
module Figaro
|
|
4
|
+
class CLI < Thor
|
|
5
|
+
class Install < Thor::Group
|
|
6
|
+
include Thor::Actions
|
|
7
|
+
|
|
8
|
+
class_option "path",
|
|
9
|
+
aliases: ["-p"],
|
|
10
|
+
default: "config/application.yml",
|
|
11
|
+
desc: "Specify a configuration file path"
|
|
12
|
+
|
|
13
|
+
def self.source_root
|
|
14
|
+
File.expand_path("../install", __FILE__)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def create_configuration
|
|
18
|
+
copy_file("application.yml", options[:path])
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def ignore_configuration
|
|
22
|
+
if File.exists?(".gitignore")
|
|
23
|
+
append_to_file(".gitignore", <<-EOF)
|
|
24
|
+
|
|
25
|
+
# Ignore application configuration
|
|
26
|
+
/#{options[:path]}
|
|
27
|
+
EOF
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Add configuration values here, as shown below.
|
|
2
|
+
#
|
|
3
|
+
# pusher_app_id: "2954"
|
|
4
|
+
# pusher_key: 7381a978f7dd7f9a1117
|
|
5
|
+
# pusher_secret: abdc3b896a0ffb85d373
|
|
6
|
+
# stripe_api_key: sk_test_2J0l093xOyW72XUYJHE4Dv2r
|
|
7
|
+
# stripe_publishable_key: pk_test_ro9jV5SNwGb1yYlQfzG17LHK
|
|
8
|
+
#
|
|
9
|
+
# production:
|
|
10
|
+
# stripe_api_key: sk_live_EeHnL644i6zo4Iyq4v1KdV9H
|
|
11
|
+
# stripe_publishable_key: pk_live_9lcthxpSIHbGwmdO941O1XVU
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require "figaro/application"
|
|
2
|
+
|
|
3
|
+
module Figaro
|
|
4
|
+
class CLI < Thor
|
|
5
|
+
class Task
|
|
6
|
+
attr_reader :options
|
|
7
|
+
|
|
8
|
+
def self.run(options = {})
|
|
9
|
+
new(options).run
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def initialize(options = {})
|
|
13
|
+
@options = options
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def configuration
|
|
19
|
+
application.configuration
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def application
|
|
23
|
+
@application ||= Figaro::Application.new(options)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
if defined? Bundler
|
|
27
|
+
def system(*)
|
|
28
|
+
Bundler.with_clean_env { super }
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
data/lib/figaro/env.rb
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module Figaro
|
|
2
|
+
module ENV
|
|
3
|
+
extend self
|
|
4
|
+
|
|
5
|
+
def respond_to?(method, *)
|
|
6
|
+
key, punctuation = extract_key_from_method(method)
|
|
7
|
+
|
|
8
|
+
case punctuation
|
|
9
|
+
when "!" then has_key?(key) || super
|
|
10
|
+
when "?", nil then true
|
|
11
|
+
else super
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def method_missing(method, *)
|
|
18
|
+
key, punctuation = extract_key_from_method(method)
|
|
19
|
+
|
|
20
|
+
case punctuation
|
|
21
|
+
when "!" then send(key) || missing_key!(key)
|
|
22
|
+
when "?" then !!send(key)
|
|
23
|
+
when nil then get_value(key)
|
|
24
|
+
else super
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def extract_key_from_method(method)
|
|
29
|
+
method.to_s.downcase.match(/^(.+?)([!?=])?$/).captures
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def has_key?(key)
|
|
33
|
+
::ENV.any? { |k, _| k.downcase == key }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def missing_key!(key)
|
|
37
|
+
raise MissingKey.new(key)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def get_value(key)
|
|
41
|
+
_, value = ::ENV.detect { |k, _| k.downcase == key }
|
|
42
|
+
value
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/figaro/error.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Figaro
|
|
2
|
+
class Error < StandardError; end
|
|
3
|
+
|
|
4
|
+
class RailsNotInitialized < Error; end
|
|
5
|
+
|
|
6
|
+
class MissingKey < Error
|
|
7
|
+
def initialize(key)
|
|
8
|
+
super("Missing required configuration key: #{key.inspect}")
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class MissingKeys < Error
|
|
13
|
+
def initialize(keys)
|
|
14
|
+
super("Missing required configuration keys: #{keys.inspect}")
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|