schema_doctor 0.0.3 → 0.0.5

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: 36282d15058adc20e4b9c2013bb9ddaa1d95f1e9457a10278be99a7b40c900e4
4
- data.tar.gz: baf1eae580dedd1d8cbe4c5ca5bfef36e08849589aec89856731a9680cfc268a
3
+ metadata.gz: 6645ba5de2a372f1d51c535e99012282cf5a731beb86d5477e8632ffd8a07676
4
+ data.tar.gz: 1268f1f6a14ce3b1436d0dc1f985a7f6716eac861adbeb62f3ce13a74746a6ae
5
5
  SHA512:
6
- metadata.gz: 917c1f0b805be6028f319f00698fdc153aedc38ffbf3b7ff6b780fc1d9eb4fd3fb7c0a106d4185cd32c54547279b509c869645a24ac3ca8849d2d5af6e4061a8
7
- data.tar.gz: b309be6513ad10e6bf0563c9da4c87d1c9b17507f87d1a670527cc6c73f0f1b41ce0dab22a5b5b395fa3a196df991f96415078c33aaad3677e1163c87a6bb5ec
6
+ metadata.gz: e4a3327c45cb32ce5dd14202a038ebc69b9fe563b15a0dfda680eca428be4de06881db55f33e3540ca61cbc671e4392fa5300a1cbb1efb354d6870796ab69f7e
7
+ data.tar.gz: 90ba1d5f0f278d921448bd468e19c96f1bcca5107523fac92642aa9c9c5697cd912385027fea4fda529fe5ce471b7e63c3a265e52ebee00b3692d36ad02e6e2b
data/.standard.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  # For available configuration options, see:
2
2
  # https://github.com/standardrb/standard
3
3
  ruby_version: 3.0
4
+ format: progress
@@ -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: association.options,
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: association.options
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
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SchemaDoctor
4
+ class Utils
5
+ class << self
6
+ def safety_dump_hash(obj)
7
+ case obj
8
+ when Hash
9
+ obj.transform_values { |v| safety_dump_hash(v) }
10
+ when Array
11
+ obj.map { |v| safety_dump_hash(v) }
12
+ when TrueClass, FalseClass, NilClass, Integer, Float, String
13
+ obj
14
+ else
15
+ obj.to_s
16
+ end
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
29
+ end
30
+ end
31
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SchemaDoctor
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.5"
5
5
  end
data/lib/schema_doctor.rb CHANGED
@@ -4,7 +4,8 @@ require_relative "schema_doctor/version"
4
4
  require_relative "schema_doctor/schema_file"
5
5
  require_relative "schema_doctor/analyzer"
6
6
  require_relative "schema_doctor/exporter"
7
- require_relative "schema_doctor/railtie"
7
+ require_relative "schema_doctor/utils"
8
+ require_relative "schema_doctor/railtie" if defined?(Rails::Railtie)
8
9
 
9
10
  module SchemaDoctor
10
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.3
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-08-04 00:00:00.000000000 Z
11
+ date: 2024-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -71,12 +71,15 @@ files:
71
71
  - lib/schema_doctor/railtie.rb
72
72
  - lib/schema_doctor/schema_file.rb
73
73
  - lib/schema_doctor/tasks/schemadoc.rake
74
+ - lib/schema_doctor/utils.rb
74
75
  - lib/schema_doctor/version.rb
75
76
  - sig/schema_doctor.rbs
76
77
  homepage: https://github.com/lnit/schema_doctor
77
78
  licenses:
78
79
  - MIT
79
80
  metadata:
81
+ homepage_uri: https://github.com/lnit/schema_doctor
82
+ source_code_uri: https://github.com/lnit/schema_doctor
80
83
  changelog_uri: https://github.com/lnit/schema_doctor/blob/master/CHANGELOG.md
81
84
  post_install_message:
82
85
  rdoc_options: []
@@ -93,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
96
  - !ruby/object:Gem::Version
94
97
  version: '0'
95
98
  requirements: []
96
- rubygems_version: 3.5.9
99
+ rubygems_version: 3.5.16
97
100
  signing_key:
98
101
  specification_version: 4
99
102
  summary: Automatic database documentation tool.