model_probe 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +110 -0
- data/lib/model_probe.rb +28 -27
- data/lib/model_probe/railtie.rb +11 -0
- data/lib/model_probe/version.rb +1 -1
- data/lib/tasks/model_probe.rake +22 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 256df9f2a0d516dc276210959300379bdf59a743
|
4
|
+
data.tar.gz: ec8afcc2bafbf1d2bf86ef0c2529bf0cc4c78316
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 156afe3b29d19de7bda2b5ade402b84827f250e2285ad02f23f2808e1122f88aafc8611f5d3dda292bed8de34127bbedc30e0de78d0c50a17099afa47ee3eba6
|
7
|
+
data.tar.gz: a0d678decaac686cfb1d234436f2504be0b2d54d67f4343d551771e34c19baa0904b41784be02acaf7d519d8322a15ddc61321130a4db7c729f115f3aea2cc05
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# ModelProbe
|
2
2
|
|
3
|
+
<a target='_blank' rel='nofollow' href='https://app.codesponsor.io/link/QMSjMHrtPhvfmCnk5Hbikhhr/hopsoft/model_probe'>
|
4
|
+
<img alt='Sponsor' width='888' height='68' src='https://app.codesponsor.io/embed/QMSjMHrtPhvfmCnk5Hbikhhr/hopsoft/model_probe.svg' />
|
5
|
+
</a>
|
6
|
+
|
3
7
|
## Schema introspection for ActiveRecord
|
4
8
|
|
5
9
|
Provides a detailed view of the underlying schema that backs an ActiveRecord model.
|
@@ -28,3 +32,109 @@ MyModel.probe
|
|
28
32
|
MyModel.print_fixture
|
29
33
|
MyModel.print_model
|
30
34
|
```
|
35
|
+
|
36
|
+
## Rails Integration
|
37
|
+
|
38
|
+
ModelProbe auto initializes in the Rails development environment.
|
39
|
+
This means your models are implicitly extended with this behavior when developing.
|
40
|
+
|
41
|
+
It also ships with these convenient rake tasks.
|
42
|
+
|
43
|
+
```sh
|
44
|
+
rails t -T model_probe
|
45
|
+
|
46
|
+
# rails model_probe:print_fixture[klass] # Print fixture
|
47
|
+
# rails model_probe:print_model[klass] # Print model
|
48
|
+
# rails model_probe:probe[klass] # Probe
|
49
|
+
```
|
50
|
+
|
51
|
+
```sh
|
52
|
+
rails model_probe:probe[User]
|
53
|
+
|
54
|
+
# confirmation_sent_at datetime..timestamp without time zone NULL
|
55
|
+
# confirmation_token string....character varying NULL
|
56
|
+
# confirmed_at datetime..timestamp without time zone NULL
|
57
|
+
# created_at datetime..timestamp without time zone
|
58
|
+
# current_sign_in_at datetime..timestamp without time zone NULL
|
59
|
+
# current_sign_in_ip inet......inet NULL
|
60
|
+
# email string....character varying NULL []
|
61
|
+
# encrypted_password string....character varying []
|
62
|
+
# failed_attempts integer...integer [0]
|
63
|
+
# * id uuid......uuid
|
64
|
+
# last_sign_in_at datetime..timestamp without time zone NULL
|
65
|
+
# last_sign_in_ip inet......inet NULL
|
66
|
+
# locked_at datetime..timestamp without time zone NULL
|
67
|
+
# payment_platform string....character varying NULL
|
68
|
+
# payment_platform_id string....character varying NULL
|
69
|
+
# phone_number_id uuid......uuid
|
70
|
+
# remember_created_at datetime..timestamp without time zone NULL
|
71
|
+
# reset_password_sent_at datetime..timestamp without time zone NULL
|
72
|
+
# reset_password_token string....character varying NULL
|
73
|
+
# sign_in_count integer...integer [0]
|
74
|
+
# unconfirmed_email string....character varying NULL
|
75
|
+
# unlock_token string....character varying NULL
|
76
|
+
# updated_at datetime..timestamp without time zone
|
77
|
+
```
|
78
|
+
|
79
|
+
```sh
|
80
|
+
rails model_probe:print_fixture[User]
|
81
|
+
|
82
|
+
# ---
|
83
|
+
# user:
|
84
|
+
# confirmation_sent_at: value
|
85
|
+
# confirmation_token: value
|
86
|
+
# confirmed_at: value
|
87
|
+
# current_sign_in_at: value
|
88
|
+
# current_sign_in_ip: value
|
89
|
+
# email: ''
|
90
|
+
# encrypted_password: ''
|
91
|
+
# failed_attempts: '0'
|
92
|
+
# last_sign_in_at: value
|
93
|
+
# last_sign_in_ip: value
|
94
|
+
# locked_at: value
|
95
|
+
# payment_platform: value
|
96
|
+
# payment_platform_id: value
|
97
|
+
# phone_number_id: value
|
98
|
+
# reset_password_sent_at: value
|
99
|
+
# reset_password_token: value
|
100
|
+
# sign_in_count: '0'
|
101
|
+
# unconfirmed_email: value
|
102
|
+
# unlock_token: value
|
103
|
+
```
|
104
|
+
|
105
|
+
```sh
|
106
|
+
rails model_probe:print_model[User]
|
107
|
+
|
108
|
+
# class User < ApplicationRecord
|
109
|
+
# # extends ...................................................................
|
110
|
+
# # includes ..................................................................
|
111
|
+
#
|
112
|
+
# # relationships .............................................................
|
113
|
+
# belongs_to :payment_platform
|
114
|
+
# belongs_to :phone_number
|
115
|
+
#
|
116
|
+
# # validations ...............................................................
|
117
|
+
# validates :created_at, presence: true
|
118
|
+
# validates :encrypted_password, presence: true
|
119
|
+
# validates :failed_attempts, presence: true
|
120
|
+
# validates :phone_number_id, presence: true
|
121
|
+
# validates :sign_in_count, presence: true
|
122
|
+
# validates :updated_at, presence: true
|
123
|
+
#
|
124
|
+
# # callbacks .................................................................
|
125
|
+
# # scopes ....................................................................
|
126
|
+
# # additional config (i.e. accepts_nested_attribute_for etc...) ..............
|
127
|
+
#
|
128
|
+
# # class methods .............................................................
|
129
|
+
# class << self
|
130
|
+
# end
|
131
|
+
#
|
132
|
+
# # public instance methods ...................................................
|
133
|
+
#
|
134
|
+
# # protected instance methods ................................................
|
135
|
+
# protected
|
136
|
+
#
|
137
|
+
# # private instance methods ..................................................
|
138
|
+
# private
|
139
|
+
# end
|
140
|
+
```
|
data/lib/model_probe.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
require "model_probe/version"
|
2
2
|
require "model_probe/color"
|
3
|
+
require "model_probe/railtie" if defined?(Rails)
|
3
4
|
|
4
5
|
module ModelProbe
|
5
6
|
include ModelProbe::Color
|
6
7
|
|
7
8
|
# Pretty prints column meta data for an ActiveModel
|
8
9
|
def probe
|
9
|
-
name_pad = columns.map{ |c| c.name.length }.max + 1
|
10
|
-
type_pad = columns.map{ |c| c.type.length }.max + 2
|
11
|
-
sql_type_pad = columns.map{ |c| c.sql_type.length }.max + 1
|
10
|
+
name_pad = columns.map { |c| c.name.length }.max + 1
|
11
|
+
type_pad = columns.map { |c| c.type.length }.max + 2
|
12
|
+
sql_type_pad = columns.map { |c| c.sql_type.length }.max + 1
|
12
13
|
|
13
|
-
columns.sort{ |a, b| a.name <=> b.name }.map do |column|
|
14
|
+
columns.sort { |a, b| a.name <=> b.name }.map do |column|
|
14
15
|
name = column.name
|
15
16
|
name = "* #{name}" if primary_key_column?(column)
|
16
17
|
print yellow(name.to_s.rjust(name_pad))
|
@@ -80,34 +81,34 @@ module ModelProbe
|
|
80
81
|
|
81
82
|
private
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
|
84
|
+
def relation_columns
|
85
|
+
@relation_columns ||= begin
|
86
|
+
columns.select { |column| relation_column? column }
|
87
|
+
end
|
86
88
|
end
|
87
|
-
end
|
88
89
|
|
89
|
-
|
90
|
-
|
91
|
-
|
90
|
+
def validation_columns
|
91
|
+
@validation_columns ||= begin
|
92
|
+
columns.select { |column| validation_column? column }
|
93
|
+
end
|
92
94
|
end
|
93
|
-
end
|
94
95
|
|
95
|
-
|
96
|
-
|
97
|
-
|
96
|
+
def primary_key_column?(column)
|
97
|
+
column.name == primary_key
|
98
|
+
end
|
98
99
|
|
99
|
-
|
100
|
-
|
101
|
-
|
100
|
+
def timestamp_column?(column)
|
101
|
+
column.type == :datetime && column.name =~ /(created|updated|modified)/
|
102
|
+
end
|
102
103
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
104
|
+
def relation_column?(column)
|
105
|
+
return false if column.name == primary_key
|
106
|
+
column.name.end_with?("_id")
|
107
|
+
end
|
107
108
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
109
|
+
def validation_column?(column)
|
110
|
+
return false if column.name == primary_key
|
111
|
+
return true unless column.null
|
112
|
+
%i(text string).include?(column.type) && column.limit.to_i > 0
|
113
|
+
end
|
113
114
|
end
|
data/lib/model_probe/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
namespace :model_probe do
|
2
|
+
desc <<~DESC
|
3
|
+
Probe. Usage: `rails model:probe[User]`
|
4
|
+
DESC
|
5
|
+
task :probe, [:klass] => :environment do |task, args|
|
6
|
+
puts args.klass.constantize.probe
|
7
|
+
end
|
8
|
+
|
9
|
+
desc <<~DESC
|
10
|
+
Print fixture. Usage: `rails model:print_fixture[User]`
|
11
|
+
DESC
|
12
|
+
task :print_fixture, [:klass] => :environment do |task, args|
|
13
|
+
puts args.klass.constantize.print_fixture
|
14
|
+
end
|
15
|
+
|
16
|
+
desc <<~DESC
|
17
|
+
Print model. Usage: `rails model:print_model[User]`
|
18
|
+
DESC
|
19
|
+
task :print_model, [:klass] => :environment do |task, args|
|
20
|
+
puts args.klass.constantize.print_model
|
21
|
+
end
|
22
|
+
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.7
|
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: 2017-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -38,7 +38,9 @@ files:
|
|
38
38
|
- Rakefile
|
39
39
|
- lib/model_probe.rb
|
40
40
|
- lib/model_probe/color.rb
|
41
|
+
- lib/model_probe/railtie.rb
|
41
42
|
- lib/model_probe/version.rb
|
43
|
+
- lib/tasks/model_probe.rake
|
42
44
|
homepage: http://hopsoft.github.com/model_probe/
|
43
45
|
licenses: []
|
44
46
|
metadata: {}
|
@@ -58,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
60
|
version: '0'
|
59
61
|
requirements: []
|
60
62
|
rubyforge_project:
|
61
|
-
rubygems_version: 2.6.
|
63
|
+
rubygems_version: 2.6.13
|
62
64
|
signing_key:
|
63
65
|
specification_version: 4
|
64
66
|
summary: Schema introspection for ActiveModel
|