model_probe 0.0.2 → 0.0.3

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.
@@ -0,0 +1,21 @@
1
+ module ModelProbe
2
+ module Color
3
+ extend self
4
+
5
+ colors = {
6
+ :red => 31,
7
+ :green => 32,
8
+ :yellow => 33,
9
+ :blue => 34,
10
+ :magenta => 35,
11
+ :cyan => 36,
12
+ :white => 37
13
+ }
14
+
15
+ colors.each do |name, code|
16
+ define_method name do |text|
17
+ "\e[#{code}m#{text}\e[0m"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module ModelProbe
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/model_probe.rb CHANGED
@@ -1,27 +1,14 @@
1
1
  require "model_probe/version"
2
+ require "model_probe/color"
2
3
 
3
4
  module ModelProbe
4
- colors = {
5
- :red => 31,
6
- :green => 32,
7
- :yellow => 33,
8
- :blue => 34,
9
- :magenta => 35,
10
- :cyan => 36,
11
- :white => 37
12
- }
13
-
14
- colors.each do |name, code|
15
- define_method name do |text|
16
- "\e[#{code}m#{text}\e[0m"
17
- end
18
- end
5
+ include ModelProbe::Color
19
6
 
20
7
  # Pretty prints column meta data for an ActiveModel.
21
8
  def probe
22
- name_pad = columns.map{|c| c.name.length}.max + 1
23
- type_pad = columns.map{|c| c.type.length}.max + 2
24
- sql_type_pad = columns.map{|c| c.sql_type.length}.max + 1
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
25
12
 
26
13
  columns.sort{ |a, b| a.name <=> b.name }.map do |column|
27
14
  name = column.name
@@ -30,7 +17,8 @@ module ModelProbe
30
17
  print " "
31
18
  print blue(column.type.to_s.ljust(type_pad, "."))
32
19
  print magenta(column.sql_type.to_s.ljust(sql_type_pad))
33
- print red("NULL") if column.null
20
+ column.null ? print(red("NULL")) : print(" ")
21
+ print " [#{column.default}]" if column.default
34
22
  puts
35
23
  end
36
24
  nil
@@ -43,7 +31,7 @@ module ModelProbe
43
31
 
44
32
  columns.sort{ |a, b| a.name <=> b.name }.map do |column|
45
33
  next if column.name =~ /^(created_at|updated_at)$/
46
- hash[name][column.name] = "value"
34
+ hash[name][column.name] = column.default || "value"
47
35
  end
48
36
 
49
37
  puts hash.to_yaml
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_probe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -24,6 +24,7 @@ files:
24
24
  - README.md
25
25
  - Rakefile
26
26
  - lib/model_probe.rb
27
+ - lib/model_probe/color.rb
27
28
  - lib/model_probe/version.rb
28
29
  - model_probe.gemspec
29
30
  homepage: ''