class Riak::BucketProperties
Provides a predictable and useful interface to bucket properties. Allows reading, reloading, and setting new values for bucket properties.
Attributes
Public Class Methods
Create a properties object for a bucket (including bucket-typed buckets). @param [Riak::Bucket, Riak::BucketTyped::Bucket] bucket
# File lib/riak/bucket_properties.rb, line 12 def initialize(bucket) @bucket = bucket @client = bucket.client end
Public Instance Methods
Read a bucket property @param [String] property_name @return [Object] the bucket property's value
# File lib/riak/bucket_properties.rb, line 49 def [](property_name) cached_props[property_name.to_s] end
Write a bucket property @param [String] property_name @param [Object] value
# 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
Take bucket properties from a given {Hash} or {Riak::BucketProperties} object. @param [Hash<String, Object>, Riak::BucketProperties] other
# File lib/riak/bucket_properties.rb, line 36 def merge!(other) cached_props.merge! other end
Clobber the cached properties, and reload them from Riak
.
# File lib/riak/bucket_properties.rb, line 18 def reload @cached_props = nil cached_props true end
Write bucket properties and invalidate the cache in this object.
# 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
Convert the cached properties into a hash for merging. @return [Hash<String, Object>] the bucket properties in a {Hash}
# File lib/riak/bucket_properties.rb, line 42 def to_hash cached_props end
Private Instance Methods
# File lib/riak/bucket_properties.rb, line 62 def cached_props @cached_props ||= client.backend do |be| be.bucket_properties_operator.get bucket end end
# File lib/riak/bucket_properties.rb, line 68 def unwrap_index(value) return value.name if value.is_a? Riak::Search::Index value end