Class: ScoutApm::Config::BooleanCoercion

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/config.rb

Overview

Any boolean is passed through A string is false iff it is 0 length, is “f”, or “false” - otherwise true An number is false if it is exactly 0 Other types are false

Instance Method Summary collapse

Instance Method Details

#coerce(val) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/scout_apm/config.rb', line 103

def coerce(val)
  case val
  when NilClass
    false
  when TrueClass
    val
  when FalseClass
    val
  when String
    coerce_string(val)
  when Numeric
    val != 0
  else
    false
  end
end

#coerce_string(val) ⇒ Object



120
121
122
123
124
125
126
127
# File 'lib/scout_apm/config.rb', line 120

def coerce_string(val)
  val = val.downcase.strip
  return false if val.length == 0
  return false if val == "f"
  return false if val == "false"

  true
end