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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f93b6db46593a9933c132850585b4a7e03f55de2
4
- data.tar.gz: 1b7fab78d73c880a2779ff067e1207f167db3ead
3
+ metadata.gz: 6c5211b57dd34605e75aade506df6064eb7eed9a
4
+ data.tar.gz: 331ec3318e0616d80d448c69df11d2611a77dba4
5
5
  SHA512:
6
- metadata.gz: 0f68a074626339cb2f12d3c570fb137cab5a5812bedf176b09393eedcdd9d7dc22cd05143fd4f5c4acb841cb4f26f117bbcf118e3ea9da84b12532cfbb173d1b
7
- data.tar.gz: 7277d6c3a2242440ec52e0c7601edddcc8b2db6bb59e07bac25b816b8f9c992203c662f74054d03d5145b43600ea8b97e649c6777ecff76719b498876b54bcd2
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 = ->(klass){ model._reflections.values.select{|r| r.is_a?(klass) } }
37
- has_one_rels = relation_selector.call(ActiveRecord::Reflection::HasOneReflection)
38
- has_many_rels = relation_selector.call(ActiveRecord::Reflection::HasManyReflection)
39
- belongs_to_rels = relation_selector.call(ActiveRecord::Reflection::BelongsToReflection)
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
@@ -2,5 +2,5 @@ require_relative 'schemard/web_server'
2
2
  require_relative 'schemard/controller'
3
3
 
4
4
  module SchemaRD
5
- VERSION = "0.3.0"
5
+ VERSION = "0.3.1"
6
6
  end
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.0
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-09 00:00:00.000000000 Z
11
+ date: 2017-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler