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



82
83
84
85
# File 'app/models/lato_settings/setting.rb', line 82

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



88
89
90
91
# File 'app/models/lato_settings/setting.rb', line 88

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



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

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

#option_minObject



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

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

#option_stepObject



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

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

#option_valuesObject



74
75
76
# File 'app/models/lato_settings/setting.rb', line 74

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

#reload_cacheObject



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

def reload_cache
  LatoSettings.reset_cache
end

#value_formattedObject

Helpers



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

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
  when 'text'
    value.to_s
  else
    value.to_s
  end
end