model_probe 0.0.6 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/model_probe/version.rb +1 -1
- data/lib/model_probe.rb +59 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 389c5a6af7396bd046a4f70061717ba925abb2cc
|
4
|
+
data.tar.gz: 6f87991ffb894e05a9f512e797509606bfcb3f76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40b316189777cd388b52c45aafc3a67a87b2cd0e13c00521403927a93293c86936c51c822159c4979bd680edb8ec0a44705917908ab3d8bc22ecb9f4f89ec61e
|
7
|
+
data.tar.gz: 7b1a797aa6404ed9bdf98ee3f450f10217bcc3a37a1642ff19151b1a18f8c01ce454e6a917429c611f66c7ddb51643fa01f8e90fce2957f77e5999ea99b76b5c
|
data/README.md
CHANGED
data/lib/model_probe/version.rb
CHANGED
data/lib/model_probe.rb
CHANGED
@@ -4,7 +4,7 @@ require "model_probe/color"
|
|
4
4
|
module ModelProbe
|
5
5
|
include ModelProbe::Color
|
6
6
|
|
7
|
-
# Pretty prints column meta data for an ActiveModel
|
7
|
+
# Pretty prints column meta data for an ActiveModel
|
8
8
|
def probe
|
9
9
|
name_pad = columns.map{ |c| c.name.length }.max + 1
|
10
10
|
type_pad = columns.map{ |c| c.type.length }.max + 2
|
@@ -24,8 +24,8 @@ module ModelProbe
|
|
24
24
|
nil
|
25
25
|
end
|
26
26
|
|
27
|
-
# Prints a stub that can be used for a test fixture
|
28
|
-
def
|
27
|
+
# Prints a stub that can be used for a test fixture
|
28
|
+
def print_fixture
|
29
29
|
name = self.name.underscore
|
30
30
|
hash = { name => {} }
|
31
31
|
|
@@ -38,4 +38,60 @@ module ModelProbe
|
|
38
38
|
nil
|
39
39
|
end
|
40
40
|
|
41
|
+
# Prints a new model definition based on the database schema
|
42
|
+
def print_model
|
43
|
+
puts "class #{name} < #{superclass.name}"
|
44
|
+
puts " # extends ..................................................................."
|
45
|
+
puts " # includes .................................................................."
|
46
|
+
puts if relation_columns.size > 0
|
47
|
+
puts " # relationships ............................................................."
|
48
|
+
relation_columns.sort_by(&:name).each do |column|
|
49
|
+
next if column.name == primary_key
|
50
|
+
puts " belongs_to :#{column.name.sub(/_id\z/, "")}" if column.name =~ /_id\z/
|
51
|
+
end
|
52
|
+
puts if relation_columns.size > 0 || validation_columns.size > 0
|
53
|
+
puts " # validations ..............................................................."
|
54
|
+
validation_columns.sort_by(&:name).each do |column|
|
55
|
+
next if column.name == primary_key
|
56
|
+
puts " validates :#{column.name} presence: :true" unless column.null
|
57
|
+
if %i(text string).include?(column.type) && column.limit.to_i > 0
|
58
|
+
puts " validates :#{column.name} length: { maximum: #{column.limit} }"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
puts if validation_columns.size > 0
|
62
|
+
puts " # callbacks ................................................................."
|
63
|
+
puts " # scopes ...................................................................."
|
64
|
+
puts " # additional config (i.e. accepts_nested_attribute_for etc...) .............."
|
65
|
+
puts " # class methods ............................................................."
|
66
|
+
puts " # public instance methods ..................................................."
|
67
|
+
puts " # protected instance methods ................................................"
|
68
|
+
puts " # private instance methods .................................................."
|
69
|
+
puts "end"
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def relation_columns
|
75
|
+
@relation_columns ||= begin
|
76
|
+
columns.select { |column| relation_column? column }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def validation_columns
|
81
|
+
@validation_columns ||= begin
|
82
|
+
columns.select { |column| validation_column? column }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def relation_column?(column)
|
87
|
+
return false if column.name == primary_key
|
88
|
+
column.name.end_with?("_id")
|
89
|
+
end
|
90
|
+
|
91
|
+
def validation_column?(column)
|
92
|
+
return false if column.name == primary_key
|
93
|
+
return true if column.null
|
94
|
+
%i(text string).include?(column.type) && column.limit.to_i > 0
|
95
|
+
end
|
96
|
+
|
41
97
|
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: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Hopkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Provides a detailed view of the underlying schema that backs an ActiveModel.
|
14
14
|
email:
|
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
45
|
version: '0'
|
46
46
|
requirements: []
|
47
47
|
rubyforge_project:
|
48
|
-
rubygems_version: 2.
|
48
|
+
rubygems_version: 2.5.1
|
49
49
|
signing_key:
|
50
50
|
specification_version: 4
|
51
51
|
summary: Schema introspection for ActiveModel.
|