lib/configliere/define.rb in configliere-0.1.1 vs lib/configliere/define.rb in configliere-0.2.1

- old
+ new

@@ -91,23 +91,24 @@ # Coerce all params with types defined to their proper form def resolve_types! typed_params.each do |param, type| val = self[param] case - when val.nil? then val = nil - when (type == :boolean) then + 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) && val.is_a?(String)) - val = val.split(",") rescue nil + val = val.split(",") rescue nil # following types map blank to nil - when (val.blank?) then val = nil - 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 (val.blank?) 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 ((val.to_s == 'now') && (type == Date)) then val = Date.today when ((val.to_s == 'now') && (type == DateTime)) then val = DateTime.now - when (type == Date) then val = Date.parse(val) rescue nil - when (type == DateTime) then val = DateTime.parse(val) rescue nil + when (type == Date) then val = Date.parse(val) rescue nil + when (type == DateTime) then val = DateTime.parse(val) rescue nil else # nothing end self[param] = val end end