config_file_manager 0.1.2 → 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: 9b4fdc0a8ed8426e6d4ecd41d04ff9ad0aa8e817aca12189cc6cbe0878b81748
4
- data.tar.gz: 903cfee08159f7a560fbc8305282d540799f06271363862898aaa4121545981c
3
+ metadata.gz: e292b152343b7533c6dc061be052d078fb351e9506e54e093dd2070ae82db895
4
+ data.tar.gz: f37d1f71cf8c1c71e844366832740ba472b0e7b65b0dd1dd11303419f03a84ee
5
5
  SHA512:
6
- metadata.gz: 305ed92cf6e19d9b6b4d5ab1af990f5dde5236c53345e206797081ccb8eb43890def787aa3834fe325ecab0bdd31cfcbe522c88315e11c3abe406ce1654fff38
7
- data.tar.gz: 1c5368b9ef06c10ce0476f1c3f09589869e134547bf7350aad2ef75bb12bd29a0ff0613287cb0a88ddca14f3d8f00773725d26758e658edb07d6b777d65997fc
6
+ metadata.gz: 31c41b7c8361f5ed1b29a4acc765f4052985585c2348cc91211cdfc0e83687955965b5bdb2158bfeff7f4d486207237981ab7fe0cdc8301b0f99eaf193af90aa
7
+ data.tar.gz: da52f61bdee2f0c9d6ce90f2777a47ca92170591771359d1d1cc6262564a869d26016fee418da1455b123519e26f57bbfa7c0b1c644e2a742fab649c4e5de47e
data/CHANGELOG.md CHANGED
@@ -1,4 +1,6 @@
1
- ## [Unreleased]
1
+ ## [0.1.3] - 2023-11-30
2
+
3
+ - Add json parsing
2
4
 
3
5
  ## [0.1.2] - 2023-08-29
4
6
 
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.2'
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'
@@ -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.2
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-29 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.