lib/google/cloud/datastore.rb in google-cloud-datastore-1.4.4 vs lib/google/cloud/datastore.rb in google-cloud-datastore-1.5.0

- old
+ new

@@ -44,10 +44,11 @@ # task = datastore.find "Task", "sampleTask" # task["priority"] = 5 # datastore.save task # module Datastore + # rubocop:disable Metrics/AbcSize # rubocop:disable Metrics/MethodLength ## # Creates a new object for connecting to the Datastore service. # Each call creates a new connection. @@ -97,19 +98,20 @@ # datastore.save task # def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil, emulator_host: nil, project: nil, keyfile: nil - project_id ||= (project || default_project_id) - project_id = project_id.to_s # Always cast to a string - raise ArgumentError, "project_id is missing" if project_id.empty? - - scope ||= configure.scope - timeout ||= configure.timeout + project_id ||= (project || default_project_id) + scope ||= configure.scope + timeout ||= configure.timeout client_config ||= configure.client_config emulator_host ||= configure.emulator_host + 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, host: emulator_host, timeout: timeout, client_config: client_config @@ -120,17 +122,24 @@ credentials ||= (keyfile || default_credentials(scope: scope)) unless credentials.is_a? Google::Auth::Credentials credentials = Datastore::Credentials.new credentials, scope: scope end + if credentials.respond_to? :project_id + project_id ||= credentials.project_id + end + 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, timeout: timeout, client_config: client_config ) ) end + # rubocop:enable Metrics/AbcSize # rubocop:enable Metrics/MethodLength ## # Configure the Google Cloud Datastore library. #