diff --git a/.gitignore b/.gitignore index 5e1422c..32541f9 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,6 @@ build-iPhoneSimulator/ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc + +# rubocop +.rubocop-https---raw-githubusercontent-com-Invoca-style-guide-master-ruby--rubocop-yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..10f1bf0 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,5 @@ +# This rubocop config file inherits from our centralized style-guide repository. +# If you are looking to update the ruby style guide, be sure to both update the rubocop config +# as well as the README.md +# https://github.com/Invoca/style-guide/tree/master/ruby +inherit_from: https://raw.githubusercontent.com/Invoca/style-guide/master/ruby/.rubocop.yml diff --git a/Gemfile b/Gemfile index d56157a..3f8ee52 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'http://rubygems.org' gemspec diff --git a/contextual_logger.gemspec b/contextual_logger.gemspec index e873c7a..19699d8 100644 --- a/contextual_logger.gemspec +++ b/contextual_logger.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Gem::Specification.new do |spec| spec.name = 'contextual_logger' spec.version = '0.1.0' diff --git a/lib/contextual_logger.rb b/lib/contextual_logger.rb index f84df0e..c44069f 100644 --- a/lib/contextual_logger.rb +++ b/lib/contextual_logger.rb @@ -1,4 +1,4 @@ -# frozen_string literal: true +# frozen_string_literal: true require 'json' @@ -59,7 +59,7 @@ def unknown(progname = nil, **extra_context, &block) def add(severity, message = nil, progname = nil, extra_context = nil) severity ||= UNKNOWN - if @logdev.nil? or severity < @level + if @logdev.nil? || (severity < @level) return true end progname ||= @progname @@ -79,7 +79,6 @@ def write_entry_to_log(severity, timestamp, progname, message, context) @logdev.write(format_message(format_severity(severity), timestamp, progname, message, context)) end - private THREAD_CONTEXT_NAMESPACE = 'ContextualLoggerCurrentLoggingContext' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 44a658f..cfc702c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,17 +15,15 @@ class Time class << self - def now_override= override_time - @@now_override = override_time - end + attr_writer :now_override def now_override - @@now_override ||= nil + @now_override ||= nil end - unless defined? @@_old_now_defined + unless defined? @_old_now_defined alias old_now now - @@_old_now_defined = true + @_old_now_defined = true end end