Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

Commit

Permalink
Update Stackdriver Logging code style
Browse files Browse the repository at this point in the history
Changes needed to adhere to updated style guide in latest Rubocop.
  • Loading branch information
blowmage committed Jan 11, 2018
1 parent 5e0c2d2 commit 135de4a
Show file tree
Hide file tree
Showing 20 changed files with 120 additions and 120 deletions.
31 changes: 12 additions & 19 deletions google-cloud-logging/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,26 @@ Style/MethodDefParentheses:
EnforcedStyle: require_no_parentheses
Style/NumericLiterals:
Enabled: false
Style/SpaceAroundOperators:
Enabled: false
Metrics/ClassLength:
Enabled: false
Style/EmptyLines:
Enabled: false
Style/EmptyElse:
Enabled: false
Style/CaseEquality:
Exclude:
- "lib/google/cloud/logging/middleware.rb"
Metrics/CyclomaticComplexity:
Max: 12
Metrics/PerceivedComplexity:
Max: 12
Metrics/AbcSize:
Max: 28
Metrics/ClassLength:
Enabled: false
Metrics/MethodLength:
Max: 22
Max: 25
Metrics/ParameterLists:
Enabled: false
Style/RescueModifier:
Enabled: false
Style/ClassVars:
Layout/EmptyLines: # for the extra line between copyright and code
Enabled: false
Style/TrivialAccessors:
Enabled: false
Style/CaseEquality:
Enabled: false
Style/FileName:
Enabled: false # for lib/google-cloud-logging.rb file
Naming/FileName:
Exclude:
- "lib/google-cloud-logging.rb"
Lint/RescueException:
Enabled: false # for lib/google/cloud/logging/rails.rb file
Exclude:
- "lib/google/cloud/logging/rails.rb"
22 changes: 8 additions & 14 deletions google-cloud-logging/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@ source "https://rubygems.org"

gemspec

gem "rake", "~> 11.0"
gem "google-cloud-core", path: "../google-cloud-core"
gem "google-cloud-env", path: "../google-cloud-env"
gem "google-cloud-storage", path: "../google-cloud-storage"
gem "stackdriver-core", path: "../stackdriver-core"
gem "gcloud-jsondoc",
git: "https://github.com/GoogleCloudPlatform/google-cloud-ruby.git",
branch: "gcloud-jsondoc"

# WORKAROUND: builds are having problems since the release of 3.0.0
# pin to the last known good version
gem "public_suffix", "~> 2.0"

# TEMP: rainbow (a dependency of rubocop) version 2.2 seems to have a problem,
# so pinning to 2.1 for now.
gem "rainbow", "~> 2.1.0"

gem "google-cloud-core", path: "../google-cloud-core"
gem "google-cloud-env", path: "../google-cloud-env"
gem "google-cloud-storage", path: "../google-cloud-storage"
# TEMP: nokogiri (a dependency of rails) 1.7 requires Ruby 2.1 or later.
# Since we're still testing on Ruby 2.0, pin nokogiri to 1.6 for now.
gem "nokogiri", "~> 1.6.8"
# WORKAROUND: builds are having problems since the release of 3.0.0
# pin to the last known good version
gem "public_suffix", "~> 2.0"
gem "rake", "~> 11.0"
gem "stackdriver-core", path: "../stackdriver-core"
6 changes: 4 additions & 2 deletions google-cloud-logging/lib/google/cloud/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
client_config: nil, project: nil, keyfile: nil
project_id ||= (project || Logging::Project.default_project_id)
project_id = project_id.to_s # Always cast to a string
fail ArgumentError, "project_id is missing" if project_id.empty?
raise ArgumentError, "project_id is missing" if project_id.empty?

credentials ||= (keyfile || Logging::Credentials.default(scope: scope))
unless credentials.is_a? Google::Auth::Credentials
Expand All @@ -409,7 +409,9 @@ def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
Logging::Project.new(
Logging::Service.new(
project_id, credentials, timeout: timeout,
client_config: client_config))
client_config: client_config
)
)
end

##
Expand Down
22 changes: 11 additions & 11 deletions google-cloud-logging/lib/google/cloud/logging/async_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def try_combine next_item
# The current state. Either :running, :suspended, :stopping, or :stopped
#
# DEPRECATED. Use #async_state instead.
alias_method :state, :async_state
alias state async_state

