schema_doctor 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.standard.yml +1 -0
- data/lib/schema_doctor/analyzer.rb +7 -7
- data/lib/schema_doctor/schema_file.rb +2 -2
- data/lib/schema_doctor/utils.rb +14 -3
- data/lib/schema_doctor/version.rb +1 -1
- data/lib/schema_doctor.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6645ba5de2a372f1d51c535e99012282cf5a731beb86d5477e8632ffd8a07676
|
4
|
+
data.tar.gz: 1268f1f6a14ce3b1436d0dc1f985a7f6716eac861adbeb62f3ce13a74746a6ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4a3327c45cb32ce5dd14202a038ebc69b9fe563b15a0dfda680eca428be4de06881db55f33e3540ca61cbc671e4392fa5300a1cbb1efb354d6870796ab69f7e
|
7
|
+
data.tar.gz: 90ba1d5f0f278d921448bd468e19c96f1bcca5107523fac92642aa9c9c5697cd912385027fea4fda529fe5ce471b7e63c3a265e52ebee00b3692d36ad02e6e2b
|
data/.standard.yml
CHANGED
@@ -25,7 +25,7 @@ module SchemaDoctor
|
|
25
25
|
next if model.table_name.blank?
|
26
26
|
|
27
27
|
puts "Processing #{model.name}..."
|
28
|
-
schema[model.name] =
|
28
|
+
schema[model.name.to_sym] =
|
29
29
|
{
|
30
30
|
name: model.name,
|
31
31
|
table_name: model.table_name,
|
@@ -61,7 +61,7 @@ module SchemaDoctor
|
|
61
61
|
|
62
62
|
def columns(model, columns = {})
|
63
63
|
model.columns.each do |column|
|
64
|
-
columns[column.name] =
|
64
|
+
columns[column.name.to_sym] =
|
65
65
|
{
|
66
66
|
name: column.name,
|
67
67
|
type: column.type,
|
@@ -80,7 +80,7 @@ module SchemaDoctor
|
|
80
80
|
|
81
81
|
def indexes(model)
|
82
82
|
connection.indexes(model.table_name).each_with_object({}) do |index, hash|
|
83
|
-
hash[index.name] = {
|
83
|
+
hash[index.name.to_sym] = {
|
84
84
|
name: index.name,
|
85
85
|
columns: index.columns,
|
86
86
|
unique: index.unique,
|
@@ -98,20 +98,20 @@ module SchemaDoctor
|
|
98
98
|
model.reflect_on_all_associations.each do |association|
|
99
99
|
case association.macro.to_s
|
100
100
|
when /\Abelongs_to/
|
101
|
-
result[:belongs][association.name] = {
|
101
|
+
result[:belongs][association.name.to_sym] = {
|
102
102
|
macro: association.macro.to_s,
|
103
103
|
name: association.name,
|
104
104
|
class_name: association.class_name,
|
105
105
|
foreign_key: association.foreign_key,
|
106
|
-
options: Utils.
|
106
|
+
options: Utils.safety_dump_hash(association.options),
|
107
107
|
polymorphic: association.polymorphic?
|
108
108
|
}
|
109
109
|
when /\Ahas/
|
110
|
-
result[:has][association.name] = {
|
110
|
+
result[:has][association.name.to_sym] = {
|
111
111
|
macro: association.macro.to_s,
|
112
112
|
name: association.name,
|
113
113
|
class_name: association.class_name,
|
114
|
-
options: Utils.
|
114
|
+
options: Utils.safety_dump_hash(association.options)
|
115
115
|
}
|
116
116
|
else
|
117
117
|
puts "Unknown association type: #{association.macro}: :#{association.name}"
|
@@ -9,14 +9,14 @@ module SchemaDoctor
|
|
9
9
|
|
10
10
|
# Load schema specification files and merge them into a single hash
|
11
11
|
Dir.glob("#{schema_dir}/*").inject({}) do |hash, file|
|
12
|
-
hash.merge(YAML.load_file(file))
|
12
|
+
hash.merge(YAML.load_file(file, symbolize_names: true))
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
def dump(specs)
|
17
17
|
# Output specification files for each model
|
18
18
|
FileUtils.mkdir_p(schema_dir)
|
19
|
-
specs.each do |name, spec|
|
19
|
+
Utils.deep_stringify(specs).each do |name, spec|
|
20
20
|
File.open("#{schema_dir}/#{name}.yml", "w") do |f|
|
21
21
|
YAML.dump({name => spec}, f)
|
22
22
|
end
|
data/lib/schema_doctor/utils.rb
CHANGED
@@ -3,18 +3,29 @@
|
|
3
3
|
module SchemaDoctor
|
4
4
|
class Utils
|
5
5
|
class << self
|
6
|
-
def
|
6
|
+
def safety_dump_hash(obj)
|
7
7
|
case obj
|
8
8
|
when Hash
|
9
|
-
obj.transform_values { |v|
|
9
|
+
obj.transform_values { |v| safety_dump_hash(v) }
|
10
10
|
when Array
|
11
|
-
obj.map { |v|
|
11
|
+
obj.map { |v| safety_dump_hash(v) }
|
12
12
|
when TrueClass, FalseClass, NilClass, Integer, Float, String
|
13
13
|
obj
|
14
14
|
else
|
15
15
|
obj.to_s
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
def deep_stringify(obj)
|
20
|
+
case obj
|
21
|
+
when Hash
|
22
|
+
obj.transform_keys(&:to_s).transform_values { |v| deep_stringify(v) }
|
23
|
+
when Array
|
24
|
+
obj.map { |v| deep_stringify(v) }
|
25
|
+
else
|
26
|
+
obj
|
27
|
+
end
|
28
|
+
end
|
18
29
|
end
|
19
30
|
end
|
20
31
|
end
|
data/lib/schema_doctor.rb
CHANGED
@@ -5,7 +5,7 @@ require_relative "schema_doctor/schema_file"
|
|
5
5
|
require_relative "schema_doctor/analyzer"
|
6
6
|
require_relative "schema_doctor/exporter"
|
7
7
|
require_relative "schema_doctor/utils"
|
8
|
-
require_relative "schema_doctor/railtie"
|
8
|
+
require_relative "schema_doctor/railtie" if defined?(Rails::Railtie)
|
9
9
|
|
10
10
|
module SchemaDoctor
|
11
11
|
class Error < StandardError; end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_doctor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lni_T
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -78,6 +78,8 @@ homepage: https://github.com/lnit/schema_doctor
|
|
78
78
|
licenses:
|
79
79
|
- MIT
|
80
80
|
metadata:
|
81
|
+
homepage_uri: https://github.com/lnit/schema_doctor
|
82
|
+
source_code_uri: https://github.com/lnit/schema_doctor
|
81
83
|
changelog_uri: https://github.com/lnit/schema_doctor/blob/master/CHANGELOG.md
|
82
84
|
post_install_message:
|
83
85
|
rdoc_options: []
|
@@ -94,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
96
|
- !ruby/object:Gem::Version
|
95
97
|
version: '0'
|
96
98
|
requirements: []
|
97
|
-
rubygems_version: 3.5.
|
99
|
+
rubygems_version: 3.5.16
|
98
100
|
signing_key:
|
99
101
|
specification_version: 4
|
100
102
|
summary: Automatic database documentation tool.
|