Class: Riak::WalkSpec
- Inherits:
-
Object
- Object
- Riak::WalkSpec
- Includes:
- Util::Escape, Util::Translation
- Defined in:
- riak-client/lib/riak/walk_spec.rb
Overview
The specification of how to follow links from one object to another in Riak, when using the link-walker resource. Example link-walking operation:
GET /riak/artists/REM/albums,_,_/tracks,_,1
This operation would have two WalkSpecs:
Riak::WalkSpec.new({:bucket => 'albums'}) Riak::WalkSpec.new({:bucket => 'tracks', :result => true})
Instance Attribute Summary (collapse)
-
- (String) bucket
The bucket followed links should be restricted to.
-
- (Boolean) keep
Whether objects should be returned from this phase of link walking.
-
- (String) tag
The “riaktag” or “rel” that followed links should be restricted to.
Class Method Summary (collapse)
-
+ (Object) normalize(*params)
Normalize a list of walk specs into WalkSpec objects.
Instance Method Summary (collapse)
- - (Object) ==(other)
- - (Object) ===(other)
-
- (WalkSpec) initialize(*args)
constructor
Creates a walk-spec for use in finding other objects in Riak.
-
- (Object) to_s
Converts the walk-spec into the form required by the link-walker resource URL.
Methods included from Util::Escape
Methods included from Util::Translation
Constructor Details
- (WalkSpec) initialize(hash) - (WalkSpec) initialize(bucket, tag, keep)
Creates a walk-spec for use in finding other objects in Riak.
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'riak-client/lib/riak/walk_spec.rb', line 74 def initialize(*args) args.flatten! case args.size when 1 hash = args.first raise ArgumentError, t("hash_type", :hash => hash.inspect) unless Hash === hash assign(hash[:bucket], hash[:tag], hash[:keep]) when 3 assign(*args) else raise ArgumentError, t("wrong_argument_count_walk_spec") end end |
Instance Attribute Details
- (String) bucket
The bucket followed links should be restricted to. “_” represents all buckets.
31 32 33 |
# File 'riak-client/lib/riak/walk_spec.rb', line 31 def bucket @bucket end |
- (Boolean) keep
Whether objects should be returned from this phase of link walking. Default is false.
37 38 39 |
# File 'riak-client/lib/riak/walk_spec.rb', line 37 def keep @keep end |
- (String) tag
The “riaktag” or “rel” that followed links should be restricted to. “_” represents all tags.
34 35 36 |
# File 'riak-client/lib/riak/walk_spec.rb', line 34 def tag @tag end |
Class Method Details
+ (Object) normalize(*params)
Normalize a list of walk specs into WalkSpec objects.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'riak-client/lib/riak/walk_spec.rb', line 40 def self.normalize(*params) params.flatten! specs = [] while params.length > 0 param = params.shift case param when Hash specs << new(param) when WalkSpec specs << param else if params.length >= 2 specs << new(param, params.shift, params.shift) else raise ArgumentError, t("too_few_arguments", :params => params.inspect) end end end specs end |
Instance Method Details
- (Object) ==(other)
95 96 97 |
# File 'riak-client/lib/riak/walk_spec.rb', line 95 def ==(other) other.is_a?(WalkSpec) && other.bucket == bucket && other.tag == tag && other.keep == keep end |
- (Object) ===(other)
99 100 101 102 103 104 105 106 107 108 109 |
# File 'riak-client/lib/riak/walk_spec.rb', line 99 def ===(other) self == other || case other when WalkSpec other.keep == keep && (bucket == "_" || bucket == other.bucket) && (tag == "_" || tag == other.tag) when Link (bucket == "_" || bucket == other.url.split("/")[2]) && (tag == "_" || tag == other.rel) end end |
- (Object) to_s
Converts the walk-spec into the form required by the link-walker resource URL
89 90 91 92 93 |
# File 'riak-client/lib/riak/walk_spec.rb', line 89 def to_s b = @bucket && escape(@bucket) || '_' t = @tag && escape(@tag) || '_' "#{b},#{t},#{@keep ? '1' : '_'}" end |