5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/session_rememberable/methods.rb', line 5
def remember(key, class_name: nil, static_data: false)
define_method(:"current_#{key}") do
instance_var = instance_variable_get("@current_#{key}")
return instance_var if instance_var
if static_data
instance_variable_set "@current_#{key}", session["current_#{key}"]
else
class_name ||= key.to_s.titleize
instance_variable_set "@current_#{key}", class_name.constantize.find_by(id: session["current_#{key}"])
end
end
helper_method :"current_#{key}"
end
|