model_probe 1.0.6 → 1.0.7

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: 87ab415eaa252a11811f0502ae31564a3b3346ef
4
- data.tar.gz: 1267d9c94f1ff29e07706cf62a897a5c5608fc49
3
+ metadata.gz: 256df9f2a0d516dc276210959300379bdf59a743
4
+ data.tar.gz: ec8afcc2bafbf1d2bf86ef0c2529bf0cc4c78316
5
5
  SHA512:
6
- metadata.gz: 0dcc0b484c372dd23e761200acf7bde44a35fdf1997c11ffe5ec1af5170995e3a7e073b2243174cd1bc50566e061f874012347662c337729c3f3e7b4e3e06ee8
7
- data.tar.gz: 96a3d8ecb8ddc01e5b3b706de0c406a82d0f8df0e125f2054e8a8e13ec2e95ee24ccff0b361763c6420ee85f78bc9e463a14010b8a2c17a1446de3a1cbd92ded
6
+ metadata.gz: 156afe3b29d19de7bda2b5ade402b84827f250e2285ad02f23f2808e1122f88aafc8611f5d3dda292bed8de34127bbedc30e0de78d0c50a17099afa47ee3eba6
7
+ data.tar.gz: a0d678decaac686cfb1d234436f2504be0b2d54d67f4343d551771e34c19baa0904b41784be02acaf7d519d8322a15ddc61321130a4db7c729f115f3aea2cc05
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- model_probe (1.0.6)
4
+ model_probe (1.0.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -16,4 +16,4 @@ DEPENDENCIES
16
16
  rake
17
17
 
18
18
  BUNDLED WITH
19
- 1.13.6
19
+ 1.16.0
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
+ ```
@@ -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
- def relation_columns
84
- @relation_columns ||= begin
85
- columns.select { |column| relation_column? column }
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
- def validation_columns
90
- @validation_columns ||= begin
91
- columns.select { |column| validation_column? column }
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
- def primary_key_column?(column)
96
- column.name == primary_key
97
- end
96
+ def primary_key_column?(column)
97
+ column.name == primary_key
98
+ end
98
99
 
99
- def timestamp_column?(column)
100
- column.type == :datetime && column.name =~ /(created|updated|modified)/
101
- end
100
+ def timestamp_column?(column)
101
+ column.type == :datetime && column.name =~ /(created|updated|modified)/
102
+ end
102
103
 
103
- def relation_column?(column)
104
- return false if column.name == primary_key
105
- column.name.end_with?("_id")
106
- end
104
+ def relation_column?(column)
105
+ return false if column.name == primary_key
106
+ column.name.end_with?("_id")
107
+ end
107
108
 
108
- def validation_column?(column)
109
- return false if column.name == primary_key
110
- return true unless column.null
111
- %i(text string).include?(column.type) && column.limit.to_i > 0
112
- end
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
@@ -0,0 +1,11 @@
1
+ if Rails.env.development?
2
+ ActiveRecord::Base.extend ModelProbe
3
+
4
+ module ModelProbe
5
+ class Railtie < Rails::Railtie
6
+ rake_tasks do
7
+ load "tasks/model_probe.rake"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module ModelProbe
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.7"
3
3
  end
@@ -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.6
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: 2016-10-30 00:00:00.000000000 Z
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.7
63
+ rubygems_version: 2.6.13
62
64
  signing_key:
63
65
  specification_version: 4
64
66
  summary: Schema introspection for ActiveModel