anyway_config 2.0.0.pre2 → 2.0.0.rc1

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +350 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +444 -119
  5. data/lib/.rbnext/2.7/anyway/auto_cast.rb +33 -0
  6. data/lib/.rbnext/2.7/anyway/config.rb +404 -0
  7. data/lib/.rbnext/2.7/anyway/option_parser_builder.rb +31 -0
  8. data/lib/.rbnext/2.7/anyway/tracing.rb +187 -0
  9. data/lib/anyway/auto_cast.rb +33 -0
  10. data/lib/anyway/config.rb +235 -58
  11. data/lib/anyway/dynamic_config.rb +1 -1
  12. data/lib/anyway/env.rb +29 -19
  13. data/lib/anyway/ext/hash.rb +14 -6
  14. data/lib/anyway/loaders.rb +79 -0
  15. data/lib/anyway/loaders/base.rb +23 -0
  16. data/lib/anyway/loaders/env.rb +16 -0
  17. data/lib/anyway/loaders/yaml.rb +46 -0
  18. data/lib/anyway/option_parser_builder.rb +6 -3
  19. data/lib/anyway/optparse_config.rb +10 -6
  20. data/lib/anyway/rails.rb +16 -0
  21. data/lib/anyway/rails/config.rb +2 -69
  22. data/lib/anyway/rails/loaders.rb +5 -0
  23. data/lib/anyway/rails/loaders/credentials.rb +64 -0
  24. data/lib/anyway/rails/loaders/secrets.rb +39 -0
  25. data/lib/anyway/rails/loaders/yaml.rb +19 -0
  26. data/lib/anyway/rails/settings.rb +58 -0
  27. data/lib/anyway/railtie.rb +14 -2
  28. data/lib/anyway/settings.rb +29 -0
  29. data/lib/anyway/tracing.rb +187 -0
  30. data/lib/anyway/version.rb +1 -1
  31. data/lib/anyway_config.rb +27 -21
  32. data/lib/generators/anyway/app_config/USAGE +9 -0
  33. data/lib/generators/anyway/app_config/app_config_generator.rb +17 -0
  34. data/lib/generators/anyway/config/USAGE +13 -0
  35. data/lib/generators/anyway/config/config_generator.rb +46 -0
  36. data/lib/generators/anyway/config/templates/config.rb.tt +9 -0
  37. data/lib/generators/anyway/config/templates/config.yml.tt +13 -0
  38. data/lib/generators/anyway/install/USAGE +4 -0
  39. data/lib/generators/anyway/install/install_generator.rb +43 -0
  40. data/lib/generators/anyway/install/templates/application_config.rb.tt +17 -0
  41. metadata +75 -10
  42. data/lib/anyway/ext/string_serialize.rb +0 -38
  43. data/lib/anyway/loaders/env_loader.rb +0 -0
  44. data/lib/anyway/loaders/secrets_loader.rb +0 -0
  45. data/lib/anyway/loaders/yaml_loader.rb +0 -0
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Generates a config class with the given name and list of parameters
3
+ and put it into `app/configs` folder.
4
+
5
+ Example:
6
+ rails generate app_config my_service param1 param2 ...
7
+
8
+ This will create:
9
+ app/configs/my_service_config.rb
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "generators/anyway/config/config_generator"
4
+
5
+ module Anyway
6
+ module Generators
7
+ class AppConfigGenerator < ConfigGenerator
8
+ source_root ConfigGenerator.source_root
9
+
10
+ private
11
+
12
+ def config_root
13
+ "app/configs"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ Description:
2
+ Generates a config class with the given name and list of parameters.
3
+
4
+ Use `--yml` / `--no-yml` option to specify whether you want to create a YAML config as well
5
+ (if no option is specified, the generator would ask you to choose during the run).
6
+
7
+ Use `--app` option to create config class in `app/configs` folder.
8
+
9
+ Example:
10
+ rails generate config my_service param1 param2 ...
11
+
12
+ This will create:
13
+ config/configs/my_service_config.rb
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+
5
+ module Anyway
6
+ module Generators
7
+ class ConfigGenerator < ::Rails::Generators::NamedBase
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ class_option :yml, type: :boolean
11
+ class_option :app, type: :boolean, default: false
12
+ argument :parameters, type: :array, default: [], banner: "param1 param2"
13
+
14
+ # check_class_collision suffix: "Config"
15
+
16
+ def run_install_if_needed
17
+ return if ::Rails.root.join(static_config_root, "application_config.rb").exist?
18
+ generate "anyway:install"
19
+ end
20
+
21
+ def create_config
22
+ template "config.rb", File.join(config_root, class_path, "#{file_name}_config.rb")
23
+ end
24
+
25
+ def create_yml
26
+ create_yml = options.fetch(:yml) { yes?("Would you like to generate a #{file_name}.yml file?") }
27
+ return unless create_yml
28
+ template "config.yml", File.join("config", "#{file_name}.yml")
29
+ end
30
+
31
+ private
32
+
33
+ def static_config_root
34
+ Anyway::Settings.autoload_static_config_path || Anyway::DEFAULT_CONFIGS_PATH
35
+ end
36
+
37
+ def config_root
38
+ if options[:app]
39
+ "app/configs"
40
+ else
41
+ static_config_root
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ <% module_namespacing do -%>
4
+ class <%= class_name %>Config < ApplicationConfig
5
+ <%- unless parameters.empty? -%>
6
+ attr_config <%= parameters.map { |param| ":#{param}" }.join(", ") %>
7
+ <%- end -%>
8
+ end
9
+ <% end -%>
@@ -0,0 +1,13 @@
1
+ default: &default
2
+ <%- parameters.each do |param| -%>
3
+ # <%= param %>: ""
4
+ <%- end -%>
5
+
6
+ development:
7
+ <<: *default
8
+
9
+ test:
10
+ <<: *default
11
+
12
+ production:
13
+ <<: *default
@@ -0,0 +1,4 @@
1
+ Description:
2
+ Generates a base config class (ApplicationConfig) for your application and
3
+ add the required configuriton (.gitignore, config/application.rb).
4
+
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators"
4
+
5
+ module Anyway
6
+ module Generators
7
+ class InstallGenerator < ::Rails::Generators::Base
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ class_option :configs_path, type: :string
11
+
12
+ def copy_application_config
13
+ template "application_config.rb", File.join(static_config_root, "application_config.rb")
14
+ end
15
+
16
+ def add_local_files_to_gitignore
17
+ if File.exist?(File.join(destination_root, ".gitignore"))
18
+ append_to_file ".gitignore", "\n/config/*.local.yml\n/config/credentials/local.*\n"
19
+ end
20
+ end
21
+
22
+ def add_setup_autoload_to_config
23
+ inject_into_file "config/application.rb", after: %r{< Rails::Application\n} do
24
+ <<-RUBY
25
+ # Configure the path for configuration classes that should be used before initialization
26
+ # NOTE: path should be relative to the project root (Rails.root)
27
+ #{default_configs_path? ? "# " : ""}config.anyway_config.autoload_static_config_path = "#{static_config_root}"
28
+ RUBY
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def static_config_root
35
+ options[:configs_path] || Anyway::Settings.autoload_static_config_path || Anyway::DEFAULT_CONFIGS_PATH
36
+ end
37
+
38
+ def default_configs_path?
39
+ static_config_root == (Anyway::Settings.autoload_static_config_path || Anyway::DEFAULT_CONFIGS_PATH)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Base class for application config classes
4
+ class ApplicationConfig < Anyway::Config
5
+ class << self
6
+ # Make it possible to access a singleton config instance
7
+ # via class methods (i.e., without explictly calling `instance`)
8
+ delegate_missing_to :instance
9
+
10
+ private
11
+
12
+ # Returns a singleton config instance
13
+ def instance
14
+ @instance ||= new
15
+ end
16
+ end
17
+ end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anyway_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre2
4
+ version: 2.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-04 00:00:00.000000000 Z
11
+ date: 2020-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-next-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: ammeter
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.3
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +52,20 @@ dependencies:
24
52
  - - ">="
