db_tools 0.1.1 → 0.1.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 +4 -4
- data/lib/db_tools/version.rb +1 -1
- data/lib/db_tools.rb +23 -7
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 326c65b22a64f78c54f46531150d1f3c83bf37e6a37ae5d2aeca513626acf46e
|
|
4
|
+
data.tar.gz: ec4411bf59f70d88d115e4ce63fecf253f178fd1b03151c81b2da745e9b46818
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d3e455432fece050f0b0f9345e5026ff9bdd5136b8fea3a2747d22cf27a8bae25901d979c1900e93a5d2b4ce6a6ff2b0b25c1c1998e2cb1221caa783665a4c0c
|
|
7
|
+
data.tar.gz: 9f14cd782f4bb211c913f6de11c3446d3394bb96368f0155571435e561ce29a644ceeff3147b79747821118d979add3bd03e2cba0f8c6e52e7da38b3af658084
|
data/lib/db_tools/version.rb
CHANGED
data/lib/db_tools.rb
CHANGED
|
@@ -38,7 +38,17 @@ module DbTools
|
|
|
38
38
|
path = File.join(root, "config", "database.yml")
|
|
39
39
|
raise Error, "No config/database.yml in #{root}" unless File.exist?(path)
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
source = File.read(path)
|
|
42
|
+
config = begin
|
|
43
|
+
development_section(ERB.new(source).result(Stubs.module_eval("binding")))
|
|
44
|
+
rescue NameError
|
|
45
|
+
UNRESOLVED
|
|
46
|
+
end
|
|
47
|
+
if config.to_s.include?(UNRESOLVED)
|
|
48
|
+
# The development database references the app (e.g. Rails credentials): boot it and try again.
|
|
49
|
+
require File.join(root, "config", "environment")
|
|
50
|
+
config = development_section(ERB.new(source).result)
|
|
51
|
+
end
|
|
42
52
|
raise Error, "config/database.yml has no development database" unless config.is_a?(Hash)
|
|
43
53
|
|
|
44
54
|
# Multi-database apps nest each database under a name; snapshot the primary one.
|
|
@@ -46,12 +56,18 @@ module DbTools
|
|
|
46
56
|
config
|
|
47
57
|
end
|
|
48
58
|
|
|
49
|
-
def self.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
def self.development_section(yaml)
|
|
60
|
+
YAML.safe_load(yaml, aliases: true)&.fetch("development", nil)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
UNRESOLVED = "__db_tools_unresolved__"
|
|
64
|
+
|
|
65
|
+
# Stands in for Rails while rendering database.yml, so other environments'
|
|
66
|
+
# credentials don't force booting the app (seconds) just to read development.
|
|
67
|
+
module Stubs
|
|
68
|
+
Rails = BasicObject.new
|
|
69
|
+
def Rails.method_missing(*) = self
|
|
70
|
+
def Rails.to_s = UNRESOLVED
|
|
55
71
|
end
|
|
56
72
|
|
|
57
73
|
# Runs a command without a shell and returns its stdout, raising on failure.
|