Class: EasySettings::Coercion

Inherits:
Object
  • Object
show all
Defined in:
lib/easy-settings/coercion.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Coercion

Returns a new instance of Coercion.



6
7
8
# File 'lib/easy-settings/coercion.rb', line 6

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/easy-settings/coercion.rb', line 4

def value
  @value
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/easy-settings/coercion.rb', line 10

def run
  case value
  when "false"
    false
  when "true"
    true
  when /^json:/
    JSON.parse(value.gsub(/^json:/, ""))
  when /^\+/ # don't treat +41791234567 as a number
    value
  else
    Integer(value) rescue Float(value) rescue value
  end
end