##
# The last exception thrown by the background thread, or nil if nothing
Expand Down Expand Up @@ -152,7 +152,7 @@ def write_entries entries, log_name: nil, resource: nil, labels: nil
ensure_thread
entries = Array(entries)
synchronize do
fail "AsyncWriter has been stopped" unless writable?
raise "AsyncWriter has been stopped" unless writable?
queue_item = QueueItem.new entries, log_name, resource, labels
if @queue.empty? || !@queue.last.try_combine(queue_item)
@queue.push queue_item
Expand Down Expand Up @@ -213,7 +213,7 @@ def logger log_name, resource, labels = {}
# @return [Boolean] Returns true if the writer was running, or false
# if the writer had already been stopped.
#
alias_method :stop, :async_stop
alias stop async_stop

##
# Suspends this asynchronous writer.
Expand All @@ -226,7 +226,7 @@ def logger log_name, resource, labels = {}
# @return [Boolean] Returns true if the writer had been running and was
# suspended, otherwise false.
#
alias_method :suspend, :async_suspend
alias suspend async_suspend

##
# Resumes this suspended asynchronous writer.
Expand All @@ -239,7 +239,7 @@ def logger log_name, resource, labels = {}
# @return [Boolean] Returns true if the writer had been suspended and
# is now running, otherwise false.
#
alias_method :resume, :async_resume
alias resume async_resume

##
# Returns true if this writer is running.
Expand All @@ -248,7 +248,7 @@ def logger log_name, resource, labels = {}
#
# @return [Boolean] Returns true if the writer is currently running.
#
alias_method :running?, :async_running?
alias running? async_running?

##
# Returns true if this writer is suspended.
Expand All @@ -257,7 +257,7 @@ def logger log_name, resource, labels = {}
#
# @return [Boolean] Returns true if the writer is currently suspended.
#
alias_method :suspended?, :async_suspended?
alias suspended? async_suspended?

##
# Returns true if this writer is still accepting writes. This means
Expand All @@ -267,7 +267,7 @@ def logger log_name, resource, labels = {}
#
# @return [Boolean] Returns true if the writer is accepting writes.
#
alias_method :writable?, :async_working?
alias writable? async_working?

##
# Returns true if this writer is fully stopped.
Expand All @@ -276,7 +276,7 @@ def logger log_name, resource, labels = {}
#
# @return [Boolean] Returns true if the writer is fully stopped.
#
alias_method :stopped?, :async_stopped?
alias stopped? async_stopped?

##
# Blocks until this asynchronous writer has been stopped, or the given
Expand All @@ -290,7 +290,7 @@ def logger log_name, resource, labels = {}
# @return [Boolean] Returns true if the writer is stopped, or false
# if the timeout expired.
#
alias_method :wait_until_stopped, :wait_until_async_stopped
alias wait_until_stopped wait_until_async_stopped

##
# Stop this asynchronous writer and block until it has been stopped.
Expand Down Expand Up @@ -340,7 +340,7 @@ def run_backgrounder
labels: queue_item.labels,
partial_success: @partial_success
)
rescue => e
rescue StandardError => e
# Ignore any exceptions thrown from the background thread, but
# keep running to ensure its state behavior remains consistent.
@last_exception = e
Expand Down
12 changes: 6 additions & 6 deletions google-cloud-logging/lib/google/cloud/logging/credentials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ module Logging
# logging.project_id #=> "my-project"
#
class Credentials < Google::Auth::Credentials
SCOPE = ["https://www.googleapis.com/auth/logging.admin"]
PATH_ENV_VARS = %w(LOGGING_CREDENTIALS
SCOPE = ["https://www.googleapis.com/auth/logging.admin"].freeze
PATH_ENV_VARS = %w[LOGGING_CREDENTIALS
LOGGING_KEYFILE
GOOGLE_CLOUD_CREDENTIALS
GOOGLE_CLOUD_KEYFILE
GCLOUD_KEYFILE)
JSON_ENV_VARS = %w(LOGGING_CREDENTIALS_JSON
GCLOUD_KEYFILE].freeze
JSON_ENV_VARS = %w[LOGGING_CREDENTIALS_JSON
LOGGING_KEYFILE_JSON
GOOGLE_CLOUD_CREDENTIALS_JSON
GOOGLE_CLOUD_KEYFILE_JSON
GCLOUD_KEYFILE_JSON)
GCLOUD_KEYFILE_JSON].freeze
DEFAULT_PATHS = \
["~/.config/gcloud/application_default_credentials.json"]
["~/.config/gcloud/application_default_credentials.json"].freeze
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class Entry
class HttpRequest
##
# @private Create an empty HttpRequest object.
def initialize
end
def initialize; end

