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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0cff622189ea7fcacf08ecfb65e1b0f459f43a04
4
- data.tar.gz: 5e02a614bfd05e297054ae6e0158198f412b34e5
3
+ metadata.gz: 63309a1abc353f70b51746460188b18635d131ea
4
+ data.tar.gz: 05b90d5cc95032b79bf93ac79aa1981265b9314c
5
5
  SHA512:
6
- metadata.gz: edd4072303a148f7513c2c7d2c5fd51128fae4f654a78c7d8eb756207f3246f26cc79d55c61c99c98330ba88dc514607618cd0b56550250c91efe490bc30783d
7
- data.tar.gz: 917f11eb0ebc37a0b186f97cee843e8c3e9bff8cb56c0211b368b1a7130652b97a693e3747ee521cafb8c13804d7b77d523b22a8c222a1654e3107fd0f52d602
6
+ metadata.gz: 54277c2c7bbe5ff57cbc2cf3e9728a77fb8f699e489f84e78a43fe98d2e75fb85ce66c0bd7d0fb9c3dd97f73435887e8d849fbfe1ba62a1e0b5c6abf5fdf912a
7
+ data.tar.gz: 388befa8639539e3623d398d2bc4bec309603f80616de1502046188bf13b4b83de793fa876c33910d1470b31539a8d9ba048cbf169fe7161a69eb4d0c013ed49
@@ -1,3 +1,3 @@
1
1
  module ModelProbe
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
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.name == primary_key
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
- name = self.name.underscore
30
- hash = { name => {} }
31
-
32
- columns.sort{ |a, b| a.name <=> b.name }.map do |column|
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.name == primary_key
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.name == primary_key
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.3
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-12 00:00:00.000000000 Z
11
+ date: 2016-08-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: