ask-ruby-harness 0.3.1 → 0.3.2

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: b57d0a2408bc2432ed17401048b318263ac9e11709d73cd4eba7b2b47d2e9997
4
- data.tar.gz: 910fa5fdc3a9a8da190fe05bd5326698043f4615853f3908648c05df55316d51
3
+ metadata.gz: bc926a8ba86f90bbc682d1361f4b436decfb071f543303a4f1055b7d8e986b59
4
+ data.tar.gz: b49641a4b3d21015363f0744ea28a5a146dd42eec21859120faee3977adfcba1
5
5
  SHA512:
6
- metadata.gz: 184e86499d3e1eede9de25e6ee241dc01dfaa2f504ae5de616c7e64cf845b83f12ee2e7681e55b7310078e72435db14f7a806e2526dcced4d70c298cecbb7518
7
- data.tar.gz: 49e9aae381d3d619787f1420f103b1d09732de6370cb43dc367b5d2d82e8cb6f1043394e449812f53abbe13faff70aa3dd1761a020f8d556f41077e477a2942a
6
+ metadata.gz: fe9cef5ac7bab9ae6742e988b0e46359d95809aedc91995918dd49d1481e770819d1e08388b90e60a3d1db0b4344dd32309ff317808283bf9ef4031104cd1713
7
+ data.tar.gz: b29401a3227880eb954e684b14fe4b197da492da840d1ab068f594f10007e6309deeeae95ca6bc5afcd6108fbadb1e119589bba5c478eb4ff959d9dbefba809e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## [0.3.2] — 2026-08-12
2
+
3
+ ### Fixed
4
+
5
+ - **ERB-safe `config/database.yml` parsing** — `database_yaml` now renders
6
+ ERB (Rails-style) before YAML loading. Raw `YAML.safe_load` choked on the
7
+ ERB most real database.yml files embed (ENV/credentials), so the named
8
+ database fallback reported "not found" for those apps.
9
+ - **Env-name lookup for named databases** — `database: "production"` from a
10
+ development-booted server now resolves that environment's own section in
11
+ `config/database.yml`: its flat single-DB config, or its `primary` pool
12
+ for multi-DB apps.
13
+
1
14
  ## [0.3.0] — 2026-08-10
2
15
 
3
16
  ### Added
@@ -3,7 +3,7 @@
3
3
  module Ask
4
4
  module Ruby
5
5
  module Harness
6
- VERSION = "0.3.1"
6
+ VERSION = "0.3.2"
7
7
  end
8
8
  end
9
9
  end
@@ -97,7 +97,11 @@ module Ask
97
97
  # Config for a NAMED database. Resolution order:
98
98
  # 1. the host app's own configurations registry (Rails multi-DB —
99
99
  # resolves credentials/ENV for us),
100
- # 2. config/database.yml, the environment section's key.
100
+ # 2. config/database.yml, the current environment section's key,
101
+ # 3. config/database.yml, the named environment section itself —
102
+ # "database: production" from a development-booted server
103
+ # resolves production's config (its "primary" pool for
104
+ # multi-DB apps).
101
105
  def database_config_for(name)
102
106
  name = name.to_s
103
107
  if ActiveRecord::Base.respond_to?(:configurations)
@@ -107,6 +111,15 @@ module Ask
107
111
 
108
112
  section = database_yaml_section
109
113
  config = section[name] if section.is_a?(Hash) && section[name].is_a?(Hash)
114
+ return sanitize_database_config(config) if config
115
+
116
+ yaml = database_yaml
117
+ env_section = yaml[name] if yaml.is_a?(Hash)
118
+ return nil unless env_section.is_a?(Hash)
119
+
120
+ # Multi-DB apps nest pools under the env key; single-DB apps keep
121
+ # the connection config flat under it.
122
+ config = env_section["primary"].is_a?(Hash) ? env_section["primary"] : env_section
110
123
  sanitize_database_config(config)
111
124
  end
112
125
 
@@ -205,12 +218,22 @@ module Ask
205
218
  private
206
219
 
207
220
  def database_yaml_section
221
+ yaml = database_yaml || {}
222
+ yaml[env] || yaml["development"] || {}
223
+ end
224
+
225
+ # Parses config/database.yml with ERB preprocessing (Rails-style) —
226
+ # most real database.yml files embed ENV/credentials ERB, which raw
227
+ # YAML.safe_load cannot parse. Returns nil when unreadable; the
228
+ # callers fall back to the Rails configurations registry.
229
+ def database_yaml
208
230
  path = app_root.join("config", "database.yml")
209
231
  return nil unless path.exist?
210
232
 
211
- yaml = YAML.safe_load(path.read, aliases: true) || {}
212
- yaml[env] || yaml["development"] || {}
213
- rescue Psych::Exception
233
+ require "erb"
234
+ rendered = ERB.new(path.read).result
235
+ YAML.safe_load(rendered, aliases: true) || {}
236
+ rescue Psych::Exception, NameError, SyntaxError
214
237
  nil
215
238
  end
216
239
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ask-ruby-harness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaka Ruto