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!, #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:



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/riak/bucket_typed/bucket.rb', line 22

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



16
17
18
# File 'lib/riak/bucket_typed/bucket.rb', line 16

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



119
120
121
122
123
# File 'lib/riak/bucket_typed/bucket.rb', line 119

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

#clear_propsObject



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

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



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

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



40
41
42
43
44
# File 'lib/riak/bucket_typed/bucket.rb', line 40

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



108
109
110
# File 'lib/riak/bucket_typed/bucket.rb', line 108

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



71
72
73
# File 'lib/riak/bucket_typed/bucket.rb', line 71

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:



66
67
68
# File 'lib/riak/bucket_typed/bucket.rb', line 66

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.



114
115
116
117
# File 'lib/riak/bucket_typed/bucket.rb', line 114

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

#pretty_print(pp) ⇒ Object

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



91
92
93
94
95
96
97
98
99
# File 'lib/riak/bucket_typed/bucket.rb', line 91

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



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

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

#props=(new_props) ⇒ Object

Raises:

  • (ArgumentError)


75
76
77
78
79
# File 'lib/riak/bucket_typed/bucket.rb', line 75

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