app_config_for 0.0.3 → 0.0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/app_config_for/gem_version.rb +16 -0
- data/lib/app_config_for/legacy_support.rb +45 -0
- data/lib/app_config_for/version.rb +6 -1
- data/lib/app_config_for.rb +42 -11
- metadata +17 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 228991a28438bec90c4aa9f06b33850a5ee4034b01a7ec87a33c90fa77ace37d
|
4
|
+
data.tar.gz: eed01754e58c59c3ea8d58c23e809f8d9c3ae1b6fe5a3b24958a1a173f01a87c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d05a93814a9b8162890151e89f2e83e99f29c58478e371aeef49c63c29713a01d1c86ab3b4a28ee320d2eb639dd51879d107dd820c9f173c3bae958c626396b9
|
7
|
+
data.tar.gz: b9dc3d8224b2e0c05167da273faf7df940c1397022d22768af8cce85101de32993a56cc2e13bca5b2d8cb656e7885251a962486856388ad1871be9163784816e
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'active_support/core_ext/string/inflections'
|
2
|
+
name = File.basename(__dir__).classify
|
3
|
+
STDERR.puts "#{name}: Warning! Outdated version of ActiveSupport active! To avoid security issues, please upgrade your version of ActiveSupport to at least 6.1.4."
|
4
|
+
if ActiveSupport.gem_version < Gem::Version.new('6.1.0')
|
5
|
+
puts "#{name}: Loading legacy support for ActiveSupport version #{ActiveSupport.gem_version}."
|
6
|
+
|
7
|
+
# Quick and dirty backport. This won't be here long. Just enough to support AppConfigFor during some legacy upgrades.
|
8
|
+
require "active_support/string_inquirer"
|
9
|
+
require "erb"
|
10
|
+
require "yaml"
|
11
|
+
|
12
|
+
module ActiveSupport
|
13
|
+
class EnvironmentInquirer < StringInquirer
|
14
|
+
|
15
|
+
Environments = %w(development test production)
|
16
|
+
|
17
|
+
def initialize(env)
|
18
|
+
super(env)
|
19
|
+
Environments.each { |e| instance_variable_set(:"@#{e}", env == e) }
|
20
|
+
end
|
21
|
+
|
22
|
+
Environments.each { |e| define_method("#{e}?") { instance_variable_get("@#{e}") }}
|
23
|
+
end
|
24
|
+
|
25
|
+
class ConfigurationFile
|
26
|
+
def initialize(file_name)
|
27
|
+
@file_name = file_name
|
28
|
+
@config = File.read(file_name)
|
29
|
+
warn(file_name + ' contains invisible non-breaking spaces.') if @config.match?("\u00A0")
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.parse(file_name)
|
33
|
+
new(file_name).parse
|
34
|
+
end
|
35
|
+
|
36
|
+
def parse
|
37
|
+
YAML.load(ERB.new(@config).result) || {}
|
38
|
+
rescue Psych::SyntaxError => e
|
39
|
+
raise "YAML syntax error occurred while parsing #{@file_name}. Error: #{e.message}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/lib/app_config_for.rb
CHANGED
@@ -2,11 +2,18 @@
|
|
2
2
|
|
3
3
|
require_relative "app_config_for/version"
|
4
4
|
require_relative "app_config_for/errors"
|
5
|
-
|
6
|
-
require 'active_support/
|
5
|
+
|
6
|
+
require 'active_support/gem_version'
|
7
|
+
if ActiveSupport.gem_version >= Gem::Version.new('6.1.4')
|
8
|
+
require 'active_support/environment_inquirer'
|
9
|
+
require 'active_support/configuration_file'
|
10
|
+
else
|
11
|
+
require_relative 'app_config_for/legacy_support'
|
12
|
+
end
|
13
|
+
|
7
14
|
require 'active_support/core_ext/object/blank'
|
8
15
|
require 'active_support/core_ext/string/inflections'
|
9
|
-
require
|
16
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
10
17
|
require 'active_support/ordered_options'
|
11
18
|
require 'active_support/core_ext/object/try'
|
12
19
|
|
@@ -23,9 +30,18 @@ module AppConfigFor
|
|
23
30
|
env_prefixes(false, false).send(at_beginning ? :unshift : :push, AppConfigFor.prefix_from(prefix || self)).uniq!
|
24
31
|
end
|
25
32
|
|
33
|
+
def add_config_directory(new_directory)
|
34
|
+
(additional_config_directories << Pathname.new(new_directory).expand_path).uniq!
|
35
|
+
end
|
36
|
+
|
37
|
+
def additional_config_directories
|
38
|
+
@additional_config_directories ||= []
|
39
|
+
end
|
40
|
+
|
26
41
|
def config_directories
|
27
42
|
directories = ['Rails'.safe_constantize&.application&.paths, try(:paths)].compact.map { |root| root["config"].existent.first }.compact
|
28
|
-
directories.map! { |directory| Pathname.new(directory) }
|
43
|
+
directories.map! { |directory| Pathname.new(directory).expand_path }
|
44
|
+
directories.concat additional_config_directories
|
29
45
|
directories.push(Pathname.getwd + 'config')
|
30
46
|
directories.uniq
|
31
47
|
end
|
@@ -39,7 +55,7 @@ module AppConfigFor
|
|
39
55
|
end
|
40
56
|
|
41
57
|
def config_files(name = nil)
|
42
|
-
name = AppConfigFor.yml_name_from(name ||
|
58
|
+
name = AppConfigFor.yml_name_from(name || config_name)
|
43
59
|
config_directories.map { |directory| directory + name }
|
44
60
|
end
|
45
61
|
|
@@ -59,17 +75,26 @@ module AppConfigFor
|
|
59
75
|
config
|
60
76
|
end
|
61
77
|
|
78
|
+
def config_name
|
79
|
+
@config_name ||= self
|
80
|
+
end
|
81
|
+
|
82
|
+
def config_name=(new_config_name)
|
83
|
+
@config_name = new_config_name
|
84
|
+
end
|
85
|
+
|
62
86
|
def config_options(name = nil)
|
63
87
|
file = name.is_a?(Pathname) ? name : config_file(name)
|
64
88
|
ActiveSupport::ConfigurationFile.parse(file.to_s).deep_symbolize_keys
|
65
89
|
rescue SystemCallError => exception
|
66
90
|
raise ConfigNotFound.new(name.is_a?(Pathname) ? name : config_files(name), exception)
|
67
91
|
rescue => exception
|
68
|
-
raise LoadError.new(file, exception)
|
92
|
+
raise file ? LoadError.new(file, exception) : exception
|
69
93
|
end
|
70
94
|
|
71
|
-
def configured(env: nil)
|
72
|
-
config_for(
|
95
|
+
def configured(reload = false, env: nil)
|
96
|
+
@configured = config_for(nil, env: env) if reload || @configured.nil?
|
97
|
+
@configured
|
73
98
|
end
|
74
99
|
|
75
100
|
def env(reload = false)
|
@@ -170,7 +195,7 @@ module AppConfigFor
|
|
170
195
|
|
171
196
|
def progenitor_of(object, style = nil)
|
172
197
|
style = verified_style!(style, object)
|
173
|
-
command = {namespace: :namespace_of, class: :parent_of}[style]
|
198
|
+
command = {namespace: :namespace_of, class: :parent_of}[style] # Todo, deal with the other styles by doing nothing and not crashing or something.
|
174
199
|
object && command && send(command, object).yield_self { |n| n && (n.respond_to?(:env_prefixes) ? n : progenitor_of(n)) }
|
175
200
|
end
|
176
201
|
|
@@ -220,14 +245,20 @@ module AppConfigFor
|
|
220
245
|
|
221
246
|
private
|
222
247
|
|
248
|
+
def prep_base(base)
|
249
|
+
base.add_env_prefix
|
250
|
+
gem = Gem.loaded_specs[base.name.underscore]
|
251
|
+
base.add_config_directory(gem.gem_dir + '/config') if gem
|
252
|
+
end
|
253
|
+
|
223
254
|
def extended(base)
|
224
255
|
# Todo: Add the ability to check the default environments directly from base if the methods don't yet exist.
|
225
256
|
# ie: base.development? is the same as base.env.development?
|
226
|
-
base
|
257
|
+
prep_base(base)
|
227
258
|
end
|
228
259
|
|
229
260
|
def included(base)
|
230
|
-
base
|
261
|
+
prep_base(base)
|
231
262
|
end
|
232
263
|
|
233
264
|
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: app_config_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frank Hall
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
22
|
+
version: '8'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.0'
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
32
|
+
version: '8'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rake
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,6 +78,8 @@ files:
|
|
72
78
|
- Rakefile
|
73
79
|
- lib/app_config_for.rb
|
74
80
|
- lib/app_config_for/errors.rb
|
81
|
+
- lib/app_config_for/gem_version.rb
|
82
|
+
- lib/app_config_for/legacy_support.rb
|
75
83
|
- lib/app_config_for/version.rb
|
76
84
|
- sig/app_config_for.rbs
|
77
85
|
homepage: https://github.com/ChapterHouse/app_config_for
|
@@ -79,8 +87,8 @@ licenses:
|
|
79
87
|
- MIT
|
80
88
|
metadata:
|
81
89
|
homepage_uri: https://github.com/ChapterHouse/app_config_for
|
82
|
-
source_code_uri: https://github.com/ChapterHouse/app_config_for/tree/v0.0.
|
83
|
-
changelog_uri: https://github.com/ChapterHouse/app_config_for/blob/v0.0.
|
90
|
+
source_code_uri: https://github.com/ChapterHouse/app_config_for/tree/v0.0.4.1
|
91
|
+
changelog_uri: https://github.com/ChapterHouse/app_config_for/blob/v0.0.4.1/CHANGELOG.md
|
84
92
|
post_install_message:
|
85
93
|
rdoc_options: []
|
86
94
|
require_paths:
|
@@ -89,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
97
|
requirements:
|
90
98
|
- - ">="
|
91
99
|
- !ruby/object:Gem::Version
|
92
|
-
version: 2.6
|
100
|
+
version: 2.3.6
|
93
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
102
|
requirements:
|
95
103
|
- - ">="
|