Class: Google::Cloud::Datastore::Key
- Inherits:
-
Object
- Object
- Google::Cloud::Datastore::Key
- Defined in:
- lib/google/cloud/datastore/key.rb
Overview
Key
Every Datastore record has an identifying key, which includes the record's entity kind and a unique identifier. The identifier may be either a key name string, assigned explicitly by the application, or an integer numeric ID, assigned automatically by Datastore.
Instance Attribute Summary collapse
-
#database ⇒ String
(also: #database_id)
The database of the Key.
-
#id ⇒ Integer?
readonly
The id of the Key.
-
#kind ⇒ String
The kind of the Key.
-
#name ⇒ String?
readonly
The name of the Key.
-
#namespace ⇒ String?
The namespace of the Key.
-
#parent ⇒ Key?
The parent of the Key.
-
#project ⇒ String
(also: #project_id, #dataset_id)
The project of the Key.
Instance Method Summary collapse
-
#complete? ⇒ Boolean
Determine if the key is complete.
-
#incomplete? ⇒ Boolean
Determine if the key is incomplete.
-
#initialize(kind = nil, id_or_name = nil) ⇒ Google::Cloud::Datastore::Dataset::Key
constructor
Create a new Key instance.
-
#path ⇒ Array<Array<(String, String)>>
Represent the Key's path (including parent) as an array of arrays.
-
#serialized_size ⇒ Object
The number of bytes the Key will take to serialize during API calls.
Constructor Details
#initialize(kind = nil, id_or_name = nil) ⇒ Google::Cloud::Datastore::Dataset::Key
Create a new Key instance.
125 126 127 128 129 130 131 132 |
# File 'lib/google/cloud/datastore/key.rb', line 125 def initialize kind = nil, id_or_name = nil @kind = kind if id_or_name.is_a? Integer @id = id_or_name else @name = id_or_name end end |
Instance Attribute Details
#database ⇒ String Also known as: database_id
The database of the Key.
89 90 91 |
# File 'lib/google/cloud/datastore/key.rb', line 89 def database @database end |
#id ⇒ Integer?
The id of the Key.
166 167 168 |
# File 'lib/google/cloud/datastore/key.rb', line 166 def id @id end |
#kind ⇒ String
The kind of the Key.
48 49 50 |
# File 'lib/google/cloud/datastore/key.rb', line 48 def kind @kind end |
#name ⇒ String?
The name of the Key.
200 201 202 |
# File 'lib/google/cloud/datastore/key.rb', line 200 def name @name end |
#namespace ⇒ String?
The namespace of the Key.
109 110 111 |
# File 'lib/google/cloud/datastore/key.rb', line 109 def namespace @namespace end |
#parent ⇒ Key?
The parent of the Key.
245 246 247 |
# File 'lib/google/cloud/datastore/key.rb', line 245 def parent @parent end |
#project ⇒ String Also known as: project_id, dataset_id
The project of the Key.
66 67 68 |
# File 'lib/google/cloud/datastore/key.rb', line 66 def project @project end |
Instance Method Details
#complete? ⇒ Boolean
Determine if the key is complete. A complete key has either an id or a name.
Inverse of #incomplete?
272 273 274 |
# File 'lib/google/cloud/datastore/key.rb', line 272 def complete? !incomplete? end |
#incomplete? ⇒ Boolean
Determine if the key is incomplete. An incomplete key has neither an id nor a name.
Inverse of #complete?
281 282 283 |
# File 'lib/google/cloud/datastore/key.rb', line 281 def incomplete? kind.nil? || (id.nil? && (name.nil? || name.empty?)) end |
#path ⇒ Array<Array<(String, String)>>
Represent the Key's path (including parent) as an array of arrays. Each inner array contains two values, the kind and the id or name. If neither an id or name exist then nil will be returned.
262 263 264 265 |
# File 'lib/google/cloud/datastore/key.rb', line 262 def path new_path = parent ? parent.path : [] new_path << [kind, id || name] end |
#serialized_size ⇒ Object
The number of bytes the Key will take to serialize during API calls.
287 288 289 |
# File 'lib/google/cloud/datastore/key.rb', line 287 def serialized_size to_grpc.to_proto.length end |