anyway_config 1.4.4 → 2.0.0.pre

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.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +187 -51
  3. data/lib/anyway.rb +22 -2
  4. data/lib/anyway/config.rb +116 -98
  5. data/lib/anyway/dynamic_config.rb +27 -0
  6. data/lib/anyway/env.rb +2 -5
  7. data/lib/anyway/ext/deep_dup.rb +4 -4
  8. data/lib/anyway/ext/deep_freeze.rb +5 -0
  9. data/lib/anyway/ext/jruby.rb +9 -4
  10. data/lib/anyway/ext/string_serialize.rb +1 -7
  11. data/{spec/dummy/config.ru → lib/anyway/loaders/env_loader.rb} +0 -0
  12. data/lib/anyway/loaders/secrets_loader.rb +0 -0
  13. data/lib/anyway/loaders/yaml_loader.rb +0 -0
  14. data/lib/anyway/option_parser_builder.rb +2 -2
  15. data/lib/anyway/optparse_config.rb +90 -0
  16. data/lib/anyway/rails/config.rb +76 -24
  17. data/lib/anyway/railtie.rb +11 -0
  18. data/lib/anyway/testing.rb +13 -0
  19. data/lib/anyway/testing/helpers.rb +36 -0
  20. data/lib/anyway/version.rb +1 -1
  21. metadata +46 -48
  22. data/.gem_release.yml +0 -3
  23. data/.gitignore +0 -40
  24. data/.rubocop.yml +0 -50
  25. data/.travis.yml +0 -30
  26. data/CHANGELOG.md +0 -112
  27. data/Gemfile +0 -21
  28. data/Rakefile +0 -23
  29. data/anyway_config.gemspec +0 -29
  30. data/config/cool.yml +0 -5
  31. data/gemfiles/jruby.gemfile +0 -7
  32. data/gemfiles/rails42.gemfile +0 -6
  33. data/gemfiles/rails5.gemfile +0 -6
  34. data/gemfiles/railsmaster.gemfile +0 -7
  35. data/spec/anyway.yml +0 -2
  36. data/spec/config_spec.rb +0 -337
  37. data/spec/config_spec_norails.rb +0 -86
  38. data/spec/dummy/config/application.rb +0 -13
  39. data/spec/dummy/config/boot.rb +0 -5
  40. data/spec/dummy/config/cool.yml +0 -5
  41. data/spec/dummy/config/cool_custom.yml +0 -2
  42. data/spec/dummy/config/database.yml +0 -25
  43. data/spec/dummy/config/environment.rb +0 -5
  44. data/spec/dummy/config/environments/test.rb +0 -2
  45. data/spec/dummy/config/routes.rb +0 -2
  46. data/spec/dummy/config/secrets.yml +0 -30
  47. data/spec/env_spec.rb +0 -50
  48. data/spec/ext/deep_dup_spec.rb +0 -38
  49. data/spec/ext/deep_freeze_spec.rb +0 -32
  50. data/spec/ext/hash_spec.rb +0 -39
  51. data/spec/ext/string_serialize_spec.rb +0 -32
  52. data/spec/spec_helper.rb +0 -31
  53. data/spec/spec_norails_helper.rb +0 -26
  54. data/spec/support/cool_config.rb +0 -10
  55. data/spec/support/print_warning_matcher.rb +0 -34
  56. data/spec/support/small_config.rb +0 -7
  57. data/spec/support/test_config.rb +0 -16
