anyway_config 2.4.2 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +8 -0
- data/lib/.rbnext/2.7/anyway/config.rb +1 -0
- data/lib/.rbnext/2.7/anyway/rbs.rb +1 -1
- data/lib/.rbnext/3.0/anyway/config.rb +1 -0
- data/lib/.rbnext/3.1/anyway/config.rb +1 -0
- data/lib/anyway/config.rb +1 -0
- data/lib/anyway/rails/autoload.rb +39 -0
- data/lib/anyway/rails/loaders/credentials.rb +1 -1
- data/lib/anyway/rbs.rb +1 -1
- data/lib/anyway/version.rb +1 -1
- data/lib/anyway_config.rb +6 -1
- data/lib/generators/anyway/config/config_generator.rb +5 -0
- data/lib/generators/anyway/config/templates/config.rb.tt +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29fe2702743a353cb8d7d793d59278dea2cfef4075e17204181ffdab9b594274
|
4
|
+
data.tar.gz: dd34c9bf703b5b93b4e5c4a1cce3e9ede85af1666d5de484005e13f217d897bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f1d05c31f97864f64b2ace127636d15535ed18c50f44f11e90949d784df40d437e48d9cd37a0bc2b8ccab0c5b17dd6a25062cbf25669f51e654fb1a5b356b2d
|
7
|
+
data.tar.gz: 6a7ceda8a770887e3775d5c75e6d8e5a6afa98f49851926d40d131c4ca0034f60b1739868d142029b35fe44b4bf39205e68d84fe97f65c89c146cbe74a4750aa
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 2.5.0 (2023-07-24)
|
6
|
+
|
7
|
+
- Generators: Add `config_name` to generated classes if name contains underscore. ([@palkan][])
|
8
|
+
|
9
|
+
- Load Rails extensions even if Rails was loaded after Anyway Config. ([@palkan][])
|
10
|
+
|
11
|
+
- Fix handling `config.credentials.content_path` provided as String. ([@palkan][])
|
12
|
+
|
5
13
|
## 2.4.2 (2023-06-07)
|
6
14
|
|
7
15
|
- Use ANYWAY_ENV as the current environment if defined. ([@palkan][])
|
data/README.md
CHANGED
@@ -548,6 +548,14 @@ Alternatively, you can call `rails g anyway:app_config name param1 param2 ...`.
|
|
548
548
|
|
549
549
|
**NOTE:** The generated `ApplicationConfig` class uses a singleton pattern along with `delegate_missing_to` to re-use the same instance across the application. However, the delegation can lead to unexpected behaviour and break Anyway Config internals if you have attributes named as `Anyway::Config` class methods. See [#120](https://github.com/palkan/anyway_config/issues/120).
|
550
550
|
|
551
|
+
### Loading Anyway Config before Rails
|
552
|
+
|
553
|
+
Anyway Config activates Rails-specific features automatically on the gem load only if Rails has been already required (we check for the `Rails::VERSION` constant presence). However, in some cases you may want to use Anyway Config before Rails initialization (e.g., in `config/puma.rb` when starting a Puma web server).
|
554
|
+
|
555
|
+
By default, Anyway Config sets up a hook (via TracePoint API) and waits for Rails to be loaded to require the Rails extensions (`require "anyway/rails"`). In case you load Rails after Anyway Config, you will see a warning telling you about that. Note that config classes loaded before Rails are not populated from Rails-specific data sources (e.g., credentials).
|
556
|
+
|
557
|
+
You can disable the warning by setting `Anyway::Rails.disable_postponed_load_warning = true` in your application. Also, you can disable the _hook_ completely by calling `Anyway::Rails.tracer.disable`.
|
558
|
+
|
551
559
|
## Using with Ruby
|
552
560
|
|
553
561
|
The default data loading mechanism for non-Rails applications is the following (ordered by priority from low to high):
|
@@ -44,7 +44,7 @@ module Anyway
|
|
44
44
|
TYPE_TO_CLASS.fetch(type) { defaults[param] ? "Symbol" : "untyped" }
|
45
45
|
when (Array === __m__)
|
46
46
|
"Array[untyped]"
|
47
|
-
when (((
|
47
|
+
when (((type,) = nil) || ((__m__.respond_to?(:deconstruct_keys) && (((__m_hash__src__ = __m__.deconstruct_keys(nil)) || true) && (Hash === __m_hash__src__ || Kernel.raise(TypeError, "#deconstruct_keys must return Hash"))) && (__m_hash__ = __m_hash__src__.dup)) && ((__m_hash__.key?(:array) && __m_hash__.key?(:type)) && ((((type = __m_hash__.delete(:type)) || true) && __m_hash__.empty?)))))
|
48
48
|
"Array[#{TYPE_TO_CLASS.fetch(type, "untyped")}]"
|
49
49
|
when (Hash === __m__)
|
50
50
|
"Hash[string,untyped]"
|
data/lib/anyway/config.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This module is used to detect a Rails application and activate the corresponding plugins
|
4
|
+
# when Anyway Config is loaded before Rails (e.g., in config/puma.rb).
|
5
|
+
module Anyway
|
6
|
+
module Rails
|
7
|
+
class << self
|
8
|
+
attr_reader :tracer
|
9
|
+
attr_accessor :disable_postponed_load_warning
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def tracepoint_class_callback(event)
|
14
|
+
# Ignore singletons
|
15
|
+
return if event.self.singleton_class?
|
16
|
+
|
17
|
+
# We wait till `rails` has been loaded, which is enough to add a railtie
|
18
|
+
# https://github.com/rails/rails/blob/main/railties/lib/rails.rb
|
19
|
+
return unless event.self.name == "Rails"
|
20
|
+
|
21
|
+
# We must check for methods defined in `rails.rb` to distinguish events
|
22
|
+
# happening when we open the `Rails` module in other files.
|
23
|
+
if defined?(::Rails.env)
|
24
|
+
tracer.disable
|
25
|
+
|
26
|
+
unless disable_postponed_load_warning
|
27
|
+
warn "Anyway Config was loaded before Rails. Activating Anyway Config Rails plugins now.\n" \
|
28
|
+
"NOTE: Already loaded configs were provisioned without Rails-specific sources."
|
29
|
+
end
|
30
|
+
|
31
|
+
require "anyway/rails"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
@tracer = TracePoint.new(:class, &method(:tracepoint_class_callback))
|
37
|
+
@tracer.enable
|
38
|
+
end
|
39
|
+
end
|
@@ -53,7 +53,7 @@ module Anyway
|
|
53
53
|
|
54
54
|
def credentials_path
|
55
55
|
if ::Rails.application.config.respond_to?(:credentials)
|
56
|
-
::Rails.application.config.credentials.content_path.relative_path_from(::Rails.root).to_s
|
56
|
+
::Rails.root.join(::Rails.application.config.credentials.content_path).relative_path_from(::Rails.root).to_s
|
57
57
|
else
|
58
58
|
"config/credentials.yml.enc"
|
59
59
|
end
|
data/lib/anyway/rbs.rb
CHANGED
@@ -44,7 +44,7 @@ module Anyway
|
|
44
44
|
TYPE_TO_CLASS.fetch(type) { defaults[param] ? "Symbol" : "untyped" }
|
45
45
|
in Array
|
46
46
|
"Array[untyped]"
|
47
|
-
in array
|
47
|
+
in array: _, type:, **nil
|
48
48
|
"Array[#{TYPE_TO_CLASS.fetch(type, "untyped")}]"
|
49
49
|
in Hash
|
50
50
|
"Hash[string,untyped]"
|
data/lib/anyway/version.rb
CHANGED
data/lib/anyway_config.rb
CHANGED
@@ -45,5 +45,10 @@ module Anyway # :nodoc:
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
|
48
|
+
if defined?(::Rails::VERSION)
|
49
|
+
require "anyway/rails"
|
50
|
+
else
|
51
|
+
require "anyway/rails/autoload"
|
52
|
+
end
|
53
|
+
|
49
54
|
require "anyway/testing" if ENV["RACK_ENV"] == "test" || ENV["RAILS_ENV"] == "test"
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
4
|
class <%= class_name %>Config < ApplicationConfig
|
5
|
+
<%- if needs_config_name? %>
|
6
|
+
config_name :<%= file_name %>
|
7
|
+
<%- end -%>
|
5
8
|
<%- unless parameters.empty? -%>
|
6
9
|
attr_config <%= parameters.map { |param| ":#{param}" }.join(", ") %>
|
7
10
|
<%- end -%>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anyway_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-next-core
|
@@ -158,6 +158,7 @@ files:
|
|
158
158
|
- lib/anyway/option_parser_builder.rb
|
159
159
|
- lib/anyway/optparse_config.rb
|
160
160
|
- lib/anyway/rails.rb
|
161
|
+
- lib/anyway/rails/autoload.rb
|
161
162
|
- lib/anyway/rails/config.rb
|
162
163
|
- lib/anyway/rails/loaders.rb
|
163
164
|
- lib/anyway/rails/loaders/credentials.rb
|