Class: Riak::BucketType

Inherits:
Object show all
Includes:
Util::String
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

Methods included from Util::String

equal_bytes?

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



18
19
20
# File 'lib/riak/bucket_type.rb', line 18

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



10
11
12
# File 'lib/riak/bucket_type.rb', line 10

def client
  @client
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/riak/bucket_type.rb', line 10

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



73
74
75
76
77
# File 'lib/riak/bucket_type.rb', line 73

def ==(other)
  return false unless self.class == other.class
  return false unless self.client == other.client
  return equal_bytes?(self.name, other.name)
end

#bucket(bucket_name) ⇒ Object

Get a bucket of this type

Parameters:

  • bucket_name (String)

    the name of this bucket



30
31
32
# File 'lib/riak/bucket_type.rb', line 30

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:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/riak/bucket_type.rb', line 58

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)


24
25
26
# File 'lib/riak/bucket_type.rb', line 24

def default?
  name == DEFAULT_NAME
end

#pretty_print(pp) ⇒ Object

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



35
36
37
38
39
40
# File 'lib/riak/bucket_type.rb', line 35

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:



44
45
46
47
48
# File 'lib/riak/bucket_type.rb', line 44

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