class Preferences::PreferenceDefinition
Represents the definition of a preference for a particular model
Attributes
type[R]
The data type for the content stored in this preference type
Public Instance Methods
default_value(group = nil)
click to toggle source
The default value to use for the preference in case none have been previously defined
# File lib/preferences/preference_definition.rb, line 29 def default_value(group = nil) @group_defaults.include?(group) ? @group_defaults[group] : @column.default end
name()
click to toggle source
The name of the preference
# File lib/preferences/preference_definition.rb, line 23 def name @column.name end
number?()
click to toggle source
Determines whether column backing this preference stores numberic values
# File lib/preferences/preference_definition.rb, line 34 def number? @column.number? end
query(value)
click to toggle source
Typecasts the value to true/false depending on the type of preference
# File lib/preferences/preference_definition.rb, line 46 def query(value) if !(value = type_cast(value)) false elsif number? !value.zero? else !value.blank? end end
type_cast(value)
click to toggle source
Typecasts the value based on the type of preference that was defined. This uses ActiveRecord’s typecast functionality so the same rules for typecasting a model’s columns apply here.
# File lib/preferences/preference_definition.rb, line 41 def type_cast(value) @type == :any ? value : @column.type_cast(value) end