class Riak::Client::BeefcakeProtobuffsBackend::BucketPropertiesOperator
Constants
- QUORUMS
Attributes
backend[R]
Public Class Methods
new(backend)
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 12 def initialize(backend) @backend = backend end
Public Instance Methods
get(bucket, options = {})
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 16 def get(bucket, options = {}) response = backend.protocol do |p| p.write :GetBucketReq, get_request(bucket, options) p.expect :GetBucketResp, RpbGetBucketResp end properties = response.props.to_hash.stringify_keys return rubyfy(properties) end
put(bucket, props = {}, options = {})
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 27 def put(bucket, props = {}, options = {}) properties = riakify props request = put_request bucket, properties, options backend.protocol do |p| p.write :SetBucketReq, request p.expect :SetBucketResp end end
Private Instance Methods
get_request(bucket, options)
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 167 def get_request(bucket, options) RpbGetBucketReq.new options.merge name_options(bucket) end
name_options(bucket)
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 155 def name_options(bucket) o = {} if bucket.is_a? Riak::Bucket o[:bucket] = bucket.name o[:type] = bucket.type.name if bucket.needs_type? else o[:bucket] = bucket end return o end
put_request(bucket, props, options)
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 171 def put_request(bucket, props, options) req_options = options.merge name_options(bucket) req_options[:props] = RpbBucketProps.new props.symbolize_keys RpbSetBucketReq.new req_options end
riakify(requested_properties)
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 49 def riakify(requested_properties) props = requested_properties.stringify_keys riakify_quorums(props) riakify_hooks(props) riakify_modfuns(props) riakify_repl_mode(props) return props end
riakify_hooks(props)
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 89 def riakify_hooks(props) %w{precommit postcommit}.each do |k| next unless v = props[k] if v.is_a? Array props[k] = v.map{ |e| riakify_single_hook(e) } else props[k] = [riakify_single_hook(v)] end end end
riakify_modfun(modfun)
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 135 def riakify_modfun(modfun) m = modfun.stringify_keys RpbModFun.new(module: m['mod'], function: m['fun']) end
riakify_modfuns(props)
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 121 def riakify_modfuns(props) %w{chash_keyfun linkfun}.each do |k| next if props[k].nil? props[k] = riakify_modfun(props[k]) end end
riakify_quorums(props)
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 69 def riakify_quorums(props) %w{r pr w pw dw rw}.each do |k| next unless props[k] v = props[k].to_s next unless QUORUMS.keys.include? v props[k] = QUORUMS[v] end end
riakify_repl_mode(props)
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 140 def riakify_repl_mode(props) return unless props['repl'].is_a? Symbol props['repl'] = case props['repl'] when :false 0 when :realtime 1 when :fullsync 2 when :true 3 end end
riakify_single_hook(hook)
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 101 def riakify_single_hook(hook) message = RpbCommitHook.new if hook.is_a? String message.name = hook elsif hook['name'] message.name = hook['name'] else message.modfun = riakify_modfun(hook) end return message end
rubyfy(received_properties)
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 39 def rubyfy(received_properties) props = received_properties.dup rubyfy_quorums(props) rubyfy_hooks(props) rubyfy_modfuns(props) return props end
rubyfy_hooks(props)
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 79 def rubyfy_hooks(props) %w{precommit postcommit}.each do |k| next unless props[k] props[k] = props[k].map do |v| next v[:name] if v[:name] rubyfy_modfun(v[:modfun]) end end end
rubyfy_modfun(modfun)
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 128 def rubyfy_modfun(modfun) { 'mod' => modfun[:module], 'fun' => modfun[:function] } end
rubyfy_modfuns(props)
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 114 def rubyfy_modfuns(props) %w{chash_keyfun linkfun}.each do |k| next if props[k].nil? props[k] = rubyfy_modfun(props[k]) end end
rubyfy_quorums(props)
click to toggle source
# File lib/riak/client/beefcake/bucket_properties_operator.rb, line 60 def rubyfy_quorums(props) %w{r pr w pw dw rw}.each do |k| next unless props[k] next unless QUORUMS.values.include? props[k] props[k] = QUORUMS.invert[props[k]] end end