log_sweeper 0.0.1 → 1.0.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
  SHA256:
3
- metadata.gz: 77b7b4be360580605c05e085b604304e967112df752cb59ac6d728f288b2f15c
4
- data.tar.gz: fae206b890ae1c4a86f2e2f79301aa23e236eb5a99e6d33f47301145a9281120
3
+ metadata.gz: 4db94e181fdea505a9a543ea7ad4316f06b4d3f396137804ef6db8cc8d38025d
4
+ data.tar.gz: 69f722b86d9c989f4ba0dac7408f9e58703ac51ed6bae91a3923d32f8c01b7c2
5
5
  SHA512:
6
- metadata.gz: d500903c3b7a51c96c146093860fe22fee76dfd064563c3377432db3c33bca710abacfe6cf228baff53ef3869dd796df087c5b370082bfb5f8e287c30b1f4e52
7
- data.tar.gz: a8417e9b67a910d0fc9074f51e20cb177bcc8d47805af40692e27855442ccd6248038ea4492bc3d8e9a3af713cc6f96f81b502efdcab58da6922ec146c6f8d42
6
+ metadata.gz: 14b54d6394d7ddce37db6c7cd233f456fb00a11e513c7993f9b6ff4a7611d85857b5a02a7cf627bcab7c16f8a41e3ad0b5575732b73b1853757b64f46cb7364c
7
+ data.tar.gz: 44d078163fdb1dc8bede864a389afb91d9f485359bddb0fc1d08a494aaa541cc0e655c5094f0a451c4839738411770f4562cd7bc2147509e441f6bb11ac03081
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ inherit_gem:
2
+ rubocop-config-umbrellio: lib/rubocop.yml
3
+
4
+ AllCops:
5
+ DisplayCopNames: true
6
+ TargetRubyVersion: 2.5
data/.travis.yml CHANGED
@@ -1,7 +1,17 @@
1
- ---
2
- sudo: false
3
1
  language: ruby
4
- cache: bundler
2
+ sudo: false
5
3
  rvm:
6
- - 2.6.0
7
- before_install: gem install bundler -v 2.0.1
4
+ - 2.3
5
+ - 2.4
6
+ - 2.5
7
+ - 2.6
8
+ before_install: gem install bundler
9
+ env: SUITE="rspec"
10
+ script: bundle exec $SUITE
11
+ matrix:
12
+ fast_finish: true
13
+ include:
14
+ - rvm: 2.6
15
+ env: SUITE="rubocop"
16
+ allow_failures:
17
+ - rvm: ruby-head
data/Gemfile CHANGED
@@ -1,4 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in log_sweeper.gemspec
4
6
  gemspec
7
+
8
+ gem "rubocop-config-umbrellio", github: "umbrellio/code-style"
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/lib/log_sweeper.rb CHANGED
@@ -1,6 +1,44 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "log_sweeper/version"
2
4
 
5
+ require "shellwords"
6
+ require "pathname"
7
+ require "logger"
8
+
3
9
  module LogSweeper
4
- class Error < StandardError; end
5
- # Your code goes here...
10
+ extend self
11
+
12
+ def run(path, logs_lifetime_days_count: 10, logger: Logger.new(STDOUT))
13
+ min_mtime = Time.now - (logs_lifetime_days_count.to_f * 24 * 3600)
14
+
15
+ Pathname.new(path).each_child do |entry|
16
+ next unless entry.file?
17
+
18
+ filename = entry.basename.to_s
19
+
20
+ if filename.match?(/\.log\b/) && entry.mtime < min_mtime
21
+ logger.info "deleting #{entry}"
22
+ entry.delete
23
+ elsif filename.match?(/\.log\.\d+$/)
24
+ logger.info "gzipping #{entry}"
25
+ compress_file(entry)
26
+ entry.delete
27
+ else
28
+ logger.info "skipping #{entry}"
29
+ end
30
+ end
31
+
32
+ true
33
+ end
34
+
35
+ private
36
+
37
+ def compress_file(file_name)
38
+ zipped = "#{file_name}.gz"
39
+
40
+ Zlib::GzipWriter.open(zipped) do |gz|
41
+ gz.write IO.binread(file_name)
42
+ end
43
+ end
6
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LogSweeper
2
- VERSION = "0.0.1"
4
+ VERSION = "1.0.0"
3
5
  end
data/log_sweeper.gemspec CHANGED
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path("lib", __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require "log_sweeper/version"
5
6
 
@@ -9,14 +10,14 @@ Gem::Specification.new do |spec|
9
10
  spec.authors = ["Yuri Smirnov"]
10
11
  spec.email = ["tycooon@yandex.ru"]
11
12
 
12
- spec.summary = %q{TBD}
13
- spec.description = %q{TBD}
13
+ spec.summary = "TBD"
14
+ spec.description = "TBD"
14
15
  spec.homepage = "https://github.com/umbrellio/log_sweeper"
15
16
  spec.license = "MIT"
16
17
 
17
18
  # Specify which files should be added to the gem when it is released.
18
19
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
21
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
22
  end
22
23
  spec.bindir = "exe"
@@ -24,6 +25,9 @@ Gem::Specification.new do |spec|
24
25
  spec.require_paths = ["lib"]
25
26
 
26
27
  spec.add_development_dependency "bundler"
28
+ spec.add_development_dependency "coveralls"
29
+ spec.add_development_dependency "pry"
27
30
  spec.add_development_dependency "rake"
28
31
  spec.add_development_dependency "rspec"
32
+ spec.add_development_dependency "simplecov"
29
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_sweeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Smirnov
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coveralls
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rake
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +80,20 @@ dependencies:
52
80
  - - ">="
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  description: TBD
56
98
  email:
57
99
  - tycooon@yandex.ru
@@ -61,6 +103,7 @@ extra_rdoc_files: []
61
103
  files:
62
104
  - ".gitignore"
63
105
  - ".rspec"
106
+ - ".rubocop.yml"
64
107
  - ".travis.yml"
65
108
  - Gemfile
66
109
  - LICENSE.txt