51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/crudboy/ext/array.rb', line 51
def v
return self unless present?
t = []
if map(&:class).uniq.size == 1
if first.is_a?(ActiveRecord::Base)
t << first.attribute_names
t << nil
each do |e|
t << e.attributes.values_at(*first.attribute_names).map(&:as_json)
end
elsif first.is_a?(Array)
t = map { |a| a.map(&:as_json) }
elsif first.is_a?(Hash) || first.is_a?(ActiveSupport::HashWithIndifferentAccess)
t << first.keys
t << nil
each do |e|
t << e.values_at(*first.keys).map(&:as_json)
end
else
return self
end
end
t
end
|