Module: SettingsManager::Validation::ClassMethods

Defined in:
lib/settings-manager/validation.rb

Instance Method Summary collapse

Instance Method Details

#allowed_settings_keys(keys = nil) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/settings-manager/validation.rb', line 20

def allowed_settings_keys(keys = nil)
  if keys.present? && keys.kind_of?(Array)
    @allowed_settings_keys = keys
  else
    @allowed_settings_keys || []
  end
end

#key_allowed?(key) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'lib/settings-manager/validation.rb', line 28

def key_allowed?(key)
  if allowed_settings_keys.any?
    allowed_settings_keys.include?(key.to_sym)
  else
    true
  end
end

#validates_setting(value, options = {}) ⇒ Object



36
37
38
39
# File 'lib/settings-manager/validation.rb', line 36

def validates_setting(value, options = {})
  options[:if] = Proc.new { |record| value.to_s == record.key.to_s }
  validates(:value, options)
end