config_file_manager 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -1
- data/README.md +13 -5
- data/lib/config_file_manager/version.rb +1 -1
- data/lib/config_file_manager.rb +13 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e292b152343b7533c6dc061be052d078fb351e9506e54e093dd2070ae82db895
|
4
|
+
data.tar.gz: f37d1f71cf8c1c71e844366832740ba472b0e7b65b0dd1dd11303419f03a84ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31c41b7c8361f5ed1b29a4acc765f4052985585c2348cc91211cdfc0e83687955965b5bdb2158bfeff7f4d486207237981ab7fe0cdc8301b0f99eaf193af90aa
|
7
|
+
data.tar.gz: da52f61bdee2f0c9d6ce90f2777a47ca92170591771359d1d1cc6262564a869d26016fee418da1455b123519e26f57bbfa7c0b1c644e2a742fab649c4e5de47e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -38,8 +38,16 @@ You can use this gem to easily configure automatic symlinking of config files in
|
|
38
38
|
```rb
|
39
39
|
# config/deploy.rb
|
40
40
|
|
41
|
-
|
42
|
-
|
41
|
+
# path to the repo root
|
42
|
+
root_path = File.expand_path('..', __dir__)
|
43
|
+
# path to the `config/` directory
|
44
|
+
config_dir_path = File.expand_path(__dir__)
|
45
|
+
|
46
|
+
config_file_manager = ConfigFileManager.new(config_dir_path)
|
47
|
+
# get absolute paths to all config files and change them
|
48
|
+
# to relative paths (relative to the repo root)
|
49
|
+
linked_files = config_file_manager.files.map { _1.delete_prefix("#{root_path}/") }
|
50
|
+
set :linked_files, linked_files
|
43
51
|
```
|
44
52
|
|
45
53
|
That way you don't have to specify the config files by hand.
|
@@ -53,7 +61,7 @@ Create an initializer that will be executed first and creates a configured insta
|
|
53
61
|
```rb
|
54
62
|
# config/initializers/0_config_file_manager.rb
|
55
63
|
|
56
|
-
CONFIG_MANAGER = ConfigFileManager.new(
|
64
|
+
CONFIG_MANAGER = ConfigFileManager.new(Rails.root.join('config'), env: Rails.env)
|
57
65
|
```
|
58
66
|
|
59
67
|
And then you can you it to conveniently load config files.
|
@@ -181,7 +189,7 @@ loader.to_relative_path("/Users/Verseth/my_app/config/foo.yml")
|
|
181
189
|
#=> "foo.yml"
|
182
190
|
```
|
183
191
|
|
184
|
-
|
192
|
+
### to_absolute_path
|
185
193
|
|
186
194
|
Converts an absolute path within the config directory to a relative path.
|
187
195
|
|
@@ -208,7 +216,7 @@ production:
|
|
208
216
|
foo: prod value <%= 10 - 2 %>
|
209
217
|
```
|
210
218
|
|
211
|
-
You
|
219
|
+
You can load it like so.
|
212
220
|
|
213
221
|
```rb
|
214
222
|
loader = ConfigFileManager.new(File.expand_path('config', __dir__))
|
data/lib/config_file_manager.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'fileutils'
|
4
|
+
require 'json'
|
4
5
|
require 'yaml'
|
5
6
|
require 'erb'
|
6
7
|
require 'pastel'
|
@@ -179,6 +180,18 @@ class ConfigFileManager
|
|
179
180
|
parsed[env]
|
180
181
|
end
|
181
182
|
|
183
|
+
# @param file_name [Array<String>]
|
184
|
+
# @param env [String, nil]
|
185
|
+
# @param symbolize [Boolean] Whether the keys should be converted to Ruby symbols
|
186
|
+
# @return [Hash, Array]
|
187
|
+
def load_json(*file_name, env: @env, symbolize: true)
|
188
|
+
env = env.to_sym if env && symbolize
|
189
|
+
parsed = ::JSON.parse(load_erb(*file_name), symbolize_names: symbolize)
|
190
|
+
return parsed unless env
|
191
|
+
|
192
|
+
parsed[env]
|
193
|
+
end
|
194
|
+
|
182
195
|
# @param file_name [Array<String>]
|
183
196
|
def delete_file(*file_name)
|
184
197
|
::File.delete(file_path(*file_name))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: config_file_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateusz Drewniak
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
requirements: []
|
64
|
-
rubygems_version: 3.4.
|
64
|
+
rubygems_version: 3.4.21
|
65
65
|
signing_key:
|
66
66
|
specification_version: 4
|
67
67
|
summary: Gem that makes it easy to load config files.
|