Class: XMLable::Options::Storage

Inherits:
Hash
  • Object
show all
Defined in:
lib/xmlable/options/storage.rb

Overview

Storage class stores handlers options

Instance Method Summary collapse

Instance Method Details

#merge_opts(other) ⇒ XMLable::Options::Storage

Merge options

Parameters:

Returns:



83
84
85
86
87
88
89
90
91
92
93
94
# 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 = {}) ⇒ Object

Initialize

Parameters:

  • hash (Hash) (defaults to: {})

    initial params



12
13
14
# File 'lib/xmlable/options/storage.rb', line 12

def new(hash = {})
  opts_set(hash)
end

#opt_default_set(key, value) ⇒ Object

Default option setter

Parameters:

  • key (String, Symbol)
  • value (Object)


66
67
68
# File 'lib/xmlable/options/storage.rb', line 66

def opt_default_set(key, value)
  self[key.to_sym] = value
end

#opt_set(key, value) ⇒ XMLable::Options::Storage

Set option

Parameters:

  • key (String, Symbol)
  • value (Object)

Returns:



33
34
35
36
37
38
39
40
# 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) ⇒ Object

Set the drop empty objects

Parameters:

  • (Boolean)


47
48
49
# 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) ⇒ Object

Set the drop undescribed objects

Parameters:

  • (Boolean)


56
57
58
# 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) ⇒ Object

Set multiple options

Parameters:

  • hash (Hash)


21
22
23
# File 'lib/xmlable/options/storage.rb', line 21

def opts_set(hash)
  hash.each { |key, value| opt_set(key, value) }
end