active-dbml 0.1.0 → 0.2.1

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: 8221dbee838a7444be8ba17b7e186639411170beed4acd2f6096bc4ce5d822f2
4
- data.tar.gz: 2ef8374f20e734b3f0c34180cce1cb542d2e875998ff0693676728b356acbfbc
3
+ metadata.gz: ddecc1470323e8c7f6db8edef2bf5eac1503419eb7e58eaedfb24342ff97d15d
4
+ data.tar.gz: 52e7fc986872d0b5bb1322a7d20cb1ad784273d70afaa7a28c99b36011cb8657
5
5
  SHA512:
6
- metadata.gz: 062d762e36de8e9e80996ef58f289930fb28955c5dfb67a069bb6b28030ad3188b69660b6629283b1b9e203304410b70e41b9f806ff954828cdff2ad2ae90de0
7
- data.tar.gz: bd8626a3d86dfa3004c5495084a81164cb108d93707e1ebae45e04b8adf4bab35d3428a9d08fe60ce3f2eb9071b5d90bf8ab6466e322da93cf4875a314205a73
6
+ metadata.gz: cfd9f9f73ad07709ed7d4e5d4c6b95d55723a2f698dfbd175ef8d02d0d8a3aa4ad33ab64fa0435cf97ebebd89eea75798bb97f922765b5254e673b93e03bb1b7
7
+ data.tar.gz: 632639874f797f81ee84a26c1affbfbf71b67e43f5da9062e019548c8f9782684b71160a8b865fc53334224c09945b78a76c4f89f56aa3ca493863b3acdef3cf
data/README.md CHANGED
@@ -13,6 +13,12 @@ ActiveDBML is open for improvements. We eagerly welcome and encourage pull reque
13
13
  - [English](/)
14
14
  - [日本語](/docs/ja.md)
15
15
 
16
+ ## Support
17
+ Supports Rails 6 or higher.
18
+
19
+ ## Future plans
20
+ - Support for Polymorphic associations.
21
+
16
22
 
17
23
  ## Usage
18
24
 
@@ -1,5 +1,5 @@
1
1
  module Active
2
2
  module Dbml
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
data/lib/active/dbml.rb CHANGED
@@ -17,6 +17,9 @@ module Active
17
17
 
18
18
  models.each do |model|
19
19
  if ActiveRecord::Base.connection.table_exists?(model.table_name)
20
+ # 抽象クラスはスキップ
21
+ next if model.abstract_class?
22
+
20
23
  primary_key = get_primary_key(model)
21
24
  foreign_keys = get_foreign_keys(model)
22
25
 
@@ -43,6 +46,10 @@ module Active
43
46
  end
44
47
 
45
48
  dbml_output.join("\n")
49
+ # begin
50
+ # rescue => exception
51
+ # Rails.logger.error exception
52
+ # end
46
53
  end
47
54
 
48
55
  private
@@ -53,12 +60,14 @@ module Active
53
60
  def self.get_foreign_keys(model)
54
61
  foreign_keys = {}
55
62
 
56
- model.reflect_on_all_associations.each do |association|
57
- case association.macro
58
- when :belongs_to
59
- foreign_key = association.options[:foreign_key]
60
- foreign_key_destination = "#{association.plural_name}.#{association.class_name.constantize.primary_key}"
63
+ # get foreign key only belongs_to association
64
+ model.reflect_on_all_associations(:belongs_to).each do |association|
65
+ foreign_key = association.options[:foreign_key]
66
+ foreign_key_destination = "#{association.plural_name}.#{association.class_name.constantize.primary_key}"
61
67
 
68
+ # NOTE: Check model type
69
+ # Skip anything other than ActiveRecord::Base
70
+ if association.class_name.constantize < ActiveRecord::Base
62
71
  association.class_name.constantize.reflect_on_all_associations.each do |relation_association|
63
72
  if model.table_name.eql?(relation_association.plural_name)
64
73
  case relation_association.macro
@@ -70,6 +79,12 @@ module Active
70
79
  end
71
80
  end
72
81
  end
82
+ elsif association.class_name.constantize < ActiveYaml::Base
83
+ puts "⚠ #{association.class_name.constantize} is an ActiveYaml model."
84
+ elsif association.class_name.constantize < ActiveHash::Base
85
+ puts "⚠ #{association.class_name.constantize} is an ActiveHash model."
86
+ else
87
+ puts "⚠ Cannot determine type of #{association.class_name.constantize}"
73
88
  end
74
89
  end
75
90
 
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-dbml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ukmshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-26 00:00:00.000000000 Z
11
+ date: 2023-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '7'
19
+ version: '6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '7'
26
+ version: '6'
27
27
  description: Active::DBML is a new, useful Ruby gem designed to streamline database
28
28
  development.
29
29
  email: