23 lines
441 B
Ruby
23 lines
441 B
Ruby
class Setting < ActiveRecord::Base
|
|
validates :key, presence: true, uniqueness: true
|
|
|
|
default_scope { order(id: :asc) }
|
|
|
|
def feature_flag?
|
|
key.start_with?('feature.')
|
|
end
|
|
|
|
class << self
|
|
def [](key)
|
|
where(key: key).pluck(:value).first.presence
|
|
end
|
|
|
|
def []=(key, value)
|
|
setting = where(key: key).first || new(key: key)
|
|
setting.value = value.presence
|
|
setting.save!
|
|
value
|
|
end
|
|
end
|
|
end
|