Class: MournfulSettings::Setting
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MournfulSettings::Setting
- Defined in:
- lib/mournful_settings/setting.rb,
lib/mournful_settings/setting/cipher.rb
Defined Under Namespace
Modules: Cipher
Constant Summary collapse
- VALUE_TYPES =
['text', 'number', 'decimal']
Class Method Summary collapse
- .for(name, default = nil) ⇒ Object
- .recrypt_all(&do_while_unencrypted) ⇒ Object
- .value_types ⇒ Object
Instance Method Summary collapse
Class Method Details
.for(name, default = nil) ⇒ Object
21 22 23 24 |
# File 'lib/mournful_settings/setting.rb', line 21 def self.for(name, default = nil) setting = find_by_name(name) setting ? setting.value : default end |
.recrypt_all(&do_while_unencrypted) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/mournful_settings/setting.rb', line 41 def self.recrypt_all &do_while_unencrypted encrypted = where(:encrypted => true) encrypted.each {|s| s.encrypted = false; s.save} do_while_unencrypted.call if do_while_unencrypted encrypted.each {|s| s.encrypted = true; s.save} end |
.value_types ⇒ Object
17 18 19 |
# File 'lib/mournful_settings/setting.rb', line 17 def self.value_types VALUE_TYPES end |
Instance Method Details
#value ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mournful_settings/setting.rb', line 26 def value if value_type.present? parent_value = encrypted? ? decrypt(super) : super case value_type.to_s when 'number' parent_value.to_f when 'decimal' BigDecimal.new(parent_value.to_s) else parent_value end end end |