app/models/setting.rb in fat_free_crm-0.16.4 vs app/models/setting.rb in fat_free_crm-0.17.1

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + # Copyright (c) 2008-2013 Michael Dvorkin and contributors. # # Fat Free CRM is freely distributable under the terms of MIT license. # See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php #------------------------------------------------------------------------------ @@ -77,9 +79,23 @@ # picking symbol translations from locale. If setting is not a symbol but # string it gets copied without translation. #------------------------------------------------------------------- def unroll(setting) send(setting).map { |key| [key.is_a?(Symbol) ? I18n.t(key) : key, key.to_sym] } + end + + # Retrieves the value object corresponding to the each key objects repeatedly. + # Equivalent to the #dig method on a Hash. + #------------------------------------------------------------------- + def dig(key, *rest) + value = self[key] + if value.nil? || rest.empty? + value + elsif value.respond_to?(:dig) + value.dig(*rest) + else + raise TypeError, "#{value.class} does not have #dig method" + end end def database_and_table_exists? # Returns false if table or database is unavailable. # Catches all database-related errors, so that Setting will return nil