Class: NsSettingsUi::Setting

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/ns_settings_ui/setting.rb

Constant Summary collapse

TYPES =
{
  string: 1,
  integer: 2,
  boolean: 3,
  date: 7,
  nullable_string: 4,
  nullable_integer: 5,
  nullable_boolean: 6
}.freeze
TYPE_HANDLERS =
{
  1 => :string_value,
  2 => :integer_value,
  3 => :boolean_value,
  7 => :date_value,
  4 => :nullable_string,
  5 => :nullable_integer,
  6 => :nullable_boolean
}.freeze
NULL_VALUES =
[nil, ''].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get(*keys) ⇒ Object

TODO: in Nttr belongs_to :country

def self.get(country, *keys)

where(country: country, key: keys.join('.')).first_or_create

end

def country_code

country.try(:alpha2).to_s

end


36
37
38
# File 'app/models/ns_settings_ui/setting.rb', line 36

def self.get(*keys)
  where(key: keys.join('.')).first_or_create
end

Instance Method Details

#formatted_valueObject


44
45
46
# File 'app/models/ns_settings_ui/setting.rb', line 44

def formatted_value
  TYPE_HANDLERS[value_type] ? send(TYPE_HANDLERS[value_type]) : value
end

#keysObject


40
41
42
# File 'app/models/ns_settings_ui/setting.rb', line 40

def keys
  key.split('.').map(&:to_sym)
end