Sha256: e81c48891d33bfe5a23b066272241140fe9533f58d6a5464990714ac26d15818

Contents?: true

Size: 406 Bytes

Versions: 10

Compression:

Stored size: 406 Bytes

Contents

require "json"

class EasySettings::Coercion
  attr_reader :value

  def initialize(value)
    @value = value
  end

  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
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
easy-settings-2.0.2 lib/easy-settings/coercion.rb
easy-settings-2.0.1 lib/easy-settings/coercion.rb
easy-settings-2.0.0 lib/easy-settings/coercion.rb
easy-settings-1.4.0 lib/easy-settings/coercion.rb
easy-settings-1.3.1 lib/easy-settings/coercion.rb
easy-settings-1.3.0 lib/easy-settings/coercion.rb
easy-settings-1.2.0 lib/easy-settings/coercion.rb
easy-settings-1.1.0 lib/easy-settings/coercion.rb
easy-settings-1.0.1 lib/easy-settings/coercion.rb
easy-settings-1.0.0 lib/easy-settings/coercion.rb