Class: Riak::BucketProperties

Inherits:
Object
  • Object
show all
Defined in:
lib/riak/bucket_properties.rb

Overview

Provides a predictable and useful interface to bucket properties. Allows reading, reloading, and setting new values for bucket properties.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket) ⇒ BucketProperties

Create a properties object for a bucket (including bucket-typed buckets).

Parameters:



12
13
14
15
# File 'lib/riak/bucket_properties.rb', line 12

def initialize(bucket)
  @bucket = bucket
  @client = bucket.client
end

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



8
9
10
# File 'lib/riak/bucket_properties.rb', line 8

def bucket
  @bucket
end

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/riak/bucket_properties.rb', line 7

def client
  @client
end

Instance Method Details

#[](property_name) ⇒ Object

Read a bucket property

Parameters:

Returns:

  • (Object)

    the bucket property’s value



49
50
51
# File 'lib/riak/bucket_properties.rb', line 49

def [](property_name)
  cached_props[property_name.to_s]
end

#[]=(property_name, value) ⇒ Object

Write a bucket property

Parameters:



56
57
58
59
# File 'lib/riak/bucket_properties.rb', line 56

def []=(property_name, value)
  value = unwrap_index(value) if property_name == 'search_index'
  cached_props[property_name.to_s] = value
end

#merge!(other) ⇒ Object

Take bucket properties from a given Hash or Riak::BucketProperties object.

Parameters:



36
37
38
# File 'lib/riak/bucket_properties.rb', line 36

def merge!(other)
  cached_props.merge! other
end

#reloadObject

Clobber the cached properties, and reload them from Riak.



18
19
20
21
22
# File 'lib/riak/bucket_properties.rb', line 18

def reload
  @cached_props = nil
  cached_props
  true
end

#storeObject

Write bucket properties and invalidate the cache in this object.



25
26
27
28
29
30
31
# File 'lib/riak/bucket_properties.rb', line 25

def store
  client.backend do |be|
    be.bucket_properties_operator.put bucket, cached_props
  end
  @cached_props = nil
  return true
end

#to_hashHash<String, Object>

Convert the cached properties into a hash for merging.

Returns:



42
43
44
# File 'lib/riak/bucket_properties.rb', line 42

def to_hash
  cached_props
end