img-lint 0.0.7 → 0.0.8

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: 5c17b75b315760007064f86fc3282938fb824388
4
- data.tar.gz: 47caa70b9662c88e91e9233a23b3e283d4dfe42c
3
+ metadata.gz: b572b2ab3cbb809acfc3f0679fc268055e454b97
4
+ data.tar.gz: e039f988782ceefde38c4970d024e440a1b4f976
5
5
  SHA512:
6
- metadata.gz: 13e31daab649ee59ce6acce0da5ee7c8d57dd45121079e49b825284fec46203bc156daefcae8555d4c2553a820c73f093b3c5336ea701b25a0ff0125d1273748
7
- data.tar.gz: bb41bb886cd1addde833686b6e79aa88d592c5af3b8f1c7d423f66bf6609991798403c4252a4015ff5ac8e720cb366166498b251949cffb20660e5fdd64a6551
6
+ metadata.gz: a3d9a569e5d9bfbb022af56f034d6e2823ad63cca3c8fb615c7ca958246e97b7cd196a7cdb786da4a2687d58aeb7657fb3b7ad76a43984541019c465b68093c1
7
+ data.tar.gz: 728fed8c31c2fae34349571ae0da8fb7c8045b102ac497d101ab033a3a9af9da51d3a70227df343f8228445068a4daf59947b5fd61877b6b5b0523c13e2ca1d1
@@ -1,8 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "yaml"
2
4
 
3
5
  module IMGLint
6
+ # Config class is responsible to load img-lint either a user defined config
7
+ # or a default one (config/default.yml)
4
8
  class Config
5
- FILE_NAME = ".img-lint.yml"
9
+ FILE_NAME = ".img-lint.yml".freeze
6
10
  DEFAULT_FILE = File.join(IMG_LINT_HOME, "config", "default.yml")
7
11
 
8
12
  class << self
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IMGLint
4
- IMG_LINT_HOME = File.realpath(File.join(File.dirname(__FILE__), '..', '..')).freeze
4
+ IMG_LINT_HOME = File.realpath(File.join(File.dirname(__FILE__), "..", ".."))
5
5
  end
@@ -1,4 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module IMGLint
4
+ # Linter class is responsible for checking images (only formats specified
5
+ # in config) if they exceed a curtain size. It also prints out list of
6
+ # suspicious images.
2
7
  class Linter
3
8
  attr_accessor :config
4
9
 
@@ -9,17 +14,27 @@ module IMGLint
9
14
  def lint(path: Dir.pwd, verbose: true)
10
15
  path ||= Dir.pwd
11
16
 
12
- max_file_size = config["max_file_size"].to_i
17
+ fat_images = find_fat_images(path, verbose)
18
+
19
+ print_report(path, fat_images, verbose)
20
+
21
+ fat_images
22
+ end
13
23
 
14
- images = Dir.glob(%(#{path}/**/*.{#{config["image_formats"]}}))
24
+ private
25
+
26
+ def find_fat_images(path, verbose)
27
+ images = Dir.glob(%(#{path}/**/*.{#{config['image_formats']}}))
15
28
 
16
29
  puts "No images found in #{path}" if verbose && images.empty?
17
30
 
18
- fat_images = images.select do |file|
19
- File.new(file).size > max_file_size * 1024
31
+ images.select do |file|
32
+ File.new(file).size > config["max_file_size"] * 1024
20
33
  end
34
+ end
21
35
 
22
- if fat_images.size > 0 && verbose
36
+ def print_report(path, fat_images, verbose)
37
+ if !fat_images.empty? && verbose
23
38
  puts "Suspicious images:"
24
39
 
25
40
  fat_images.each do |image|
@@ -30,8 +45,6 @@ module IMGLint
30
45
  puts [image, "#{file_size}Kb"].join("\t")
31
46
  end
32
47
  end
33
-
34
- fat_images
35
48
  end
36
49
  end
37
50
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IMGLint
4
- VERSION = "0.0.7"
4
+ VERSION = "0.0.8".freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: img-lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoli Makarevich