lib/configliere/define.rb
def resolve_types!
      params_with(:type).each do |param, type|
        val  = self[param]
        case
        when val.nil?            then val = nil
        when (type == :boolean)  then
          if ['false', false, 0, '0', ''].include?(val) then val = false else val = true end
        when (type == Array)
          if val.is_a?(String) then val = val.split(",") rescue nil ; end
        # for all following types, map blank/empty to nil
        when (val.respond_to?(:empty?) && val.empty?) then val = nil
        when (type == :filename) then val = File.expand_path(val)
        when (type == Float)     then val = val.to_f
        when (type == Integer)   then val = val.to_i
        when (type == Symbol)    then val = val.to_s.to_sym     rescue nil
        when (type == Regexp)    then val = Regexp.new(val)     rescue nil
        when ((val.to_s == 'now') && (type == Date))     then val = Date.today
        when ((val.to_s == 'now') && (type == DateTime)) then val = DateTime.now
        when ((val.to_s == 'now') && (type == Time))     then val = Time.now
        when [Date, Time, DateTime].include?(type)       then val = type.parse(val) rescue nil
        else raise ArgumentError, "Unknown type #{type} given"
        end
        self[param] = val
      end
    end
# Coerce all params with types defined to their proper form
Coerce all params with types defined to their proper form
Coerce all params with types defined to their proper form
def resolve_types!
      params_with(:type).each do |param, type|
        val  = self[param]
        case
        when val.nil?            then val = nil
        when (type == :boolean)  then
          if ['false', false, 0, '0', ''].include?(val) then val = false else val = true end
        when (type == Array)
          if val.is_a?(String) then val = val.split(",") rescue nil ; end
        when (val.respond_to?(:empty?) && val.empty?) then val = nil
        when (type == :filename) then val = File.expand_path(val)
        when (type == Float)     then val = val.to_f
        when (type == Integer)   then val = val.to_i
        when (type == Symbol)    then val = val.to_s.to_sym     rescue nil
        when (type == Regexp)    then val = Regexp.new(val)     rescue nil
        when ((val.to_s == 'now') && (type == Date))     then val = Date.today
        when ((val.to_s == 'now') && (type == DateTime)) then val = DateTime.now
        when ((val.to_s == 'now') && (type == Time))     then val = Time.now
        when [Date, Time, DateTime].include?(type)       then val = type.parse(val) rescue nil
        else raise ArgumentError, "Unknown type #{type} given"
        end
        self[param] = val
      end
    end
def resolve_types! params_with ( :type ) . each do | param , type | val = self [ param ] case when val . nil? then val = nil when ( type == :boolean ) then if [ 'false' , false , 0 , '0' , '' ] . include? ( val ) then val = false else val = true end when ( type == Array ) if val . is_a? ( String ) then val = val . split ( "," ) rescue nil ; end when ( val . respond_to? ( :empty? ) && val . empty? ) then val = nil when ( type == :filename ) then val = File . expand_path ( val ) when ( type == Float ) then val = val . to_f when ( type == Integer ) then val = val . to_i when ( type == Symbol ) then val = val . to_s . to_sym rescue nil when ( type == Regexp ) then val = Regexp . new ( val ) rescue nil when ( ( val . to_s == 'now' ) && ( type == Date ) ) then val = Date . today when ( ( val . to_s == 'now' ) && ( type == DateTime ) ) then val = DateTime . now when ( ( val . to_s == 'now' ) && ( type == Time ) ) then val = Time . now when [ Date , Time , DateTime ] . include? ( type ) then val = type . parse ( val ) rescue nil else raise ArgumentError , "Unknown type #{type} given" end self [ param ] = val end end
Coerce all params with types defined to their proper form
Coerce all params with types defined to their proper form
# for all following types, map blank/empty to nil