@@ -1,13 +0,0 @@
1
- require File.expand_path('../boot', __FILE__)
2
-
3
- require "rails"
4
-
5
- Bundler.require(*Rails.groups)
6
-
7
- module Dummy
8
- class Application < Rails::Application
9
- config.logger = Logger.new('/dev/null')
10
- config.eager_load = false
11
- end
12
- end
13
-
@@ -1,5 +0,0 @@
1
- # Set up gems listed in the Gemfile.
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
-
4
- require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
- $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -1,5 +0,0 @@
1
- test:
2
- host: "test.host"
3
- user:
4
- name: "root"
5
- password: <%= ENV['ANYWAY_SECRET_PASSWORD'] || "root" %>
@@ -1,2 +0,0 @@
1
- test:
2
- host: "custom.host"
@@ -1,25 +0,0 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3
3
- #
4
- # Ensure the SQLite 3 gem is defined in your Gemfile
5
- # gem 'sqlite3'
6
- #
7
- default: &default
8
- adapter: sqlite3
9
- pool: 5
10
- timeout: 5000
11
-
12
- development:
13
- <<: *default
14
- database: db/development.sqlite3
15
-
16
- # Warning: The database defined as "test" will be erased and
17
- # re-generated from your development database when you run "rake".
18
- # Do not set this db to the same as development or production.
19
- test:
20
- <<: *default
21
- database: db/test.sqlite3
22
-
23
- production:
24
- <<: *default
25
- database: db/production.sqlite3
@@ -1,5 +0,0 @@
1
- # Load the Rails application.
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the Rails application.
5
- Dummy::Application.initialize!
@@ -1,2 +0,0 @@
1
- Dummy::Application.configure do
2
- end
@@ -1,2 +0,0 @@
1
- Dummy::Application.routes.draw do
2
- end
@@ -1,30 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Your secret key is used for verifying the integrity of signed cookies.
4
- # If you change this key, all old signed cookies will become invalid!
5
-
6
- # Make sure the secret is at least 30 characters and all random,
7
- # no regular words or you'll be exposed to dictionary attacks.
8
- # You can use `rake secret` to generate a secure secret key.
9
-
10
- # Make sure the secrets in this file are kept private
11
- # if you're sharing your code publicly.
12
-
13
- development:
14
- secret_key_base: 0acf417376117dfb765e573f21090cf03217b8f0a8eaa301813c8a25c66139b5615f0e93fada39ec81599953468e792344810390008ca6ec90db825dc6b096c8
15
-
16
- test:
17
- secret_key_base: 164c31e4e77c1f37bbe4ce13c8f975beb0c21472e1eee6f08f2186b10b198586fcac88d161b9c2ac455acfac444c1cad4bf7c695f58e04ca2bf75c4028a9e967
18
- cool:
19
- user:
20
- name: test
21
- bullshit: 'mooo'
22
- my_app:
23
- name: 'app'
24
- secret: 'my_secret'
25
- elshit: 'UUU'
26
-
27
- # Do not keep production secrets in the repository,
28
- # instead read values from the environment.
29
- production:
30
- secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
data/spec/env_spec.rb DELETED
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Anyway::Env do
6
- let(:env) { Anyway.env }
7
-
8
- it "loads simple key/values by module", :aggregate_failures do
9
- ENV['TESTO_KEY'] = 'a'
10
- ENV['MY_TEST_KEY'] = 'b'
11
- expect(env.fetch('testo')['key']).to eq 'a'
12
- expect(env.fetch('my_test')['key']).to eq 'b'
13
- end
14
-
15
- it "loads hash values", :aggregate_failures do
16
- ENV['TESTO_DATA__ID'] = '1'
17
- ENV['TESTO_DATA__META__NAME'] = 'meta'
18
- ENV['TESTO_DATA__META__VAL'] = 'true'
19
- testo_config = env.fetch('testo')
20
- expect(testo_config['data']['id']).to eq 1
21
- expect(testo_config['data']['meta']['name']).to eq 'meta'
22
- expect(testo_config['data']['meta']['val']).to be_truthy
23
- end
24
-
25
- it "loads array values", :aggregate_failures do
26
- ENV['TESTO_DATA__IDS'] = '1,2, 3'
27
- ENV['TESTO_DATA__META__NAMES'] = 'meta, kotleta'
28
- ENV['TESTO_DATA__META__SIZE'] = '2'
29
- ENV['TESTO_DATA__TEXT'] = '"C\'mon, everybody"'
30
- testo_config = env.fetch('testo')
31
- expect(testo_config['data']['ids']).to include(1, 2, 3)
32
- expect(testo_config['data']['meta']['names']).to include('meta', 'kotleta')
33
- expect(testo_config['data']['meta']['size']).to eq 2
34
- expect(testo_config['data']['text']).to eq "C'mon, everybody"
35
- end
36
-
37
- it "returns deep duped hash" do
38
- ENV['TESTO_CONF'] = 'path/to/conf.yml'
39
- ENV['TESTO_DATA__ID'] = '1'
40
- ENV['TESTO_DATA__META__NAME'] = 'meta'
41
- ENV['TESTO_DATA__META__VAL'] = 'true'
42
- testo_config = env.fetch('testo')
43
- testo_config.delete('conf')
44
- testo_config['data']['meta'].delete('name')
45
-
46
- new_config = env.fetch('testo')
47
- expect(new_config['data']['meta']['name']).to eq 'meta'
48
- expect(new_config['conf']).to eq 'path/to/conf.yml'
49
- end
50
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Anyway::Ext::DeepDup do
6
- using Anyway::Ext::DeepDup
7
-
8
- it "duplicates nested arrays and hashes", :aggregate_failures do
9
- source = {
10
- a: 1,
11
- b: 'hello',
12
- c: {
13
- id: 1,
14
- list: [1, 2, { name: 'John' }]
15
- },
16
- d: [{ id: 1 }, { id: 2 }]
17
- }
18
-
19
- dup = source.deep_dup
20
-
21
- expect(dup[:a]).to eq 1
22
- expect(dup[:b]).to eq 'hello'
23
- expect(dup[:c]).to eq(
24
- id: 1,
25
- list: [1, 2, { name: 'John' }]
26
- )
27
- expect(dup[:d]).to eq(
28
- [{ id: 1 }, { id: 2 }]
29
- )
30
-
31
- expect(dup[:c]).not_to be_equal(source[:c])
32
- expect(dup[:c][:list]).not_to be_equal(source[:c][:list])
33
- expect(dup[:c][:list].last).not_to be_equal(source[:c][:list].last)
34
-
35
- expect(dup[:d].first).not_to be_equal(source[:d].first)
36
- expect(dup[:d].last).not_to be_equal(source[:d].last)
37
- end
38
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'anyway/ext/deep_freeze'
5
-
6
- describe Anyway::Ext::DeepFreeze do
7
- using Anyway::Ext::DeepFreeze
8
-
9
- it "freezes nested arrays and hashes", :aggregate_failures do
10
- source = {
11
- a: 1,
12
- b: 'hello',
13
- c: {
14
- id: 1,
15
- list: [1, 2, { name: 'John' }]
16
- },
17
- d: [{ id: 1 }, { id: 2 }]
18
- }
19
-
20
- dup = source.deep_freeze
21
-
22
- expect(dup).to be_frozen
23
- expect(dup[:c]).to be_frozen
24
- expect(dup[:d]).to be_frozen
25
-
26
- expect(dup[:c][:list]).to be_frozen
27
- expect(dup[:c][:list].last).to be_frozen
28
-
29
- expect(dup[:d].first).to be_frozen
30
- expect(dup[:d].last).to be_frozen
31
- end
32
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Anyway::Ext::Hash do
6
- using Anyway::Ext::Hash
7
-
8
- describe "#stringify_keys!" do
9
- let(:source) do
10
- {
11
- a: 1,
12
- b: 'hello',
13
- c: {
14
- id: 1
15
- }
16
- }
17
- end
18
-
19
- let(:expected_result) do
20
- {
21
- 'a' => 1,
22
- 'b' => 'hello',
23
- 'c' => {
24
- 'id' => 1
25
- }
26
- }
27
- end
28
-
29
- it "transforms keys of hash to strings" do
30
- source.stringify_keys!
31
-
32
- expect(source).to eq(expected_result)
33
- end
34
-
35
- it "returns a hash with transformed keys to strings" do
36
- expect(source.stringify_keys!).to eq(expected_result)
37
- end
38
- end
39
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Anyway::Ext::StringSerialize do
6
- using Anyway::Ext::StringSerialize
7
-
8
- it "serializes a string", :aggregate_failures do
9
- expect("1,2, 3".serialize).to eq [1, 2, 3]
10
-
11
- expect("t".serialize).to eq true
12
- expect("true".serialize).to eq true
13
- expect("y".serialize).to eq true
14
- expect("yes".serialize).to eq true
15
-
16
- expect("f".serialize).to eq false
17
- expect("false".serialize).to eq false
18
- expect("n".serialize).to eq false
19
- expect("no".serialize).to eq false
20
-
21
- expect("null".serialize).to eq nil
22
- expect("nil".serialize).to eq nil
23
-
24
- expect("1".serialize).to eq 1
25
-
26
- expect("1.5".serialize).to eq 1.5
27
-
28
- expect("'localhost'".serialize).to eq "localhost"
29
-
30
- expect("localhost".serialize).to eq "localhost"
31
- end
32
- end
data/spec/spec_helper.rb DELETED
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
- $LOAD_PATH.unshift(File.dirname(__FILE__))
5
-
6
- begin
7
- require "pry-byebug"
8
- rescue LoadError # rubocop:disable all
9
- end
10
-
11
- ENV["RAILS_ENV"] = 'test'
12
-
13
- require File.expand_path('dummy/config/environment', __dir__)
14
- require 'anyway_config'
15
-
16
- Rails.application.eager_load!
17
-
18
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
19
-
20
- RSpec.configure do |config|
21
- config.mock_with :rspec
22
-
23
- config.example_status_persistence_file_path = "tmp/rspec_examples.txt"
24
- config.filter_run :focus
25
- config.run_all_when_everything_filtered = true
26
-
27
- config.order = :random
28
- Kernel.srand config.seed
29
-
30
- config.before(:each) { Anyway.env.clear }
31
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
- $LOAD_PATH.unshift(File.dirname(__FILE__))
5
-
6
- begin
7
- require "pry-byebug"
8
- rescue LoadError # rubocop:disable all
9
- end
10
-
11
- require 'anyway_config'
12
- require 'erb'
13
-
14
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
15
-
16
- RSpec.configure do |config|
17
- config.mock_with :rspec
18
-
19
- config.filter_run :focus
20
- config.run_all_when_everything_filtered = true
21
-
22
- config.order = :random
23
- Kernel.srand config.seed
24
-
25
- config.before(:each) { Anyway.env.clear }
26
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class CoolConfig < Anyway::Config # :nodoc:
4
- config_name :cool
5
- attr_config :meta,
6
- :data,
7
- port: 8080,
8
- host: 'localhost',
9
- user: { name: 'admin', password: 'admin' }
10
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec::Matchers.define :print_warning do |message|
4
- def supports_block_expectations?
5
- true
6
- end
7
-
8
- match do |block|
9
- stderr = fake_stderr(&block)
10
- message ? stderr.include?(message) : !stderr.empty?
11
- end
12
-
13
- description do
14
- "write #{message && "\"#{message}\"" || 'anything'} to standard error"
15
- end
16
-
17
- failure_message do
18
- "expected to #{description}"
19
- end
20
-
21
- failure_message_when_negated do
22
- "expected not to #{description}"
23
- end
24
-
25
- # Fake STDERR and return a string written to it.
26
- def fake_stderr
27
- original_stderr = $stderr
28
- $stderr = StringIO.new
29
- yield
30
- $stderr.string
31
- ensure
32
- $stderr = original_stderr
33
- end
34
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class SmallConfig < Anyway::Config # :nodoc:
4
- config_name :small
5
- attr_config :meta,
6
- :data
7
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Anyway
4
- class TestConfig < Anyway::Config # :nodoc:
5
- attr_config :test,
6
- api: { key: '' },
7
- log: {
8
- format: {
9
- color: false,
10
- max_length: 100
11
- },
12
- level: :info
13
- },
14
- log_levels: %i[info fatal]
15
- end
16
- end