class Volt::Persistors::Cookies
Backs a collection in the local store
Public Instance Methods
added(model, index)
click to toggle source
Called when a model is added to the collection
# File lib/volt/models/persistors/cookies.rb, line 49 def added(model, index) # Save an added cookie end
changed(attribute_name)
click to toggle source
Callled when an cookies value is changed
# File lib/volt/models/persistors/cookies.rb, line 71 def changed(attribute_name) # TODO: Make sure we're only assigning directly, not sub models unless $writing_cookies value = @model.get(attribute_name) # Temp, expire in 1 year, going to expand this api write_cookie(attribute_name, value.to_s, expires: Time.now + (356 * 24 * 60 * 60), path: '/') end true end
loaded(initial_state = nil)
click to toggle source
# File lib/volt/models/persistors/cookies.rb, line 53 def loaded(initial_state = nil) # When the main model is first loaded, we pull in the data from the # store if it exists if !@cookies_loaded && @model.path == [] @cookies_loaded = true writing_cookies do # Assign directly so we don't trigger the callbacks on the initial load attrs = @model.attributes read_cookies.each_pair do |key, value| attrs[key.to_sym] = value end end end end
removed(attribute_name)
click to toggle source
# File lib/volt/models/persistors/cookies.rb, line 83 def removed(attribute_name) writing_cookies do write_cookie(attribute_name, '', max_age: 0, path: '/') end end