anyway_config 2.4.2 → 2.5.1

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: 2b7d08d5b962854362876ef57a33cb5a7db900a2b116cfc55e6a111fe67a6908
4
+ data.tar.gz: 8330ecf2804805dc40fd4966e5f0da06a8e46d87a9f01d1d377f5687b61cbdff
5
5
  SHA512:
6
- metadata.gz: 8fabe569de72f9a65d22a4a69a8b2b4cad0d97ef2dc62f245133352b142402ec2eb2b6f9492c713aceaac6518ca1453e1527855e6eaf5b4adb12ec0b2c2c1b50
7
- data.tar.gz: 2fe2eef92329925f2626a501bd34c0081170e507f30214b9199710e509f208b0f3df7bfda163b304304e1fda58c8b4f757f527e748afd21708514877e4a1765c
6
+ metadata.gz: 5af5f14653ba282b7c4e89d88c85dc3908d693fa7dc93c0436dba5044c1a8d98cae12284b97bfae9c3b9415dea5b745ac3bb9ee3639fc7880c61b3c3f6bf7465
7
+ data.tar.gz: b6d44f0500203371beaa12cdc47a24a9e9a66d66305491649e0961a9285d5280692cf5828736fa79afbd8fdd1459e26bf0a2715415c44188604c90616b880242
data/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 2.5.1 (2023-08-04)
6
+
7
+ - Fix Rails detection. ([@palkan][])
8
+
9
+ Fixes [#134](https://github.com/palkan/anyway_config/issues/134).
10
+
11
+ ## 2.5.0 (2023-07-24)
12
+
13
+ - Generators: Add `config_name` to generated classes if name contains underscore. ([@palkan][])
14
+
15
+ - Load Rails extensions even if Rails was loaded after Anyway Config. ([@palkan][])
16
+
17
+ - Fix handling `config.credentials.content_path` provided as String. ([@palkan][])
18
+
5
19
  ## 2.4.2 (2023-06-07)
6
20
 
7
21
  - 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
+ using RubyNext
8
+
9
+ class << self
10
+ attr_reader :tracer, :name_method
11
+ attr_accessor :disable_postponed_load_warning
12
+
13
+ private
14
+
15
+ def tracepoint_class_callback(event)
16
+ # Ignore singletons
17
+ return if event.self.singleton_class?
18
+
19
+ # We wait till `rails/application/configuration.rb` has been loaded, since we rely on it
20
+ # See https://github.com/palkan/anyway_config/issues/134
21
+ return unless name_method.bind_call(event.self) == "Rails::Application::Configuration"
22
+
23
+ tracer.disable
24
+
25
+ unless disable_postponed_load_warning
26
+ warn "Anyway Config was loaded before Rails. Activating Anyway Config Rails plugins now.\n" \
27
+ "NOTE: Already loaded configs were provisioned without Rails-specific sources."
28
+ end
29
+
30
+ require "anyway/rails"
31
+ end
32
+ end
33
+
34
+ @tracer = TracePoint.new(:end, &method(:tracepoint_class_callback))
35
+ @tracer.enable
36
+ # Use `Module#name` instead of `self.name` to handle overwritten `name` method
37
+ @name_method = Module.instance_method(:name)
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.1"
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.1
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-08-04 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