class TrkDatatables::Preferences
Constants
- KEY_IN_PREFERENCES
Public Class Methods
new(holder, field, class_name)
click to toggle source
# File lib/trk_datatables/preferences.rb, line 4 def initialize(holder, field, class_name) @holder = holder @field = field @class_name = class_name end
Public Instance Methods
get(key, check_value = nil)
click to toggle source
Get the key from holder Use check_value proc to ignore wrong format. This is usefull when you change format and you do not want to clear all existing values
# File lib/trk_datatables/preferences.rb, line 13 def get(key, check_value = nil) return unless @holder result = @holder.send(@field).dig KEY_IN_PREFERENCES, @class_name, key return result if check_value.nil? return result if check_value.call result end
set(key, value)
click to toggle source
# File lib/trk_datatables/preferences.rb, line 21 def set(key, value) return unless @holder h = {KEY_IN_PREFERENCES => {@class_name => {key => value}}} @holder.send("#{@field}=", {}) if @holder.send(@field).nil? @holder.send(@field).deep_merge! h @holder.save! end