loga 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: feb7e0fc4418e6763bb4cbe7cd0a381e8f0edf09
4
- data.tar.gz: 7ee939ed4ba16283823ca2ca8f77bd9148e145b3
3
+ metadata.gz: a962ebefb507146c9e7e2586efb356fd9615db7d
4
+ data.tar.gz: d1cc277cb5364e6b017d1c2e8f5524da815d9f88
5
5
  SHA512:
6
- metadata.gz: 71a379ec8c9659592d58dc1c0fae6096d00c6ed457368d26013970108ee4957141a5323620d931824768c2304ff04d95a1b707d90e893f3a2c0c3751054cb725
7
- data.tar.gz: 3d71749a93556d196ea112fefa59cf26544a5b883dbda8044238ee759dde6dee71956ff74c4cbf1caaa06a088fd514de7f584ffdef6cc4699e7ae7984e661578
6
+ metadata.gz: cd8aa79bea6fc3f231a11da411e4157ba61b9c7ed26bd016cf6627a211ca74cc46e41577ee1a3480c046323d5cc9a936bcea175c3bdb9f52aef4a8af91bae60b
7
+ data.tar.gz: af8f9e6abb19c279a1b3ca59310e33a0123e6b9e7d618d6a4e8bdca14ba237f2c8f929377d3f95c03157e06add6e0b011ba0bfe111154da2eb4411191c0992c0
@@ -5,6 +5,7 @@ require 'loga/utilities'
5
5
  require 'loga/event'
6
6
  require 'loga/formatter'
7
7
  require 'loga/parameter_filter'
8
+ require 'loga/revision_strategy'
8
9
  require 'loga/rack/logger'
9
10
  require 'loga/rack/request'
10
11
  require 'loga/rack/request_id'
@@ -1,7 +1,5 @@
1
1
  require 'logger'
2
2
  require 'socket'
3
- require 'active_support'
4
- require 'active_support/core_ext/object/blank'
5
3
 
6
4
  module Loga
7
5
  class Configuration
@@ -43,26 +41,8 @@ module Loga
43
41
 
44
42
  private
45
43
 
46
- class GitRevisionStrategy
47
- DEFAULT_REVISION = 'unknown.sha'.freeze
48
-
49
- def self.call
50
- revision = fetch_revision if binary_available?
51
- revision = DEFAULT_REVISION if revision.blank?
52
- revision
53
- end
54
-
55
- def self.binary_available?
56
- system 'which git'
57
- end
58
-
59
- def self.fetch_revision
60
- `git rev-parse HEAD`.strip
61
- end
62
- end
63
-
64
44
  def compute_service_version
65
- service_version == :git ? GitRevisionStrategy.call : service_version.strip
45
+ RevisionStrategy.call(service_version)
66
46
  end
67
47
 
68
48
  def initialize_logger
@@ -0,0 +1,32 @@
1
+ # rubocop:disable Style/SpecialGlobalVars
2
+ require 'active_support/core_ext/object/blank'
3
+
4
+ module Loga
5
+ class RevisionStrategy
6
+ DEFAULT_REVISION = 'unknown.sha'.freeze
7
+
8
+ class << self
9
+ def call(service_version = :git)
10
+ if service_version == :git
11
+ fetch_from_git || read_from_file || DEFAULT_REVISION
12
+ elsif service_version.blank?
13
+ DEFAULT_REVISION
14
+ else
15
+ service_version.strip
16
+ end
17
+ end
18
+
19
+ def fetch_from_git
20
+ sha1_hash = `git rev-parse --short HEAD`
21
+ $?.exitstatus == 0 ? sha1_hash.strip : false
22
+ end
23
+
24
+ def read_from_file
25
+ File.read('REVISION').strip
26
+ rescue Errno::ENOENT
27
+ false
28
+ end
29
+ end
30
+ end
31
+ end
32
+ # rubocop:enable Style/SpecialGlobalVars
@@ -1,3 +1,3 @@
1
1
  module Loga
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -44,14 +44,6 @@ describe Loga::Configuration do
44
44
  subject.initialize!
45
45
  end
46
46
 
47
- context 'when service_version is :git' do
48
- before { subject.service_version = :git }
49
- it 'computes the service_version with git' do
50
- subject.initialize!
51
- expect(subject.service_version).to match(/\h+/)
52
- end
53
- end
54
-
55
47
  describe 'logger' do
56
48
  let(:logdev) { subject.logger.instance_variable_get(:@logdev) }
57
49
 
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Loga::RevisionStrategy do
4
+ describe '.call' do
5
+ it 'uses :git as default argument' do
6
+ expect(Loga::RevisionStrategy.call).to match(/\h+/)
7
+ end
8
+
9
+ it "returns 'unknown.sha' when argument is empty string" do
10
+ expect(Loga::RevisionStrategy.call('')).to eq('unknown.sha')
11
+ end
12
+
13
+ context 'called with :git argument' do
14
+ it 'fetches the service version from git' do
15
+ expect(Loga::RevisionStrategy.call(:git)).to match(/\h+/)
16
+ end
17
+
18
+ it 'reads the REVISION file when no git repo' do
19
+ allow(Loga::RevisionStrategy).to receive(:fetch_from_git) { false }
20
+ expect(File).to receive(:read).with('REVISION').and_return('sha1_hash')
21
+ expect(Loga::RevisionStrategy.call(:git)).to eq('sha1_hash')
22
+ end
23
+
24
+ it "returns 'unknown.sha' otherwise" do
25
+ allow(Loga::RevisionStrategy).to receive(:fetch_from_git) { false }
26
+ allow(Loga::RevisionStrategy).to receive(:read_from_file) { false }
27
+ expect(Loga::RevisionStrategy.call(:git)).to eq('unknown.sha')
28
+ end
29
+ end
30
+
31
+ context 'called with anything else' do
32
+ it 'returns the argument called with' do
33
+ expect(Loga::RevisionStrategy.call('foobar')).to eq('foobar')
34
+ end
35
+
36
+ it 'strips any leading and trailing whitespace' do
37
+ expect(Loga::RevisionStrategy.call("\t foobar\r\n ")).to eq('foobar')
38
+ end
39
+ end
40
+ end
41
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loga
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Funding Circle
@@ -182,6 +182,7 @@ files:
182
182
  - lib/loga/rack/request.rb
183
183
  - lib/loga/rack/request_id.rb
184
184
  - lib/loga/railtie.rb
185
+ - lib/loga/revision_strategy.rb
185
186
  - lib/loga/tagged_logging.rb
186
187
  - lib/loga/utilities.rb
187
188
  - lib/loga/version.rb
@@ -256,6 +257,7 @@ files:
256
257
  - spec/unit/loga/parameter_filter_spec.rb
257
258
  - spec/unit/loga/rack/logger_spec.rb
258
259
  - spec/unit/loga/rack/request_spec.rb
260
+ - spec/unit/loga/revision_strategy_spec.rb
259
261
  - spec/unit/loga/utilities_spec.rb
260
262
  - spec/unit/loga_spec.rb
261
263
  homepage: https://github.com/FundingCircle/loga
@@ -352,6 +354,7 @@ test_files:
352
354
  - spec/unit/loga/parameter_filter_spec.rb
353
355
  - spec/unit/loga/rack/logger_spec.rb
354
356
  - spec/unit/loga/rack/request_spec.rb
357
+ - spec/unit/loga/revision_strategy_spec.rb
355
358
  - spec/unit/loga/utilities_spec.rb
356
359
  - spec/unit/loga_spec.rb
357
360
  has_rdoc: