Class: Riak::BucketTyped::Bucket

Inherits:
Riak::Bucket show all
Defined in:
lib/riak/bucket_typed/bucket.rb

Overview

A bucket that has a Riak::BucketType attached to it. Normally created using the Riak::BucketType#bucket method. Inherits most of its behavior from the Riak::Bucket class.

Constant Summary

Constants inherited from Riak::Bucket

Riak::Bucket::SEARCH_PRECOMMIT_HOOK

Instance Attribute Summary collapse

Attributes inherited from Riak::Bucket

#client, #name

Instance Method Summary collapse

Methods inherited from Riak::Bucket

#allow_mult, #allow_mult=, #counter, #disable_index!, #enable_index!, #exist_many, #exists?, #get_many, #get_or_new, #get_preflist, #is_indexed?, #n_value, #n_value=, #new

Methods included from Util::Translation

#i18n_scope, #t

Methods included from Util::String

equal_bytes?

Constructor Details

#initialize(client, name, type) ⇒ Bucket

Create a bucket-typed bucket manually.

Parameters:



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/riak/bucket_typed/bucket.rb', line 36

def initialize(client, name, type)
  if type.is_a? String
    type = client.bucket_type type
  elsif !(type.is_a? BucketType)
    raise ArgumentError, t('argument_error.bucket_type', bucket_type: type)
  end

  @type = type

  super client, name
end

Instance Attribute Details

#typeBucketType (readonly)

Returns the bucket type used with this bucket.

Returns:

  • (BucketType)

    the bucket type used with this bucket



30
31
32
# File 'lib/riak/bucket_typed/bucket.rb', line 30

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



133
134
135
136
137
# File 'lib/riak/bucket_typed/bucket.rb', line 133

def ==(other)
  return false unless self.class == other.class
  return false unless self.type == other.type
  super
end

#clear_propsObject



99
100
101
102
# File 'lib/riak/bucket_typed/bucket.rb', line 99

def clear_props
  @props = nil
  @client.clear_bucket_props(self, type: self.type.name)
end

#delete(key, options = { }) ⇒ Object

Deletes a key from the bucket

Parameters:

  • key (String)

    the key to delete

  • options (Hash) (defaults to: { })

    quorum options

Options Hash (options):

  • :rw (Fixnum)
    • the read/write quorum for the

    delete

  • :vclock (String)
    • the vector clock of the

    object being deleted



68
69
70
# File 'lib/riak/bucket_typed/bucket.rb', line 68

def delete(key, options = {  })
  super key, o(options)
end

#get(key, options = { }) ⇒ Riak::RObject Also known as: []

Retrieve an object from within the bucket type and bucket.

Parameters:

  • key (String)

    the key of the object to retrieve

  • options (Hash) (defaults to: { })

    query parameters for the request

Options Hash (options):

  • :r (Fixnum)
    • the read quorum for the request - how many nodes should concur on the read

Returns:

Raises:

  • (FailedRequest)

    if the object is not found or some other error occurs



54
55
56
57
58
# File 'lib/riak/bucket_typed/bucket.rb', line 54

def get(key, options = {  })
  object = super key, o(options)
  object.bucket = self
  return object
end

#get_index(index, query, options = { }) ⇒ Array<String>

Note:

This will only work if your Riak installation supports 2I.

Queries a secondary index on the bucket-typed bucket.

Parameters:

  • index (String)

    the name of the index

  • query (String, Integer, Range)

    the value of the index, or a Range of values to query

Returns:

  • (Array<String>)

    a list of keys that match the index query



122
123
124
# File 'lib/riak/bucket_typed/bucket.rb', line 122

def get_index(index, query, options = {  })
  super index, query, o(options)
end

#inspectString

Returns a friendly representation of this bucket-typed bucket.

Returns:

  • (String)

    a friendly representation of this bucket-typed bucket



85
86
87
# File 'lib/riak/bucket_typed/bucket.rb', line 85

def inspect
  "#<Riak::BucketTyped::Bucket {#{ type.name }/#{ name }}>"
end

#keys(options = { }) {|Array<String>| ... } ⇒ Array<String>

Note:

This operation has serious performance implications and should not be used in production applications.

Retrieves a list of keys in this bucket. If a block is given, keys will be streamed through the block (useful for large buckets). When streaming, results of the operation will not be returned to the caller.

Yields:

  • (Array<String>)

    a list of keys from the current chunk

Returns:



80
81
82
# File 'lib/riak/bucket_typed/bucket.rb', line 80

def keys(options = {  }, &block)
  super o(options), &block
end

#needs_type?Boolean

Does this Riak::BucketTyped::Bucket have a non-default bucket type?

Returns:

  • (Boolean)

    true if this bucket has a non-default type.



128
129
130
131
# File 'lib/riak/bucket_typed/bucket.rb', line 128

def needs_type?
  return true unless type.default?
  return false
end

#pretty_print(pp) ⇒ Object

Pretty prints the bucket for ‘pp` or `pry`.



105
106
107
108
109
110
111
112
113
# File 'lib/riak/bucket_typed/bucket.rb', line 105

def pretty_print(pp)
  pp.object_group self do
    pp.breakable
    pp.text "bucket_type="
    type.pretty_print(pp)
    pp.breakable
    pp.text "name=#{name}"
  end
end

#propsObject



95
96
97
# File 'lib/riak/bucket_typed/bucket.rb', line 95

def props
  @props ||= @client.get_bucket_props(self, type: self.type.name)
end

#props=(new_props) ⇒ Object

Raises:

  • (ArgumentError)


89
90
91
92
93
# File 'lib/riak/bucket_typed/bucket.rb', line 89

def props=(new_props)
  raise ArgumentError, t('hash_type', hash: new_props.inspect) unless new_props.is_a? Hash
  complete_props = props.merge new_props
  @client.set_bucket_props(self, complete_props, self.type.name)
end