app/models/setting.rb in fat_free_crm-0.21.0 vs app/models/setting.rb in fat_free_crm-0.22.0
- old
+ new
@@ -56,24 +56,23 @@
def [](name)
# Return value if cached
return cache[name] if cache.key?(name)
# Check database
- if database_and_table_exists?
- if setting = find_by_name(name.to_s)
- return cache[name] = setting.value unless setting.value.nil?
- end
+ if database_and_table_exists? && (setting = find_by_name(name.to_s))&.value.present?
+ return cache[name] = setting.value
end
# Check YAML settings
- return cache[name] = yaml_settings[name] if yaml_settings.key?(name)
+ cache[name] = yaml_settings[name] if yaml_settings.key?(name)
end
# Set setting value
#-------------------------------------------------------------------
def []=(name, value)
raise ArgumentError, "name cannot be blank" if name.blank?
return nil unless database_and_table_exists?
+
setting = find_by_name(name.to_s) || new(name: name.to_s)
setting.value = value
setting.save
cache[name] = value
end