active_record_schema_scrapper 0.5.0 → 0.6.0

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: 7df5fa6fd93bbe7079a740148c55fa00e9f9e3f6
4
- data.tar.gz: 567ae9e5bb444f021e23e90f7132907b9d81b7f9
3
+ metadata.gz: ff98b2cbf22a93995d92d5b4ad517c660902cbc9
4
+ data.tar.gz: f9278f579ff046555eefdfb57d9f8a99614a9ecb
5
5
  SHA512:
6
- metadata.gz: 1f00c8d507012e7b7b6c4e50515ae24dcb3602ff1835090f300bc1bdb06fde55fa3b0a980c4c14cc1f04ee04b2bc960b001073e72e899645d9fab6167dd5dadf
7
- data.tar.gz: e72135d7bbd58958e31545ce9fe02e57135da5cab2d1c1aab1c5652b995483e170f5246e4b583f6d1e3b1fd638bf17a71c9d768152efaf9b64c6f7fccba98411
6
+ metadata.gz: af0b10a1f5357dab7bedcc19f5b2143e39cabc592af12bc824319ce3259395d976defe9c6f3b2c7df92cb85e9f419a09b022b67a2fa535bbbdc4ffe03d35924f
7
+ data.tar.gz: 1efb86d39c21a34db1f54e9d6d9bc5dc725c4c626df88dd96f28ea40a51ec3475792e0e6d31b841751131de0f5f0e6f4cb503ea119cee77f8e2d0a2c9f0c095b
@@ -102,7 +102,19 @@ class ActiveRecordSchemaScrapper
102
102
  private
103
103
 
104
104
  def call
105
- @attributes ||= model.columns_hash.map do |k, v|
105
+ @attributes ||= begin
106
+ parse_attributes
107
+ rescue NoMethodError => e
108
+ no_method_error(e)
109
+ rescue TypeError => e
110
+ model.try!(:abstract_class?) ? statement_invalid(e) : []
111
+ rescue ActiveRecord::StatementInvalid => e
112
+ statement_invalid(e)
113
+ end
114
+ end
115
+
116
+ def parse_attributes
117
+ model.columns_hash.map do |k, v|
106
118
  ActiveRecordSchemaScrapper::Attribute.new(
107
119
  name: k,
108
120
  type: v.type,
@@ -114,16 +126,21 @@ class ActiveRecordSchemaScrapper
114
126
  cast_type: cast_type(v)
115
127
  )
116
128
  end
117
- rescue NoMethodError => e
129
+ end
130
+
131
+ def no_method_error(e)
132
+ puts e.message
118
133
  @errors << ErrorObject.new(class_name: model.name,
119
134
  message: "#{model.name} is not a valid ActiveRecord model.",
120
135
  original_error: e,
121
136
  level: :error,
122
137
  type: :invalid_model)
123
138
  []
124
- rescue ActiveRecord::StatementInvalid => e
139
+ end
140
+
141
+ def statement_invalid(e)
125
142
  level = model.abstract_class? ? :warn : :error
126
- message = model.abstract_class? ? "#{model.name} is an abstract class and has no associated table." : e.message
143
+ message = model.abstract_class? ? "#{model.name} is an abstract class and has no associated table." : e.try!(:message)
127
144
  @errors << ErrorObject.new(class_name: model.name,
128
145
  message: message,
129
146
  original_error: e,
@@ -1,3 +1,3 @@
1
1
  class ActiveRecordSchemaScrapper
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
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.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Zeisler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-26 00:00:00.000000000 Z
11
+ date: 2016-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord