class Riak::BucketProperties

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

Attributes

bucket[R]
client[R]

Public Class Methods

new(bucket) click to toggle source

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

[](property_name) click to toggle source

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
[]=(property_name, value) click to toggle source

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
merge!(other) click to toggle source

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
reload() click to toggle source

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
store() click to toggle source

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
to_hash() click to toggle source

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

cached_props() click to toggle source
# 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
unwrap_index(value) click to toggle source
# File lib/riak/bucket_properties.rb, line 68
def unwrap_index(value)
  return value.name if value.is_a? Riak::Search::Index

  value
end