Class: Riak::BucketType

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

Overview

A representation of a bucket type

Constant Summary collapse

DEFAULT_NAME =

The name of Riak’s default bucket type.

'default'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, name) ⇒ BucketType

Create a bucket type object manually.

Parameters:

  • client (Client)

    the Client for this bucket type

  • name (String)

    the name of this bucket type



15
16
17
# File 'lib/riak/bucket_type.rb', line 15

def initialize(client, name)
  @client, @name = client, name
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



70
71
72
73
74
75
# File 'lib/riak/bucket_type.rb', line 70

def ==(other)
  return false unless self.class == other.class
  return false unless self.client == other.client
  return false unless self.name == other.name
  true
end

#bucket(bucket_name) ⇒ Object

Get a bucket of this type

Parameters:

  • bucket_name (String)

    the name of this bucket



27
28
29
# File 'lib/riak/bucket_type.rb', line 27

def bucket(bucket_name)
  BucketTyped::Bucket.new client, bucket_name, self
end

#data_type_classClass<Riak::Crdt::Base>

Return the data type used for handling the CRDT stored in this bucket type. Returns ‘nil` for a non-CRDT bucket type.

Returns:

Raises:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/riak/bucket_type.rb', line 55

def data_type_class
  return nil unless dt = properties[:datatype]
  parent = Riak::Crdt
  case dt
  when 'counter'
    parent::Counter
  when 'map'
    parent::Map
  when 'set'
    parent::Set
  else
    raise CrdtError::UnrecognizedDataType.new dt
  end
end

#default?Boolean

Is this bucket type the default?

Returns:

  • (Boolean)


21
22
23
# File 'lib/riak/bucket_type.rb', line 21

def default?
  name == DEFAULT_NAME
end

#pretty_print(pp) ⇒ Object

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



32
33
34
35
36
37
# File 'lib/riak/bucket_type.rb', line 32

def pretty_print(pp)
  pp.object_group self do
    pp.breakable
    pp.text "name=#{name}"
  end
end

#propertiesHash<Symbol,Object> Also known as: props

Get the properties of this bucket type

Returns:



41
42
43
44
45
# File 'lib/riak/bucket_type.rb', line 41

def properties
  @properties ||= client.backend do |be|
    be.get_bucket_type_props name
  end
end