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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 822e17fb52f85c3f3066322083d1d2d30265bb58fbce6f50e88590ebea140ba4
4
- data.tar.gz: c3cfd97af9fe5de290b8a378517b3f11a7a020e550929c7e3765e34411988246
3
+ metadata.gz: 29fe2702743a353cb8d7d793d59278dea2cfef4075e17204181ffdab9b594274
4
+ data.tar.gz: dd34c9bf703b5b93b4e5c4a1cce3e9ede85af1666d5de484005e13f217d897bd
5
5
  SHA512:
6
- metadata.gz: 8fabe569de72f9a65d22a4a69a8b2b4cad0d97ef2dc62f245133352b142402ec2eb2b6f9492c713aceaac6518ca1453e1527855e6eaf5b4adb12ec0b2c2c1b50
7
- data.tar.gz: 2fe2eef92329925f2626a501bd34c0081170e507f30214b9199710e509f208b0f3df7bfda163b304304e1fda58c8b4f757f527e748afd21708514877e4a1765c
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):
@@ -299,6 +299,7 @@ module Anyway # :nodoc:
299
299
  "via `config_name :my_config`"
300
300
  end
301
301
 
302
+ # TODO(v3.0): Replace downcase with underscore
302
303
  Regexp.last_match[1].tap(&:downcase!)
303
304
  end
304
305
 
@@ -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 (((array, 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)) && (((array = __m_hash__.delete(:array)) || true) && (((type = __m_hash__.delete(:type)) || true) && __m_hash__.empty?)))))
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]"
@@ -299,6 +299,7 @@ module Anyway # :nodoc:
299
299
  "via `config_name :my_config`"
300
300
  end
301
301
 
302
+ # TODO(v3.0): Replace downcase with underscore
302
303
  Regexp.last_match[1].tap(&:downcase!)
303
304
  end
304
305
 
@@ -299,6 +299,7 @@ module Anyway # :nodoc:
299
299
  "via `config_name :my_config`"
300
300
  end
301
301
 
302
+ # TODO(v3.0): Replace downcase with underscore
302
303
  Regexp.last_match[1].tap(&:downcase!)
303
304
  end
304
305
 
data/lib/anyway/config.rb CHANGED
@@ -299,6 +299,7 @@ module Anyway # :nodoc:
299
299
  "via `config_name :my_config`"
300
300
  end
301
301
 
302
+ # TODO(v3.0): Replace downcase with underscore
302
303
  Regexp.last_match[1].tap(&:downcase!)
303
304
  end
304
305
 
@@ -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:, type:, **nil
47
+ in array: _, type:, **nil
48
48
  "Array[#{TYPE_TO_CLASS.fetch(type, "untyped")}]"
49
49
  in Hash
50
50
  "Hash[string,untyped]"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Anyway # :nodoc:
4
- VERSION = "2.4.2"
4
+ VERSION = "2.5.0"
5
5
  end
data/lib/anyway_config.rb CHANGED
@@ -45,5 +45,10 @@ module Anyway # :nodoc:
45
45
  end
46
46
  end
47
47
 
48
- require "anyway/rails" if defined?(::Rails::VERSION)
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"
@@ -41,6 +41,11 @@ module Anyway
41
41
  static_config_root
42
42
  end
43
43
  end
44
+
45
+ def needs_config_name?
46
+ raise "No longer needed" if Gem::Version.new(Anyway::VERSION) >= Gem::Version.new("3.0.0")
47
+ file_name.include?("_")
48
+ end
44
49
  end
45
50
  end
46
51
  end
@@ -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.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-06-07 00:00:00.000000000 Z
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