Sha256: c4207795fecb7aa45c054bf16650bcdd4f09f5bdfad382191f6ff89b9f2b1a5e
Contents?: true
Size: 1.54 KB
Versions: 3
Compression:
Stored size: 1.54 KB
Contents
#:nodoc: module Settings #:nodoc: module Model ## # Model that represents a single setting. This model is also used to retrieve # all possible values for a certain settngs. This is done by calling a method # that matches the format get_SETTING-NAME_values. For example, a setting named "theme" # would result in a call to Settings::Model::Setting#get_theme_values. # # In order to add new method you'll have to monkey patch this model as following: # # class Setting < Sequel::Model # def self.get_my_setting_values # # Do something and return it... # end # end # # @author Yorick Peterse # @since 0.1 # @todo Monkey patching a model in order to get possible values isn't the nicest way # of solving this problem but it does allow for extra flexibility. It might be a good # idea to refactor this and put it in it's own class/plugin/whatever. # class Setting < Sequel::Model ## # Retrieves all settings and returns them as a key/value hash. # # @author Yorick Peterse # @since 0.1 # @return [Hash] key/value hash containing all settings and their values. # def self.get_settings settings = {} self.all.each do |s| if s.value.nil? value = s.default else value = s.value end settings[s.name.to_sym] = value end return settings end end # Setting end # Model end # Settings
Version data entries
3 entries across 3 versions & 1 rubygems