lib/restfully/link.rb in restfully-0.3.2 vs lib/restfully/link.rb in restfully-0.4.0
- old
+ new
@@ -1,5 +1,6 @@
+require 'uri'
module Restfully
class Link
VALID_RELATIONSHIPS = %w{member parent collection self alternate}
RELATIONSHIPS_REQUIRING_TITLE = %w{collection member}
@@ -7,22 +8,22 @@
attr_reader :rel, :title, :href, :errors
def initialize(attributes = {})
@rel = attributes['rel']
@title = attributes['title']
- @href = attributes['href']
+ @href = URI.parse(attributes['href'].to_s)
@resolvable = attributes['resolvable'] || false
@resolved = attributes['resolved'] || false
end
def resolvable?; @resolvable == true; end
def resolved?; @resolved == true; end
def self?; @rel == 'self'; end
def valid?
@errors = []
- if href.nil? || href.empty?
- errors << "href cannot be empty."
+ if href.nil?
+ errors << "href cannot be nil."
end
unless VALID_RELATIONSHIPS.include?(rel)
errors << "#{rel} is not a valid link relationship."
end
if (!title || title.empty?) && RELATIONSHIPS_REQUIRING_TITLE.include?(rel)
\ No newline at end of file