85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/active_record_mask/active_record_mask.rb', line 85
def empty_value_for_attribute(attr_name)
column = self.class.columns_hash[attr_name.to_s]
return nil unless column
if self.class.revealed_defaults.key?(attr_name.to_sym)
return self.class.revealed_defaults[attr_name.to_sym]
end
case column.type
when :string, :text
if (column.try(:array) rescue false)
[]
else
""
end
when :integer, :float, :decimal
0
when :datetime, :timestamp, :time, :date
nil
when :boolean
false
when :json, :jsonb, :hstore
{}
when :array
[]
else
nil
end
end
|