lib/google/cloud/datastore.rb in google-cloud-datastore-2.4.0 vs lib/google/cloud/datastore.rb in google-cloud-datastore-2.5.0
- old
+ new
@@ -72,10 +72,12 @@
# @param [Integer] timeout Default timeout to use in requests. Optional.
# @param [String] endpoint Override of the endpoint host name. Optional.
# If the param is nil, uses the default endpoint.
# @param [String] emulator_host Datastore emulator host. Optional.
# If the param is nil, uses the value of the `emulator_host` config.
+ # @param [String] database_id Identifier for a Datastore database in the project. If not
+ # present, the default database of the project will be used.
# @param [String] project Alias for the `project_id` argument. Deprecated.
# @param [String] keyfile Alias for the `credentials` argument.
# Deprecated.
#
# @return [Google::Cloud::Datastore::Dataset]
@@ -101,25 +103,27 @@
credentials: nil,
scope: nil,
timeout: nil,
endpoint: nil,
emulator_host: nil,
+ database_id: nil,
project: nil,
keyfile: nil
- project_id ||= (project || default_project_id)
- scope ||= configure.scope
- timeout ||= configure.timeout
- endpoint ||= configure.endpoint
+ project_id = get_project_id project_id, project
+ scope ||= configure.scope
+ timeout ||= configure.timeout
+ endpoint ||= configure.endpoint
emulator_host ||= configure.emulator_host
+ database_id ||= configure.database_id
if emulator_host
project_id = project_id.to_s # Always cast to a string
raise ArgumentError, "project_id is missing" if project_id.empty?
return Datastore::Dataset.new(
Datastore::Service.new(
- project_id, :this_channel_is_insecure,
+ project_id, :this_channel_is_insecure, database_id,
host: emulator_host, timeout: timeout
)
)
end
@@ -134,11 +138,11 @@
project_id = project_id.to_s # Always cast to a string
raise ArgumentError, "project_id is missing" if project_id.empty?
Datastore::Dataset.new(
Datastore::Service.new(
- project_id, credentials,
+ project_id, credentials, database_id,
host: endpoint, timeout: timeout
)
)
end
@@ -171,9 +175,17 @@
#
def self.configure
yield Google::Cloud.configure.datastore if block_given?
Google::Cloud.configure.datastore
+ end
+
+ ##
+ # @private Default project.
+ def self.get_project_id project_id, project
+ project_id || project || Google::Cloud.configure.datastore.project_id ||
+ Google::Cloud.configure.project_id ||
+ Google::Cloud.env.project_id
end
##
# @private Default project.
def self.default_project_id