Module: Collapsium::Config::Support::Values

Included in:
Configuration, Configuration
Defined in:
lib/collapsium-config/support/values.rb

Overview

Contains helper functions for parsing configuration values.

Instance Method Summary collapse

Instance Method Details

#array_value(value) ⇒ Object

Given the value, turn it into an Array:

  • comma-separated strings are split

  • other single values are wrapped into an Array



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/collapsium-config/support/values.rb', line 25

def array_value(value)
  # Split comma-separated strings.
  if value.respond_to? :split
    value = value.split(/,/)
  end

  # If the value is an Array, we strip its string elements.
  if value.is_a? Array
    value = value.map do |v|
      if v.respond_to? :strip
        next v.strip
      end
      next v
    end
  else
    # Otherwise turn the value into an Array if it's a single
    # value.
    value = [value]
  end

  return value
end