class XMLable::Options::Storage
Storage
class stores handlers options
Public Instance Methods
merge_opts(other)
click to toggle source
Merge options
@param [Hash, XMLable::Options::Storage] opts
@return [XMLable::Options::Storage]
# File lib/xmlable/options/storage.rb, line 83 def merge_opts(other) merger = proc do |_, v1, v2| if [v1, v2].all? { |h| h.is_a?(Hash) } v1.merge(v2, &merger) elsif [v1, v2].all? { |h| h.is_a?(Array) } v1 + v2 else v2 end end merge(other, &merger) end
new(hash = {})
click to toggle source
Initialize
@param [Hash] hash initial params
# File lib/xmlable/options/storage.rb, line 12 def new(hash = {}) opts_set(hash) end
opt_default_set(key, value)
click to toggle source
Default option setter
@param [String, Symbol] key @param [Object] value
# File lib/xmlable/options/storage.rb, line 66 def opt_default_set(key, value) self[key.to_sym] = value end
opt_set(key, value)
click to toggle source
Set option
@param [String, Symbol] key @param [Object] value
@return [XMLable::Options::Storage]
# File lib/xmlable/options/storage.rb, line 33 def opt_set(key, value) key = key.to_s value = false if key =~ /^no_/ key = key.sub(/^no_/, '').to_sym method = "opt_set_#{key}" respond_to?(method) ? send(method, value) : opt_default_set(key, value) self end
opt_set_drop_empty(value)
click to toggle source
Set the drop empty objects
@param [Boolean]
# File lib/xmlable/options/storage.rb, line 47 def opt_set_drop_empty(value) self[:drop_empty_attributes] = self[:drop_empty_elements] = value end
opt_set_drop_undescribed(value)
click to toggle source
Set the drop undescribed objects
@param [Boolean]
# File lib/xmlable/options/storage.rb, line 56 def opt_set_drop_undescribed(value) self[:drop_undescribed_attributes] = self[:drop_undescribed_elements] = value end
opts_set(hash)
click to toggle source
Set multiple options
@param [Hash] hash
# File lib/xmlable/options/storage.rb, line 21 def opts_set(hash) hash.each { |key, value| opt_set(key, value) } end