class Gon::Watch
Constants
- JS_FUNCTION
Public Class Methods
all_variables()
click to toggle source
# File lib/gon/watch.rb, line 15 def all_variables @watch_variables || {} end
clear()
click to toggle source
# File lib/gon/watch.rb, line 19 def clear @watch_variables = {} end
render()
click to toggle source
# File lib/gon/watch.rb, line 7 def render JS_FUNCTION + "window.gon.watchedVariables=#{Gon::JsonDumper.dump all_variables};" end
render_amd()
click to toggle source
# File lib/gon/watch.rb, line 11 def render_amd JS_FUNCTION + "gon.watchedVariables=#{Gon::JsonDumper.dump all_variables};" end
Private Class Methods
return_variable(value)
click to toggle source
# File lib/gon/watch.rb, line 51 def return_variable(value) controller = Gon::EnvFinder.controller_env controller.render json: Gon::Escaper.escape_unicode(Gon::JsonDumper.dump value) end
return_variable?(variable)
click to toggle source
# File lib/gon/watch.rb, line 41 def return_variable?(variable) controller = Gon::EnvFinder.controller_env params = controller.params variable = variable.to_s.gsub('=', '') controller.request.xhr? && params[:gon_return_variable] && params[:gon_watched_variable] == variable end
set_variable(name, value)
click to toggle source
Calls superclass method
Gon.set_variable
# File lib/gon/watch.rb, line 25 def set_variable(name, value) if return_variable?(name) return_variable value elsif Gon.send(:current_gon) variable = {} @watch_variables ||= {} env = Gon.send(:current_gon).env variable['url'] = env['ORIGINAL_FULLPATH'] || env['REQUEST_URI'] variable['method'] = env['REQUEST_METHOD'] variable['name'] = name @watch_variables[name] = variable super end end