Class: Riak::Link
- Includes:
- Util::Escape, Util::Translation
- Defined in:
- lib/riak/link.rb
Overview
Represents a link from one object to another in Riak
Instance Attribute Summary collapse
-
#bucket ⇒ String
The bucket of the related resource.
-
#key ⇒ String
The key of the related resource.
-
#tag ⇒ String
(also: #rel)
The relationship tag (or “rel”) of the other resource to this one.
Class Method Summary collapse
-
.parse(header_string) ⇒ Array<Link>
An array of Riak::Link structs parsed from the header.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(*args) ⇒ Link
constructor
A new instance of Link.
- #inspect ⇒ Object
- #to_s(new_scheme = false) ⇒ Object
- #to_walk_spec ⇒ Object
-
#url(new_scheme = false) ⇒ String
The URL (relative or absolute) of the related resource.
- #url=(value) ⇒ Object
Methods included from Util::Escape
#escape, #maybe_escape, #maybe_unescape, #unescape
Methods included from Util::Translation
Constructor Details
#initialize(url, tag) ⇒ Link #initialize(bucket, key, tag) ⇒ Link
Returns a new instance of Link.
58 59 60 61 62 63 64 65 |
# File 'lib/riak/link.rb', line 58 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 |
Instance Attribute Details
#bucket ⇒ String
Returns the bucket of the related resource.
31 32 33 |
# File 'lib/riak/link.rb', line 31 def bucket @bucket end |
#key ⇒ String
Returns the key of the related resource.
34 35 36 |
# File 'lib/riak/link.rb', line 34 def key @key end |
#tag ⇒ String Also known as: rel
Returns the relationship tag (or “rel”) of the other resource to this one.
26 27 28 |
# File 'lib/riak/link.rb', line 26 def tag @tag end |
Class Method Details
Instance Method Details
#==(other) ⇒ Object
100 101 102 |
# File 'lib/riak/link.rb', line 100 def ==(other) other.is_a?(Link) && url == other.url && tag == other.tag end |
#eql?(other) ⇒ Boolean
96 97 98 |
# File 'lib/riak/link.rb', line 96 def eql?(other) self == other end |
#hash ⇒ Object
92 93 94 |
# File 'lib/riak/link.rb', line 92 def hash self.to_s.hash end |
#inspect ⇒ Object
84 85 86 |
# File 'lib/riak/link.rb', line 84 def inspect to_s end |
#to_s(new_scheme = false) ⇒ Object
88 89 90 |
# File 'lib/riak/link.rb', line 88 def to_s(new_scheme = false) %Q[<#{url(new_scheme)}>; riaktag="#{tag}"] end |
#to_walk_spec ⇒ Object
104 105 106 107 |
# File 'lib/riak/link.rb', line 104 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) ⇒ String
Returns the URL (relative or absolute) of the related resource.
68 69 70 71 72 73 74 75 76 |
# File 'lib/riak/link.rb', line 68 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) ⇒ Object
78 79 80 81 82 |
# File 'lib/riak/link.rb', line 78 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 |