38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/formidable.rb', line 38
def track(args)
return if Config.api_key.empty?
raise "Must define a form." unless args[:form]
errors = args[:errors] || {}
errors = {:base => errors} if errors.any? and errors.kind_of?(Array)
values =
if Config.track_values and errors.any?
args[:values]
else
{}
end
times = args[:times]
total_time = args[:total_time]
attempt = args[:attempt]
if args[:timing_data]
tt, t = Timer.parse(args[:timing_data])
total_time ||= tt
times ||= t
end
request = Thread.current[:formidable_request]
if request
if request.env["action_dispatch.parameter_filter"]
filter_parameters(request.env["action_dispatch.parameter_filter"])
end
values ||= request.params.reject{|k, v| [:utf8, :action, :controller, :authenticity_token, :commit, :formidable].include?(k.to_sym) }
if timing_data = request.params[:formidable]
tt, t = Timer.parse(request.params[:formidable])
total_time ||= tt
times ||= t
end
end
times ||= {}
values ||= {}
cookies = Thread.current[:formidable_cookies]
if cookies
attempt ||= Attempt.parse(cookies, args[:form], errors.empty?)
end
values.delete_if{|k,v| filter?(k)}
flatten(errors, true)
flatten(values)
flatten(times)
values.delete_if{|k,v| !errors[k] or errors[k].empty?}
prefix = args[:prefix]
if prefix
regex = Regexp.new('\A' + prefix.to_s + '\[([^\]]+)\]')
remove_prefix(errors, regex)
remove_prefix(values, regex)
remove_prefix(times, regex)
end
data = {
:form => args[:form],
:errors => errors,
:values => values,
:times => times,
:total_time => total_time,
:attempt => attempt
}
if Config.thread
Thread.new do
Remote.send(data)
end
true
else
Remote.send(data)
end
end
|