Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/envied/coercer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions spec/coercer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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