config_file_manager 0.1.1 → 0.1.3

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: 26d20f796f74a141b1bbd0ade461af62aaa1e4910a9ef0852e0b4d763d21dac0
4
- data.tar.gz: 48e06aed577794ee223251bf339c805a140a46c09cc842df1e7729f1b03d02b0
3
+ metadata.gz: e292b152343b7533c6dc061be052d078fb351e9506e54e093dd2070ae82db895
4
+ data.tar.gz: f37d1f71cf8c1c71e844366832740ba472b0e7b65b0dd1dd11303419f03a84ee
5
5
  SHA512:
6
- metadata.gz: '08a72f46169385ce9c4577ce55792e6f0a3f31904e963c974ef4126cae580e4f7285df9922784058b39efd13a89b3dae82b2e86adb8b235abe177ae290a28f2b'
7
- data.tar.gz: 3dbe69a543fad3646381737c9821b90585168c59722d4187a4a7b41ce6aaaf4a68bf5663b64324a81f88d898e2ec99cc85936c3a238fa8fd763dc500a6e33886
6
+ metadata.gz: 31c41b7c8361f5ed1b29a4acc765f4052985585c2348cc91211cdfc0e83687955965b5bdb2158bfeff7f4d486207237981ab7fe0cdc8301b0f99eaf193af90aa
7
+ data.tar.gz: da52f61bdee2f0c9d6ce90f2777a47ca92170591771359d1d1cc6262564a869d26016fee418da1455b123519e26f57bbfa7c0b1c644e2a742fab649c4e5de47e
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
- ## [Unreleased]
1
+ ## [0.1.3] - 2023-11-30
2
+
3
+ - Add json parsing
4
+
5
+ ## [0.1.2] - 2023-08-29
6
+
7
+ - Fix `ConfigFileManager#create_missing_dirs`
2
8
 
3
9
  ## [0.1.1] - 2023-08-28
4
10
 
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
- config_file_manager = ConfigFileManager.new(File.expand_path(__dir__))
42
- set :linked_files, config_file_manager.to_relative_paths(config_file_manager.files)
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(File.expand_path('..', __dir__), env: Rails.env)
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
- ## to_absolute_path
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 cna load it like so.
219
+ You can load it like so.
212
220
 
213
221
  ```rb
214
222
  loader = ConfigFileManager.new(File.expand_path('config', __dir__))
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ConfigFileManager # rubocop:disable Style/StaticClass
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.3'
5
5
  end
@@ -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'
@@ -125,7 +126,7 @@ class ConfigFileManager
125
126
  def create_missing_dirs(example_extension: @example_extension, print: false)
126
127
  puts COLORS.blue('== Copying missing config directories ==') if print
127
128
  dirs(example_extension: example_extension).each do |dir|
128
- create_missing_dir("#{dir}#{example_extension}", file, print: print)
129
+ create_missing_dir("#{dir}#{example_extension}", dir, print: print)
129
130
  end
130
131
  end
131
132
 
@@ -179,11 +180,28 @@ 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))
185
198
  end
186
199
 
200
+ # @param dir_name [Array<String>]
201
+ def delete_dir(*dir_name)
202
+ ::FileUtils.rm_r(file_path(*dir_name))
203
+ end
204
+
187
205
  # @param file_name [Array<String>]
188
206
  # @return [String]
189
207
  def load_erb(*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.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-08-28 00:00:00.000000000 Z
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.14
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.