anyway_config 2.0.6 → 2.1.0

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.
@@ -5,16 +5,66 @@ module Anyway
5
5
  #
6
6
  # Settings contain the library-wide configuration.
7
7
  class Settings
8
+ # Future encapsulates settings that will be introduced in the upcoming version
9
+ # with the default values, which could break compatibility
10
+ class Future
11
+ class << self
12
+ def setting(name, default_value)
13
+ settings[name] = default_value
14
+
15
+ define_method(name) do
16
+ store[name]
17
+ end
18
+
19
+ define_method(:"#{name}=") do |val|
20
+ store[name] = val
21
+ end
22
+ end
23
+
24
+ def settings
25
+ @settings ||= {}
26
+ end
27
+ end
28
+
29
+ def initialize
30
+ @store = {}
31
+ end
32
+
33
+ def use(*names)
34
+ store.clear
35
+ names.each { store[_1] = self.class.settings[_1] }
36
+ end
37
+
38
+ private
39
+
40
+ attr_reader :store
41
+ end
42
+
8
43
  class << self
9
44
  # Define whether to load data from
10
45
  # *.yml.local (or credentials/local.yml.enc)
11
46
  attr_accessor :use_local_files
12
47
 
13
- # Return a path to YML config file given the config name
14
- attr_accessor :default_config_path
48
+ # A proc returning a path to YML config file given the config name
49
+ attr_reader :default_config_path
50
+
51
+ def default_config_path=(val)
52
+ if val.is_a?(Proc)
53
+ @default_config_path = val
54
+ return
55
+ end
56
+
57
+ val = val.to_s
58
+
59
+ @default_config_path = ->(name) { File.join(val, "#{name}.yml") }
60
+ end
15
61
 
16
62
  # Enable source tracing
17
63
  attr_accessor :tracing_enabled
64
+
65
+ def future
66
+ @future ||= Future.new
67
+ end
18
68
  end
19
69
 
20
70
  # By default, use local files only in development (that's the purpose if the local files)
@@ -86,7 +86,7 @@ module Anyway
86
86
  if trace?
87
87
  value.transform_values(&:to_h).tap { _1.default_proc = nil }
88
88
  else
89
- {value: value, source: source}
89
+ {value, source}
90
90
  end
91
91
  end
92
92
 
@@ -141,7 +141,7 @@ module Anyway
141
141
 
142
142
  def current_trace() = trace_stack.last
143
143
 
144
- alias tracing? current_trace
144
+ alias_method :tracing?, :current_trace
145
145
 
146
146
  def source_stack
147
147
  (Thread.current[:__anyway__trace_source_stack__] ||= [])
@@ -171,9 +171,9 @@ module Anyway
171
171
  return yield unless Tracing.tracing?
172
172
  val = yield
173
173
  if val.is_a?(Hash)
174
- Tracing.current_trace.merge_values(val, type: type, **opts)
174
+ Tracing.current_trace.merge_values(val, type:, **opts)
175
175
  else
176
- Tracing.current_trace.record_value(val, *path, type: type, **opts)
176
+ Tracing.current_trace.record_value(val, *path, type:, **opts)
177
177
  end
178
178
  val
179
179
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Anyway
4
+ using Anyway::Ext::DeepDup
5
+
6
+ module Utils
7
+ def self.deep_merge!(source, other)
8
+ other.each do |key, other_value|
9
+ this_value = source[key]
10
+
11
+ if this_value.is_a?(::Hash) && other_value.is_a?(::Hash)
12
+ deep_merge!(this_value, other_value)
13
+ else
14
+ source[key] = other_value.deep_dup
15
+ end
16
+ end
17
+
18
+ source
19
+ end
20
+ end
21
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Anyway # :nodoc:
4
- VERSION = "2.0.6"
4
+ VERSION = "2.1.0"
5
5
  end
@@ -11,6 +11,8 @@ require "anyway/ext/deep_dup"
11
11
  require "anyway/ext/deep_freeze"
12
12
  require "anyway/ext/hash"
13
13
 
14
+ require "anyway/utils/deep_merge"
15
+
14
16
  require "anyway/settings"
15
17
  require "anyway/tracing"
16
18
  require "anyway/config"
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.0.6
4
+ version: 2.1.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: 2020-07-07 00:00:00.000000000 Z
11
+ date: 2020-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-next-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.8.0
19
+ version: 0.11.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.8.0
26
+ version: 0.11.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ammeter
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -70,14 +70,14 @@ dependencies:
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '3.8'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.8'
83
83
  - !ruby/object:Gem::Dependency
@@ -106,14 +106,21 @@ files:
106
106
  - CHANGELOG.md
107
107
  - LICENSE.txt
108
108
  - README.md
109
+ - lib/.rbnext/1995.next/anyway/config.rb
110
+ - lib/.rbnext/1995.next/anyway/dynamic_config.rb
111
+ - lib/.rbnext/1995.next/anyway/env.rb
112
+ - lib/.rbnext/1995.next/anyway/loaders/base.rb
113
+ - lib/.rbnext/1995.next/anyway/tracing.rb
109
114
  - lib/.rbnext/2.7/anyway/auto_cast.rb
110
115
  - lib/.rbnext/2.7/anyway/config.rb
111
116
  - lib/.rbnext/2.7/anyway/option_parser_builder.rb
117
+ - lib/.rbnext/2.7/anyway/rails/loaders/yaml.rb
118
+ - lib/.rbnext/2.7/anyway/settings.rb
112
119
  - lib/.rbnext/2.7/anyway/tracing.rb
113
- - lib/.rbnext/2.8/anyway/config.rb
114
- - lib/.rbnext/2.8/anyway/loaders.rb
115
- - lib/.rbnext/2.8/anyway/loaders/base.rb
116
- - lib/.rbnext/2.8/anyway/tracing.rb
120
+ - lib/.rbnext/3.0/anyway/config.rb
121
+ - lib/.rbnext/3.0/anyway/loaders.rb
122
+ - lib/.rbnext/3.0/anyway/loaders/base.rb
123
+ - lib/.rbnext/3.0/anyway/tracing.rb
117
124
  - lib/anyway.rb
118
125
  - lib/anyway/auto_cast.rb
119
126
  - lib/anyway/config.rb
@@ -140,6 +147,7 @@ files:
140
147
  - lib/anyway/testing.rb
141
148
  - lib/anyway/testing/helpers.rb
142
149
  - lib/anyway/tracing.rb
150
+ - lib/anyway/utils/deep_merge.rb
143
151
  - lib/anyway/version.rb
144
152
  - lib/anyway_config.rb
145
153
  - lib/generators/anyway/app_config/USAGE