Sha256: 0c40b0c5ebcc83dc2fe7b6de0b648c05e6f7dee2ff53810cb51317218ce88031
Contents?: true
Size: 1.59 KB
Versions: 10
Compression:
Stored size: 1.59 KB
Contents
module KirguduBase module Settings class SettingsManager def initialize @options = {} end def get(option_name) option = @options[option_name] unless option option = self.get_option_by_name(option_name) @options[option_name] = option unless option end option end def set(option_name, value) option = set.get_option_by_name(option_name) unless option # option = self.create_value_for_option() option.value = value end end def generate_values_for_options(user) values_ids = ::KirguduBase::Settings::Value.all.map { |u| u.option_id } options = ::KirguduBase::Settings::Option.where { -(id.in values_ids) } options.each do |option| self.create_value_for_option(user, option) end end def create_value_for_option(user, option) value = ::KirguduBase::Settings::Value.new( option: option, creator: user, updater: user ) value.data = option.default_value if option.default_value value.save end def load_options(option_names) @options = {} ::KirguduBase::Settings::Option.where(slug: option_names).each do |option| @options[option.slug] = option end end def get_option_value(option_name) option = ::KirguduBase::Settings::Option.where(name: option_name).first option.data if option end def get_options_values(group) ::KirguduBase::Settings::Option.include(value).where(group_id: group) end protected def get_option_by_name(option_name) @options = self.load_options(0) unless @options @options[option_name] end end end end
Version data entries
10 entries across 10 versions & 1 rubygems