Module: Gcloud::Datastore::Proto
- Defined in:
- lib/gcloud/datastore/proto.rb,
lib/gcloud/proto/datastore_v1.pb.rb
Overview
Proto is the namespace that contains all Protocol Buffer objects.
The methods in this module are for convenience in using the Protocol Buffer objects and as such can change in the future. Neither the convenience methods nor the Protocol Buffer objects are not part of the gcloud public API. These methods, and even this module’s existance, may change in the future.
You have been warned.
Defined Under Namespace
Classes: AllocateIdsRequest, AllocateIdsResponse, BeginTransactionRequest, BeginTransactionResponse, CommitRequest, CommitResponse, CompositeFilter, Entity, EntityResult, Filter, GqlQuery, GqlQueryArg, Key, KindExpression, LookupRequest, LookupResponse, Mutation, MutationResult, PartitionId, Property, PropertyExpression, PropertyFilter, PropertyOrder, PropertyReference, Query, QueryResultBatch, ReadOptions, RollbackRequest, RollbackResponse, RunQueryRequest, RunQueryResponse, Value
Constant Summary
collapse
- PROP_FILTER_OPS =
{
"<" => PropertyFilter::Operator::LESS_THAN,
"lt" => PropertyFilter::Operator::LESS_THAN,
"<=" => PropertyFilter::Operator::LESS_THAN_OR_EQUAL,
"lte" => PropertyFilter::Operator::LESS_THAN_OR_EQUAL,
">" => PropertyFilter::Operator::GREATER_THAN,
"gt" => PropertyFilter::Operator::GREATER_THAN,
">=" => PropertyFilter::Operator::GREATER_THAN_OR_EQUAL,
"gte" => PropertyFilter::Operator::GREATER_THAN_OR_EQUAL,
"=" => PropertyFilter::Operator::EQUAL,
"eq" => PropertyFilter::Operator::EQUAL,
"eql" => PropertyFilter::Operator::EQUAL,
"~" => PropertyFilter::Operator::HAS_ANCESTOR,
"~>" => PropertyFilter::Operator::HAS_ANCESTOR,
"ancestor" => PropertyFilter::Operator::HAS_ANCESTOR,
"has_ancestor" => PropertyFilter::Operator::HAS_ANCESTOR,
"has ancestor" => PropertyFilter::Operator::HAS_ANCESTOR }
Class Method Summary
collapse
Class Method Details
.decode_cursor(cursor) ⇒ Object
150
151
152
153
154
|
# File 'lib/gcloud/datastore/proto.rb', line 150
def self.decode_cursor cursor
dc = cursor.to_s.unpack("m").first.force_encoding Encoding::ASCII_8BIT
dc = nil if dc.empty?
dc
end
|
.encode_cursor(cursor) ⇒ Object
146
147
148
|
# File 'lib/gcloud/datastore/proto.rb', line 146
def self.encode_cursor cursor
Array(cursor.to_s).pack("m").chomp
end
|
.from_proto_properties(proto_properties) ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/gcloud/datastore/proto.rb', line 89
def self.from_proto_properties proto_properties
hash_properties = {}
Array(proto_properties).each do |p|
hash_properties[p.name] = Proto.from_proto_value p.value
end
hash_properties
end
|
.from_proto_value(proto_value) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/gcloud/datastore/proto.rb', line 34
def self.from_proto_value proto_value
if !proto_value.timestamp_microseconds_value.nil?
microseconds = proto_value.timestamp_microseconds_value
self.time_from_microseconds microseconds
elsif !proto_value.key_value.nil?
Gcloud::Datastore::Key.from_proto(proto_value.key_value)
elsif !proto_value.entity_value.nil?
Gcloud::Datastore::Entity.from_proto(proto_value.entity_value)
elsif !proto_value.boolean_value.nil?
proto_value.boolean_value
elsif !proto_value.double_value.nil?
proto_value.double_value
elsif !proto_value.integer_value.nil?
proto_value.integer_value
elsif !proto_value.string_value.nil?
return proto_value.string_value
elsif !proto_value.list_value.nil?
return Array(proto_value.list_value).map do |item|
from_proto_value item
end
else
nil
end
end
|
.microseconds_from_time(time) ⇒ Object
106
107
108
|
# File 'lib/gcloud/datastore/proto.rb', line 106
def self.microseconds_from_time time
(time.utc.to_f * 1000000).to_i
end
|
.new_composite_filter ⇒ Object
.new_filter ⇒ Object
Convenience methods to create protocol buffer objects
171
172
173
|
# File 'lib/gcloud/datastore/proto.rb', line 171
def self.new_filter
Filter.new
end
|
.new_mutation ⇒ Object
182
183
184
185
186
187
188
189
190
|
# File 'lib/gcloud/datastore/proto.rb', line 182
def self.new_mutation
Mutation.new.tap do |m|
m.upsert = []
m.update = []
m.insert = []
m.insert_auto_id = []
m.delete = []
end
end
|
.new_partition_id(new_dataset_id, new_namespace) ⇒ Object
235
236
237
238
239
240
|
# File 'lib/gcloud/datastore/proto.rb', line 235
def self.new_partition_id new_dataset_id, new_namespace
PartitionId.new.tap do |pi|
pi.dataset_id = new_dataset_id
pi.namespace = new_namespace
end
end
|
.new_path_element(new_kind, new_id_or_name) ⇒ Object
224
225
226
227
228
229
230
231
232
233
|
# File 'lib/gcloud/datastore/proto.rb', line 224
def self.new_path_element new_kind, new_id_or_name
Key::PathElement.new.tap do |pe|
pe.kind = new_kind
if new_id_or_name.is_a? Integer
pe.id = new_id_or_name
else
pe.name = new_id_or_name
end
end
end
|
.new_property_expression(name) ⇒ Object
206
207
208
209
210
|
# File 'lib/gcloud/datastore/proto.rb', line 206
def self.new_property_expression name
PropertyExpression.new.tap do |pe|
pe.property = new_property_reference name
end
end
|
.new_property_expressions(*names) ⇒ Object
200
201
202
203
204
|
# File 'lib/gcloud/datastore/proto.rb', line 200
def self.new_property_expressions *names
names.map do |name|
new_property_expression name
end
end
|
.new_property_filter(name, operator, value) ⇒ Object
192
193
194
195
196
197
198
|
# File 'lib/gcloud/datastore/proto.rb', line 192
def self.new_property_filter name, operator, value
PropertyFilter.new.tap do |pf|
pf.property = new_property_reference name
pf.operator = Proto.to_prop_filter_op operator
pf.value = Proto.to_proto_value value
end
end
|
.new_property_reference(name) ⇒ Object
218
219
220
221
222
|
# File 'lib/gcloud/datastore/proto.rb', line 218
def self.new_property_reference name
PropertyReference.new.tap do |pr|
pr.name = name
end
end
|
.new_property_references(*names) ⇒ Object
212
213
214
215
216
|
# File 'lib/gcloud/datastore/proto.rb', line 212
def self.new_property_references *names
names.map do |name|
new_property_reference name
end
end
|
.new_run_query_request(query_proto) ⇒ Object
242
243
244
245
246
|
# File 'lib/gcloud/datastore/proto.rb', line 242
def self.new_run_query_request query_proto
RunQueryRequest.new.tap do |rq|
rq.query = query_proto
end
end
|
.time_from_microseconds(microseconds) ⇒ Object
110
111
112
|
# File 'lib/gcloud/datastore/proto.rb', line 110
def self.time_from_microseconds microseconds
Time.at(microseconds / 1000000, microseconds % 1000000).utc
end
|
.to_more_results_string(more_results) ⇒ Object
.to_prop_filter_op(str) ⇒ Object
.to_prop_order_direction(direction) ⇒ Object
.to_proto_properties(hash_properties) ⇒ Object
97
98
99
100
101
102
103
104
|
# File 'lib/gcloud/datastore/proto.rb', line 97
def self.to_proto_properties hash_properties
hash_properties.map do |name, value|
Proto::Property.new.tap do |p|
p.name = name.to_s
p.value = Proto.to_proto_value value
end
end
end
|
.to_proto_value(value) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/gcloud/datastore/proto.rb', line 59
def self.to_proto_value value
v = Gcloud::Datastore::Proto::Value.new
if Time === value
v.timestamp_microseconds_value = self.microseconds_from_time value
elsif Gcloud::Datastore::Key === value
v.key_value = value.to_proto
elsif Gcloud::Datastore::Entity === value
v.entity_value = value.to_proto
elsif NilClass === value
elsif TrueClass === value
v.boolean_value = true
elsif FalseClass === value
v.boolean_value = false
elsif Float === value
v.double_value = value
elsif defined?(BigDecimal) && BigDecimal === value
v.double_value = value
elsif Integer === value
v.integer_value = value
elsif String === value
v.string_value = value
elsif Array === value
v.list_value = value.map { |item| to_proto_value item }
else
fail PropertyError, "A property of type #{value.class} is not supported."
end
v
end
|