25
53
  - !ruby/object:Gem::Version
26
54
  version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '13.0'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: rspec
29
71
  requirement: !ruby/object:Gem::Requirement
@@ -39,19 +81,19 @@ dependencies:
39
81
  - !ruby/object:Gem::Version
40
82
  version: '3.8'
41
83
  - !ruby/object:Gem::Dependency
42
- name: simplecov
84
+ name: ruby-next
43
85
  requirement: !ruby/object:Gem::Requirement
44
86
  requirements:
45
87
  - - ">="
46
88
  - !ruby/object:Gem::Version
47
- version: 0.3.8
89
+ version: '0.5'
48
90
  type: :development
49
91
  prerelease: false
50
92
  version_requirements: !ruby/object:Gem::Requirement
51
93
  requirements:
52
94
  - - ">="
53
95
  - !ruby/object:Gem::Version
54
- version: 0.3.8
96
+ version: '0.5'
55
97
  description: "\n Configuration DSL for Ruby libraries and applications.\n Allows
56
98
  you to easily follow the twelve-factor application principles (https://12factor.net/config).\n
57
99
  \ "
@@ -61,27 +103,50 @@ executables: []
61
103
  extensions: []
62
104
  extra_rdoc_files: []
63
105
  files:
106
+ - CHANGELOG.md
64
107
  - LICENSE.txt
65
108
  - README.md
109
+ - lib/.rbnext/2.7/anyway/auto_cast.rb
110
+ - lib/.rbnext/2.7/anyway/config.rb
111
+ - lib/.rbnext/2.7/anyway/option_parser_builder.rb
112
+ - lib/.rbnext/2.7/anyway/tracing.rb
66
113
  - lib/anyway.rb
114
+ - lib/anyway/auto_cast.rb
67
115
  - lib/anyway/config.rb
68
116
  - lib/anyway/dynamic_config.rb
69
117
  - lib/anyway/env.rb
70
118
  - lib/anyway/ext/deep_dup.rb
71
119
  - lib/anyway/ext/deep_freeze.rb
72
120
  - lib/anyway/ext/hash.rb
73
- - lib/anyway/ext/string_serialize.rb
74
- - lib/anyway/loaders/env_loader.rb
75
- - lib/anyway/loaders/secrets_loader.rb
76
- - lib/anyway/loaders/yaml_loader.rb
121
+ - lib/anyway/loaders.rb
122
+ - lib/anyway/loaders/base.rb
123
+ - lib/anyway/loaders/env.rb
124
+ - lib/anyway/loaders/yaml.rb
77
125
  - lib/anyway/option_parser_builder.rb
78
126
  - lib/anyway/optparse_config.rb
127
+ - lib/anyway/rails.rb
79
128
  - lib/anyway/rails/config.rb
129
+ - lib/anyway/rails/loaders.rb
130
+ - lib/anyway/rails/loaders/credentials.rb
131
+ - lib/anyway/rails/loaders/secrets.rb
132
+ - lib/anyway/rails/loaders/yaml.rb
133
+ - lib/anyway/rails/settings.rb
80
134
  - lib/anyway/railtie.rb
135
+ - lib/anyway/settings.rb
81
136
  - lib/anyway/testing.rb
82
137
  - lib/anyway/testing/helpers.rb
138
+ - lib/anyway/tracing.rb
83
139
  - lib/anyway/version.rb
84
140
  - lib/anyway_config.rb
141
+ - lib/generators/anyway/app_config/USAGE
142
+ - lib/generators/anyway/app_config/app_config_generator.rb
143
+ - lib/generators/anyway/config/USAGE
144
+ - lib/generators/anyway/config/config_generator.rb
145
+ - lib/generators/anyway/config/templates/config.rb.tt
146
+ - lib/generators/anyway/config/templates/config.yml.tt
147
+ - lib/generators/anyway/install/USAGE
148
+ - lib/generators/anyway/install/install_generator.rb
149
+ - lib/generators/anyway/install/templates/application_config.rb.tt
85
150
  homepage: http://github.com/palkan/anyway_config
86
151
  licenses:
87
152
  - MIT
@@ -106,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
171
  - !ruby/object:Gem::Version
107
172
  version: 1.3.1
108
173
  requirements: []
109
- rubygems_version: 3.0.4
174
+ rubygems_version: 3.0.6
110
175
  signing_key:
111
176
  specification_version: 4
112
177
  summary: Configuration DSL for Ruby libraries and applications
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Anyway
4
- module Ext
5
- # Extend String through refinements
6
- module StringSerialize
7
- # Regexp to detect array values
8
- # Array value is a values that contains at least one comma
9
- # and doesn't start/end with quote
10
- ARRAY_RXP = /\A[^'"].*\s*,\s*.*[^'"]\z/
11
-
12
- refine ::String do
13
- def serialize
14
- case self
15
- when ARRAY_RXP
16
- split(/\s*,\s*/).map { |word| word.serialize }
17
- when /\A(true|t|yes|y)\z/i
18
- true
19
- when /\A(false|f|no|n)\z/i
20
- false
21
- when /\A(nil|null)\z/i
22
- nil
23
- when /\A\d+\z/
24
- to_i
25
- when /\A\d*\.\d+\z/
26
- to_f
27
- when /\A['"].*['"]\z/
28
- gsub(/(\A['"]|['"]\z)/, "")
29
- else
30
- self
31
- end
32
- end
33
- end
34
-
35
- using self
36
- end
37
- end
38
- end
File without changes
File without changes
File without changes