model_probe 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/model_probe/version.rb +1 -1
- data/lib/model_probe.rb +17 -10
- 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: 63309a1abc353f70b51746460188b18635d131ea
|
4
|
+
data.tar.gz: 05b90d5cc95032b79bf93ac79aa1981265b9314c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54277c2c7bbe5ff57cbc2cf3e9728a77fb8f699e489f84e78a43fe98d2e75fb85ce66c0bd7d0fb9c3dd97f73435887e8d849fbfe1ba62a1e0b5c6abf5fdf912a
|
7
|
+
data.tar.gz: 388befa8639539e3623d398d2bc4bec309603f80616de1502046188bf13b4b83de793fa876c33910d1470b31539a8d9ba048cbf169fe7161a69eb4d0c013ed49
|
data/lib/model_probe/version.rb
CHANGED
data/lib/model_probe.rb
CHANGED
@@ -12,7 +12,7 @@ module ModelProbe
|
|
12
12
|
|
13
13
|
columns.sort{ |a, b| a.name <=> b.name }.map do |column|
|
14
14
|
name = column.name
|
15
|
-
name = "* #{name}" if column
|
15
|
+
name = "* #{name}" if primary_key_column?(column)
|
16
16
|
print yellow(name.to_s.rjust(name_pad))
|
17
17
|
print " "
|
18
18
|
print blue(column.type.to_s.ljust(type_pad, "."))
|
@@ -26,14 +26,13 @@ module ModelProbe
|
|
26
26
|
|
27
27
|
# Prints a stub that can be used for a test fixture
|
28
28
|
def print_fixture
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
next if column.name =~ /^(created_at|updated_at)$/
|
34
|
-
hash[name][column.name] = column.default || "value"
|
29
|
+
values = columns.sort_by(&:name).each_with_object({}) do |column, memo|
|
30
|
+
next if primary_key_column?(column)
|
31
|
+
next if timestamp_column?(column)
|
32
|
+
memo[column.name] = column.default || "value"
|
35
33
|
end
|
36
34
|
|
35
|
+
hash = { self.name.underscore => values }
|
37
36
|
puts hash.to_yaml
|
38
37
|
nil
|
39
38
|
end
|
@@ -46,13 +45,13 @@ module ModelProbe
|
|
46
45
|
puts if relation_columns.size > 0
|
47
46
|
puts " # relationships ............................................................."
|
48
47
|
relation_columns.sort_by(&:name).each do |column|
|
49
|
-
next if column
|
48
|
+
next if primary_key_column?(column)
|
50
49
|
puts " belongs_to :#{column.name.sub(/_id\z/, "")}" if column.name =~ /_id\z/
|
51
50
|
end
|
52
51
|
puts if relation_columns.size > 0 || validation_columns.size > 0
|
53
52
|
puts " # validations ..............................................................."
|
54
53
|
validation_columns.sort_by(&:name).each do |column|
|
55
|
-
next if column
|
54
|
+
next if primary_key_column?(column)
|
56
55
|
puts " validates :#{column.name}, presence: :true" unless column.null
|
57
56
|
if %i(text string).include?(column.type) && column.limit.to_i > 0
|
58
57
|
puts " validates :#{column.name}, length: { maximum: #{column.limit} }"
|
@@ -75,6 +74,7 @@ module ModelProbe
|
|
75
74
|
puts " # private instance methods .................................................."
|
76
75
|
puts " private"
|
77
76
|
puts "end"
|
77
|
+
nil
|
78
78
|
end
|
79
79
|
|
80
80
|
private
|
@@ -91,6 +91,14 @@ module ModelProbe
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
+
def primary_key_column?(column)
|
95
|
+
column.name == primary_key
|
96
|
+
end
|
97
|
+
|
98
|
+
def timestamp_column?(column)
|
99
|
+
column.type == :datetime && column.name =~ /(created|updated|modified)/
|
100
|
+
end
|
101
|
+
|
94
102
|
def relation_column?(column)
|
95
103
|
return false if column.name == primary_key
|
96
104
|
column.name.end_with?("_id")
|
@@ -101,5 +109,4 @@ module ModelProbe
|
|
101
109
|
return true unless column.null
|
102
110
|
%i(text string).include?(column.type) && column.limit.to_i > 0
|
103
111
|
end
|
104
|
-
|
105
112
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: model_probe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Hopkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|