securial 2.1.5 → 2.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 380f3eb7c41909962f49e0d860ac4ebfb8948b4477557ca0d4fc3a3b599b78c6
4
- data.tar.gz: fe9c3e04c95f70836d453e36f4bbaf67b428a397c05a7516ca42d152a8368f9d
3
+ metadata.gz: 914b5c4ac539dfc8c6994f001eeec7237a0fbda2030c828898864b9371ac2ac4
4
+ data.tar.gz: 3b23660aa0a8e439d0bfa46f8bfab87949634dd84a45eaedb91088058a1576d3
5
5
  SHA512:
6
- metadata.gz: 2a144e1b69790b12456fb2db21218f3ae77cf72c148a92af38d7934ab21740af566b4bd2155738d90d490da4004f12531a447296c674565b54774f667c33719b
7
- data.tar.gz: 50404735621bed58aa44b3a98a5387a85093ea9d0a68050daa39e21fcad42fab30efbcf953b63c118b5d77dec4c640c47bc0e84a1c1382225030670f9aa18612
6
+ metadata.gz: 5f50a95757c49396f0c45ce9970e9f4333603e8499f8ae532def4f3d96252ec8dc91be4533f8f2cb190e2d905fd6cfcb4bccec4aad978ead7ed99bcedc40e183
7
+ data.tar.gz: a7e219a841c30569a68dec40b3ff2abbca4f446a60c6e0de7214a470bb188eb1bdcded2bea1c86a79ba5b31752f2b746bebde25c8b58ddce1dd4e6031d89fffb
data/lib/securial/cli.rb CHANGED
@@ -208,43 +208,33 @@ module Securial
208
208
  adapter = config.dig("default", "adapter")
209
209
  return unless adapter.is_a?(String) && %w[postgresql mysql2].include?(adapter)
210
210
 
211
- # Step 2: Modify the raw file line-by-line to preserve anchors and formatting
211
+ # Step 2: Modify the raw YAML file line-by-line
212
212
  lines = File.readlines(db_config_path)
213
- inside_default = false
214
213
  updated_lines = []
214
+ inside_default = false
215
+ inserted = false
216
+
217
+ lines.each do |line|
218
+ updated_lines << line
215
219
 
216
- lines.each_with_index do |line, index|
217
220
  if line =~ /^default:/
218
221
  inside_default = true
219
- updated_lines << line
220
222
  next
221
223
  end
222
224
 
223
- if inside_default
224
- # Break out of default block when another top-level key appears
225
- if line =~ /^\S/ && line !~ /^\s/
226
- inside_default = false
227
- end
228
-
229
- # Skip existing host/username/password lines
230
- next if line =~ /^\s*(host|username|password):/
225
+ if inside_default && line.strip.start_with?("adapter:")
226
+ # Insert immediately after the adapter line
227
+ updated_lines += [
228
+ " host: <%= ENV.fetch(\"DB_HOST\", \"localhost\") %>\n",
229
+ " username: <%= ENV.fetch(\"DB_USERNAME\") { \"postgres\" } %>\n",
230
+ " password: <%= ENV.fetch(\"DB_PASSWORD\") { \"postgres\" } %>\n",
231
+ ]
232
+ inserted = true
231
233
  end
232
234
 
233
- updated_lines << line
235
+ # Exit `default:` block when another top-level key appears
236
+ inside_default = false if inside_default && line =~ /^\S/ && line !~ /^\s/
234
237
  end
235
-
236
- # Find index of `default:` line to insert after
237
- insert_index = updated_lines.find_index { |l| l =~ /^default:/ }
238
- return unless insert_index
239
-
240
- injection = [
241
- " host: <%= ENV.fetch(\"DB_HOST\", \"localhost\") %>",
242
- " username: <%= ENV.fetch(\"DB_USERNAME\") { \"postgres\" } %>",
243
- " password: <%= ENV.fetch(\"DB_PASSWORD\") { \"postgres\" } %>",
244
- ]
245
-
246
- updated_lines.insert(insert_index + 1, *injection)
247
-
248
238
  File.write(db_config_path, updated_lines.join)
249
239
  end
250
240
 
@@ -6,5 +6,5 @@ module Securial
6
6
  #
7
7
  # @see https://semver.org/ Semantic Versioning 2.0.0
8
8
  # @return [String] the current version in the format "major.minor.patch"
9
- VERSION = "2.1.5".freeze
9
+ VERSION = "2.1.6".freeze
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: securial
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 2.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aly Badawy