class Compendium::Params
Attributes
options[R]
Public Class Methods
model_name()
click to toggle source
# File lib/compendium/params.rb, line 18 def self.model_name ActiveModel::Name.new(Compendium::Params, Compendium, 'compendium.params') end
new(hash = {}, options = {})
click to toggle source
Calls superclass method
# File lib/compendium/params.rb, line 13 def initialize(hash = {}, options = {}) @options = options super(prepare_hash_from_options(hash)) end
Protected Instance Methods
get_default_value(current, default)
click to toggle source
# File lib/compendium/params.rb, line 39 def get_default_value(current, default) if current.blank? && !default.blank? default.respond_to?(:call) ? default.call : default else current end end
prepare_hash_from_options(params)
click to toggle source
# File lib/compendium/params.rb, line 24 def prepare_hash_from_options(params) params = params.slice(*options.keys) options.each do |option| begin klass = "Compendium::#{"#{option.type}Param".classify}".constantize params[option.name] = klass.new(get_default_value(params[option.name], option.default), option.choices) rescue IndexError raise IndexError, "invalid index for #{option_name}" end end params end