active_record_schema_scrapper 0.1.0 → 0.1.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: 1bb5f2380fba44f87c33896211f1a4cde471abe8
4
- data.tar.gz: 2c0233670efdc5067016cd132a5c0bd2c27b6ddd
3
+ metadata.gz: ad8b72a1fd99a6cc14f70a87ec35f42870f26a2c
4
+ data.tar.gz: 8fd34f4c58f20e2678b9468e86f0a624afb11f22
5
5
  SHA512:
6
- metadata.gz: c9428815ebb80cb3a2085f78fbefbcd04aac55d83ee3840ff2df6649b62ea9519e955259e6b54bb41589fe568f0cd5ed4e1a0d205fd25b2bb5e5f3bfa7d8bb2d
7
- data.tar.gz: 76723da500c4e809c4cd4060297cf76af8ce515c485a3573ffcf5e892e5d42fb3f09eb89407423bd39b01495dc561bfc6f286999796b6129f624f8dbb9e7169c
6
+ metadata.gz: 5f63130533253906f4b03f29ff7fad8c1f69db8d07b073e206e8d3de760c30f77d8939959282d6e4a40fa332db496576bd195c55b858b2b56aac7d9475261560
7
+ data.tar.gz: 0e49306e9cd3caf0b506dbe905ca80a771372e275c2e0b42e3181b1a1e144e06eada0bb7d2bbe7a1ad01ecfa7dfb943e0789e82bd5a5a001588b200ebc248216
@@ -11,30 +11,40 @@ class ActiveRecordSchemaScrapper
11
11
  def each
12
12
  types.each do |type|
13
13
  model.reflect_on_all_associations(type).each do |a|
14
- hash = if a.try(:delegate_reflection)
15
- { source: a.delegate_reflection.options[:source],
16
- through: a.delegate_reflection.options[:through],
17
- dependent: a.delegate_reflection.options[:dependent],
18
- }
19
- else
20
- { source: a.try(:delegate_reflection).try(:name),
21
- through: a.try(:through),
22
- dependent: a.options[:dependent] }
23
- end.merge({
24
- name: a.name,
25
- foreign_key: a.foreign_key,
26
- class_name: a.klass.name,
27
- type: type,
28
- })
29
- yield(ActiveRecordSchemaScrapper::Association.new(hash))
14
+ begin
15
+ hash = if a.try(:delegate_reflection)
16
+ { source: a.delegate_reflection.options[:source],
17
+ through: a.delegate_reflection.options[:through],
18
+ dependent: a.delegate_reflection.options[:dependent],
19
+ }
20
+ else
21
+ { source: a.try(:delegate_reflection).try(:name),
22
+ through: a.try(:through),
23
+ dependent: a.options[:dependent] }
24
+ end.merge({
25
+ name: a.name,
26
+ foreign_key: a.foreign_key,
27
+ class_name: a.klass.name,
28
+ type: type,
29
+ })
30
+
31
+ yield(ActiveRecordSchemaScrapper::Association.new(hash))
32
+ rescue NameError => e
33
+ errors << "Missing model #{a.name.to_s.camelize} for association #{model.name}.belongs_to :#{a.name}"
34
+ end
30
35
  end
31
36
  end
32
37
  end
33
38
 
34
39
  def to_a
35
- map {|v| v}
40
+ map { |v| v }
36
41
  end
37
42
 
43
+ def errors
44
+ @errors ||= []
45
+ end
46
+
47
+
38
48
  def self.types
39
49
  [:has_and_belongs_to_many, :belongs_to, :has_one, :has_many]
40
50
  end
@@ -1,3 +1,3 @@
1
1
  class ActiveRecordSchemaScrapper
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_schema_scrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-16 00:00:00.000000000 Z
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus