Class: LatoSettings::Setting

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/lato_settings/setting.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionsObject

Returns the value of attribute actions.



3
4
5
# File 'app/models/lato_settings/setting.rb', line 3

def actions
  @actions
end

Class Method Details

.get(key, default = nil) ⇒ Object

DEPRECATED METHOD: TO BE REMOVED IN FUTURE VERSIONS



79
80
81
82
# File 'app/models/lato_settings/setting.rb', line 79

def self.get(key, default = nil)
  Rails.logger.warn "LatoSettings::Setting.get is deprecated. Use LatoSettings.get instead."
  LatoSettings.get(key, default)
end

.load_cacheObject

DEPRECATED METHOD: TO BE REMOVED IN FUTURE VERSIONS



85
86
87
88
# File 'app/models/lato_settings/setting.rb', line 85

def self.load_cache
  Rails.logger.warn "LatoSettings::Setting.load_cache is deprecated. Use LatoSettings.reset_cache instead."
  LatoSettings.reset_cache
end

Instance Method Details

#option_maxObject



63
64
65
# File 'app/models/lato_settings/setting.rb', line 63

def option_max
  options&.dig('max') || nil
end

#option_minObject



59
60
61
# File 'app/models/lato_settings/setting.rb', line 59

def option_min
  options&.dig('min') || nil
end

#option_stepObject



67
68
69
# File 'app/models/lato_settings/setting.rb', line 67

def option_step
  options&.dig('step') || 1
end

#option_valuesObject



71
72
73
# File 'app/models/lato_settings/setting.rb', line 71

def option_values
  options&.dig('values') || []
end

#reload_cacheObject



33
34
35
# File 'app/models/lato_settings/setting.rb', line 33

def reload_cache
  LatoSettings.reset_cache
end

#value_formattedObject

Helpers



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/lato_settings/setting.rb', line 40

def value_formatted
  return nil if value.nil?

  case typology
  when 'string'
    value.to_s
  when 'number'
    value.to_f
  when 'date'
    Date.parse(value)
  when 'select'
    option_values.include?(value) ? value : nil
  when 'integer'
    value.to_i
  else
    value.to_s
  end
end