schemard 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/schemard/relation_generator.rb +23 -4
- data/lib/schemard.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c5211b57dd34605e75aade506df6064eb7eed9a
|
4
|
+
data.tar.gz: 331ec3318e0616d80d448c69df11d2611a77dba4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a58160c570e363447459e1d883edd5999bf0568748ec771ea1b8d7298d3f59e96437573f161e9785799d6b1d980e1b68f07ee14fdf4e169475a6e564f20dae09
|
7
|
+
data.tar.gz: 384b99ab3d408844a9a73a0710d769f2dcb3014b8305cb90e1e1d471743d4ac62a95654b4245601bd9e9b1283c15bcad167bde5f56cd6149099d3761b32d9d81
|
@@ -33,10 +33,29 @@ module SchemaRD
|
|
33
33
|
.each_with_object({}) do |model, hash|
|
34
34
|
hash[model.table_name] = {}
|
35
35
|
|
36
|
-
relation_selector = ->(
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
relation_selector = ->(type){
|
37
|
+
# Over ActiveRecord 4.2.7
|
38
|
+
if defined?(ActiveRecord::Reflection::HasOneReflection)
|
39
|
+
klasses = {
|
40
|
+
has_one: ActiveRecord::Reflection::HasOneReflection,
|
41
|
+
has_many: ActiveRecord::Reflection::HasManyReflection,
|
42
|
+
belongs_to: ActiveRecord::Reflection::BelongsToReflection
|
43
|
+
}
|
44
|
+
model._reflections.values.select{|r| r.is_a?(klasses[type]) }
|
45
|
+
else
|
46
|
+
klasses = {
|
47
|
+
has_one: ActiveRecord::Associations::HasOneAssociation,
|
48
|
+
has_many: ActiveRecord::Associations::HasManyAssociation,
|
49
|
+
belongs_to: ActiveRecord::Associations::BelongsToAssociation
|
50
|
+
}
|
51
|
+
model.reflections.values
|
52
|
+
.select{|r| r.is_a?(ActiveRecord::Reflection::AssociationReflection) }
|
53
|
+
.select{|r| r.association_class == klasses[type] }
|
54
|
+
end
|
55
|
+
}
|
56
|
+
has_one_rels = relation_selector.call(:has_one)
|
57
|
+
has_many_rels = relation_selector.call(:has_many)
|
58
|
+
belongs_to_rels = relation_selector.call(:belongs_to)
|
40
59
|
|
41
60
|
if has_one_rels.present?
|
42
61
|
hash[model.table_name]["has_one"] = has_one_rels.map{|r| r.klass.table_name }
|
data/lib/schemard.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schemard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ken TANAKA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|