class Saneitized::Hash
Public Class Methods
new(hash = {}, options = {})
click to toggle source
Calls superclass method
# File lib/saneitized/hash.rb, line 7 def initialize(hash = {}, options = {}) @options = options @key_blacklist = Array(options.fetch(:key_blacklist){[]}) new_hash = {} hash.each do |key, value| new_hash[sane_key(key)] = convert_key_value(key, value) end super(new_hash) self end
Public Instance Methods
[]=(key, value)
click to toggle source
Calls superclass method
# File lib/saneitized/hash.rb, line 18 def []=(key, value) super key, Saneitized.convert(value, @options) end
merge!(*args, &block)
click to toggle source
# File lib/saneitized/hash.rb, line 22 def merge!(*args, &block) raise NotImplementedError end
Private Instance Methods
convert_key_value(key, value)
click to toggle source
# File lib/saneitized/hash.rb, line 32 def convert_key_value(key, value) if @key_blacklist.include? key value else Saneitized.convert(value, @options) end end
sane_key(key)
click to toggle source
# File lib/saneitized/hash.rb, line 28 def sane_key(key) @options[:saneitize_keys] ? Saneitized.convert(key) : key end