Class: Google::Cloud::Bigtable::ColumnFamilyMap
- Inherits:
-
Object
- Object
- Google::Cloud::Bigtable::ColumnFamilyMap
- Includes:
- Enumerable
- Defined in:
- lib/google/cloud/bigtable/column_family_map.rb
Overview
Represents a table's column families.
See Project#create_table, Instance#create_table and Table#column_families.
Instance Method Summary collapse
-
#[](name) ⇒ ColumnFamily
Retrieves the ColumnFamily object corresponding to the
name
. -
#add(name, gc_rule: nil) ⇒ Object
(also: #create)
Adds a new column family to the table.
-
#delete(name) ⇒ Object
(also: #drop)
Deletes the named column family from the table.
-
#each {|name, column_family| ... } ⇒ Enumerator?
Calls the block once for each column family in the map, passing the name and column family pair as parameters.
-
#empty? ⇒ Boolean
Returns true if the map contains no name and column family pairs.
-
#initialize {|_self| ... } ⇒ ColumnFamilyMap
constructor
Creates a new ColumnFamilyMap object.
-
#length ⇒ Integer
(also: #size)
Returns the number of name and column family pairs in the map.
-
#name?(name) ⇒ Boolean
(also: #key?)
Returns true if the given name is present in the map.
-
#names ⇒ Array<String>
(also: #keys)
Returns a new array populated with the names from the map.
-
#update(name, gc_rule: nil) ⇒ Object
Updates an existing column family in the table.
Constructor Details
#initialize {|_self| ... } ⇒ ColumnFamilyMap
Creates a new ColumnFamilyMap object.
104 105 106 107 108 |
# File 'lib/google/cloud/bigtable/column_family_map.rb', line 104 def initialize @column_families = empty_map yield self if block_given? end |
Instance Method Details
#[](name) ⇒ ColumnFamily
Retrieves the ColumnFamily object corresponding to the name
. If not
found, returns nil
.
137 138 139 140 141 |
# File 'lib/google/cloud/bigtable/column_family_map.rb', line 137 def [] name return nil unless name? name ColumnFamily.from_grpc @column_families[name], name end |
#add(name, gc_rule: nil) ⇒ Object Also known as: create
Adds a new column family to the table.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/google/cloud/bigtable/column_family_map.rb', line 206 def add name, positional_gc_rule = nil, gc_rule: nil raise ArgumentError, "column family #{name.inspect} already exists" if @column_families.has_key? name gc_rule ||= positional_gc_rule if positional_gc_rule warn "The positional gc_rule argument is deprecated. Use the named gc_rule argument instead." end column_family = Google::Bigtable::Admin::V2::ColumnFamily.new column_family.gc_rule = gc_rule.to_grpc if gc_rule @column_families[name] = column_family nil end |
#delete(name) ⇒ Object Also known as: drop
Deletes the named column family from the table.
277 278 279 280 281 282 283 |
# File 'lib/google/cloud/bigtable/column_family_map.rb', line 277 def delete name raise ArgumentError, "column family #{name.inspect} does not exist" unless @column_families.has_key? name @column_families.delete name nil end |
#each {|name, column_family| ... } ⇒ Enumerator?
Calls the block once for each column family in the map, passing the name and column family pair as parameters.
If no block is given, an enumerator is returned instead.
122 123 124 125 126 127 128 129 |
# File 'lib/google/cloud/bigtable/column_family_map.rb', line 122 def each return enum_for :each unless block_given? @column_families.each do |name, column_family_grpc| column_family = ColumnFamily.from_grpc column_family_grpc, name yield name, column_family end end |
#empty? ⇒ Boolean
Returns true if the map contains no name and column family pairs.
178 179 180 |
# File 'lib/google/cloud/bigtable/column_family_map.rb', line 178 def empty? length.zero? end |
#length ⇒ Integer Also known as: size
Returns the number of name and column family pairs in the map.
168 169 170 |
# File 'lib/google/cloud/bigtable/column_family_map.rb', line 168 def length @column_families.length end |
#name?(name) ⇒ Boolean Also known as: key?
Returns true if the given name is present in the map.
148 149 150 |
# File 'lib/google/cloud/bigtable/column_family_map.rb', line 148 def name? name @column_families.has_key? name end |
#names ⇒ Array<String> Also known as: keys
Returns a new array populated with the names from the map.
158 159 160 |
# File 'lib/google/cloud/bigtable/column_family_map.rb', line 158 def names @column_families.keys end |
#update(name, gc_rule: nil) ⇒ Object
Updates an existing column family in the table.
248 249 250 251 252 253 254 255 256 |
# File 'lib/google/cloud/bigtable/column_family_map.rb', line 248 def update name, gc_rule: nil raise ArgumentError, "column family #{name.inspect} does not exist" unless @column_families.has_key? name column_family = Google::Bigtable::Admin::V2::ColumnFamily.new column_family.gc_rule = gc_rule.to_grpc if gc_rule @column_families[name] = column_family nil end |