##
# The request method. Examples: `"GET"`, `"HEAD"`, `"PUT"`, `"POST"`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def self.from_grpc grpc_list, service, resources: nil, filter: nil,
# @private Raise an error unless an active connection to the service
# is available.
def ensure_service!
fail "Must have active connection to service" unless @service
raise "Must have active connection to service" unless @service
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class Entry
class Operation
##
# @private Create an empty Operation object.
def initialize
end
def initialize; end

##
# An arbitrary operation identifier. Log entries with the same
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class Entry
class SourceLocation
##
# @private Create an empty SourceLocation object.
def initialize
end
def initialize; end

##
# Source file name. Depending on the runtime environment, this might
Expand Down
2 changes: 1 addition & 1 deletion google-cloud-logging/lib/google/cloud/logging/log/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def self.from_grpc grpc_list, service, resource: nil, max: nil
# @private Raise an error unless an active connection to the service
# is available.
def ensure_service!
fail "Must have active connection to service" unless @service
raise "Must have active connection to service" unless @service
end
end
end
Expand Down
23 changes: 12 additions & 11 deletions google-cloud-logging/lib/google/cloud/logging/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Logger
##
# The Google Cloud log_name to write the log entry with.
attr_reader :log_name
alias_method :progname, :log_name
alias progname log_name

##
# The Google Cloud resource to write the log entry with.
Expand All @@ -84,8 +84,8 @@ class Logger
##
# The logging severity threshold (e.g. `Logger::INFO`)
attr_reader :level
alias_method :sev_threshold, :level
alias_method :local_level, :level
alias sev_threshold level
alias local_level level

##
# Boolean flag that indicates whether this logger can be silenced or
Expand Down Expand Up @@ -317,7 +317,7 @@ def add severity, message = nil, progname = nil
write_entry severity, message unless @closed
true
end
alias_method :log, :add
alias log add

##
# Logs the given message at UNKNOWN severity.
Expand Down Expand Up @@ -393,11 +393,13 @@ def unknown?
#
def level= severity
new_level = derive_severity severity
fail ArgumentError, "invalid log level: #{severity}" if new_level.nil?
if new_level.nil?
raise ArgumentError, "invalid log level: #{severity}"
end
@level = new_level
end
alias_method :sev_threshold=, :level=
alias_method :local_level=, :level=
alias sev_threshold= level=
alias local_level= level=

##
# Close the logging "device". This effectively disables logging from
Expand Down Expand Up @@ -482,7 +484,7 @@ def delete_request_info

##
# @deprecated Use delete_request_info
alias_method :delete_trace_id, :delete_request_info
alias delete_trace_id delete_request_info

##
# No-op method. Created to match the spec of ActiveSupport::Logger#flush
Expand Down Expand Up @@ -584,15 +586,14 @@ def derive_severity severity
when "error".freeze then ::Logger::ERROR
when "fatal".freeze then ::Logger::FATAL
when "unknown".freeze then ::Logger::UNKNOWN
else nil
end
end

##
# @private Get Google Cloud deverity from logger level number.
def gcloud_severity severity_int
%i(DEBUG INFO WARNING ERROR CRITICAL DEFAULT)[severity_int]
rescue
%i[DEBUG INFO WARNING ERROR CRITICAL DEFAULT][severity_int]
rescue StandardError
:DEFAULT
end

Expand Down
4 changes: 2 additions & 2 deletions google-cloud-logging/lib/google/cloud/logging/metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def reload!
@grpc = service.get_metric name
true
end
alias_method :refresh!, :reload!
alias refresh! reload!

##
# Permanently deletes the logs-based metric.
Expand Down Expand Up @@ -160,7 +160,7 @@ def self.from_grpc grpc, service
# @private Raise an error unless an active connection to the service is
# available.
def ensure_service!
fail "Must have active connection to service" unless service
raise "Must have active connection to service" unless service
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def self.from_grpc grpc_list, service, max = nil
# @private Raise an error unless an active connection to the service
# is available.
def ensure_service!
fail "Must have active connection to service" unless @service
raise "Must have active connection to service" unless @service
end
end
end
Expand Down
Loading

0 comments on commit 135de4a

Please sign in to comment.