class Riak::Link
Represents a link from one object to another in Riak
Attributes
bucket[RW]
@return [String] the bucket of the related resource
key[RW]
@return [String] the key of the related resource
rel[RW]
@return [String] the relationship tag (or “rel”) of the other resource to this one
rel=[RW]
@return [String] the relationship tag (or “rel”) of the other resource to this one
tag[RW]
@return [String] the relationship tag (or “rel”) of the other resource to this one
Public Class Methods
new(*args)
click to toggle source
@overload initialize(url, tag)
@param [String] url the url of the related resource @param [String] tag the tag for the related resource
@overload initialize(bucket, key, tag)
@param [String] bucket the bucket of the related resource @param [String] key the key of the related resource @param [String] tag the tag for the related resource
# File lib/riak/link.rb, line 45 def initialize(*args) raise ArgumentError unless (2..3).include?(args.size) if args.size == 2 self.url, @tag = args else @bucket, @key, @tag = args end end
parse(header_string)
click to toggle source
@param [String] header_string the string value of the Link: HTTP header from a Riak
response @return [Array<Link>] an array of Riak::Link
structs parsed from the header
# File lib/riak/link.rb, line 32 def self.parse(header_string) header_string.scan(%r{<([^>]+)>\s*;\s*(?:rel|riaktag)=\"([^\"]+)\"}).map do |match| new(match[0], match[1]) end end
Public Instance Methods
==(other)
click to toggle source
# File lib/riak/link.rb, line 87 def ==(other) other.is_a?(Link) && url == other.url && tag == other.tag end
eql?(other)
click to toggle source
# File lib/riak/link.rb, line 83 def eql?(other) self == other end
hash()
click to toggle source
# File lib/riak/link.rb, line 79 def hash self.to_s.hash end
inspect()
click to toggle source
# File lib/riak/link.rb, line 71 def inspect to_s end
to_s(new_scheme = false)
click to toggle source
# File lib/riak/link.rb, line 75 def to_s(new_scheme = false) %Q[<#{url(new_scheme)}>; riaktag="#{tag}"] end
to_walk_spec()
click to toggle source
# File lib/riak/link.rb, line 91 def to_walk_spec raise t("bucket_link_conversion") if tag == "up" || key.nil? WalkSpec.new(:bucket => bucket, :tag => tag) end
url(new_scheme = false)
click to toggle source
@return [String] the URL (relative or absolute) of the related resource
# File lib/riak/link.rb, line 55 def url(new_scheme = false) return @url unless @bucket if new_scheme "/buckets/#{escape(bucket)}" + (key.blank? ? "" : "/keys/#{escape(key)}") else "/riak/#{escape(bucket)}" + (key.blank? ? "" : "/#{escape(key)}") end end
url=(value)
click to toggle source
# File lib/riak/link.rb, line 65 def url=(value) @url = value @bucket = unescape($1) if value =~ %r{^/buckets/([^/]+)/?} || value =~ %r{^/[^/]+/([^/]+)/?} @key = unescape($1) if value =~ %r{^/buckets/[^/]+/keys/([^/]+)/?} || value =~ %r{^/[^/]+/[^/]+/([^/]+)/?} end