diff --git a/lib/envied/coercer.rb b/lib/envied/coercer.rb index 399eef5..c7e4a1f 100644 --- a/lib/envied/coercer.rb +++ b/lib/envied/coercer.rb @@ -11,6 +11,11 @@ def to_hash(str) require 'rack/utils' ::Rack::Utils.parse_query(str) end + + def to_uri(str) + require 'uri' + ::URI.parse(str) + end end Coercible::Coercer::String.send(:include, CoercerExts) @@ -38,7 +43,7 @@ def coerce_method_for(type) def self.supported_types @supported_types ||= begin - [:hash, :array, :time, :date, :symbol, :boolean, :integer, :string].sort + [:hash, :array, :time, :date, :symbol, :boolean, :integer, :string, :uri].sort end end diff --git a/spec/coercer_spec.rb b/spec/coercer_spec.rb index 23904e0..1764e17 100644 --- a/spec/coercer_spec.rb +++ b/spec/coercer_spec.rb @@ -95,5 +95,13 @@ def coerce_to(type) end end end + + describe 'uri coercion' do + let(:coerce){ coerce_to(:Uri) } + + it 'converts strings to uris' do + expect(coerce['http://www.google.com']).to be_a(URI) + end + end end end