motor-admin 0.2.11 → 0.2.12

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
  SHA256:
3
- metadata.gz: 3a5b90096b26ecbc08a8db9eab674f5eb73968cbd3e67fef43c476142f75543e
4
- data.tar.gz: fba671589698de0216d59280c9935f940705d12c837808beed32e5de64dec443
3
+ metadata.gz: 7d0e456f8e9d1dc83186c2ef270182308da0bb43bab8779eaa391b2f6f3c7a4f
4
+ data.tar.gz: 1f5a52343c0ba8ca6b4c622b221656a9e38ac2df6678a6659653e2469f71c92d
5
5
  SHA512:
6
- metadata.gz: 64046834ea3379dc2e79b1261b985fff168c5c52d19cd2540b6e951d0d669816a78fa21ac544a9cf4b82f81425f73917db39430e42b04d12db66279a3c159a62
7
- data.tar.gz: 22c5025d749429478eb6f2d2d74a2264cbe5153a42b32b6cb2986ed1d694714cfce007a8751cea224748e7521ee5efe40f1ff06531d185e475b8e2a0fe58dce6
6
+ metadata.gz: b58213d454339da735ef28bb926eea83b910a9399a38892a34744c85ba64f7cce0c9668d40c10afe839807ea194a2144282e20fc6b0133f2bb215ec3f5a5b0f5
7
+ data.tar.gz: e945c189f9929b3afd5eada7330f8b83cc62386a3ac1718d1956bc4cd6b499933defdf0e0c094221170c4b0d58584cf64024e3ac7084d8ed3dcf3c59b5a21449
@@ -83,18 +83,52 @@ module Motor
83
83
  # @param result [ActiveRecord::Result]
84
84
  # @return [Hash]
85
85
  def build_columns_hash(result)
86
- result.columns.map do |column_name|
87
- column_type = result.column_types[column_name]
86
+ result.columns.map.with_index do |column_name, index|
87
+ column_type_class = result.column_types[column_name]
88
+
89
+ column_type =
90
+ if column_type_class
91
+ ActiveRecordUtils::Types.find_name_for_type(column_type_class)
92
+ else
93
+ not_nil_value = result.rows.reduce(nil) do |acc, row|
94
+ column = row[index]
95
+
96
+ break column unless column.nil?
97
+
98
+ acc
99
+ end
100
+
101
+ fetch_column_type_from_value(not_nil_value)
102
+ end
88
103
 
89
104
  {
90
105
  name: column_name,
91
106
  display_name: column_name.humanize,
92
- column_type: ActiveRecordUtils::Types.find_name_for_type(column_type),
107
+ column_type: column_type,
93
108
  is_array: column_type.class.to_s == 'ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array'
94
109
  }
95
110
  end
96
111
  end
97
112
 
113
+ # @param value [Object]
114
+ # @return [String]
115
+ def fetch_column_type_from_value(value)
116
+ case value
117
+ when Integer
118
+ 'integer'
119
+ when Float
120
+ 'float'
121
+ when Time
122
+ 'datetime'
123
+ when Date
124
+ 'date'
125
+ when TrueClass, FalseClass
126
+ 'boolean'
127
+ else
128
+ 'string'
129
+ end
130
+ end
131
+
98
132
  # @param query [Motor::Query]
99
133
  # @param limit [Integer]
100
134
  # @param variables_hash [Hash]
data/lib/motor/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Motor
4
- VERSION = '0.2.11'
4
+ VERSION = '0.2.12'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motor-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Matsyburka