simple-images-downloader 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile.lock +2 -9
  4. data/README.md +14 -1
  5. data/lib/simple_images_downloader/client.rb +17 -0
  6. data/lib/simple_images_downloader/configuration.rb +30 -1
  7. data/lib/simple_images_downloader/dispenser.rb +8 -6
  8. data/lib/simple_images_downloader/downloader.rb +16 -22
  9. data/lib/simple_images_downloader/errors.rb +24 -3
  10. data/lib/simple_images_downloader/line.rb +1 -5
  11. data/lib/simple_images_downloader/source_file.rb +6 -4
  12. data/lib/simple_images_downloader/strategies/from_file_strategy.rb +24 -0
  13. data/lib/simple_images_downloader/strategies/from_url_strategy.rb +18 -0
  14. data/lib/simple_images_downloader/strategies/strategy.rb +14 -0
  15. data/lib/simple_images_downloader/stringio_to_tempfile.rb +0 -2
  16. data/lib/simple_images_downloader/validatable/destination_validator.rb +14 -0
  17. data/lib/simple_images_downloader/validatable/file_accessibility_validator.rb +13 -0
  18. data/lib/simple_images_downloader/validatable/file_persistance_validator.rb +13 -0
  19. data/lib/simple_images_downloader/validatable/mime_type_validator.rb +59 -0
  20. data/lib/simple_images_downloader/validatable/validator.rb +11 -0
  21. data/lib/simple_images_downloader/validatable.rb +9 -0
  22. data/lib/simple_images_downloader/version.rb +1 -1
  23. data/lib/simple_images_downloader.rb +22 -15
  24. data/rubocop.yml +4 -1
  25. data/simple_images_downloader.gemspec +0 -3
  26. metadata +16 -36
  27. data/lib/simple_images_downloader/file_persistance_validator.rb +0 -13
  28. data/lib/simple_images_downloader/image_path_validator.rb +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eaab3c2b2fd909ddb983e0f23b20bb4361c41288ea834ab698b972c42a3b211b
4
- data.tar.gz: ea9be3356750b3ec278b01f439eac533c12dc757ab9c0fb26496e7b90a954302
3
+ metadata.gz: 902c3b0e5fe1566296ac139123707162e33ded87accc9ff5705231fb3fa96f4f
4
+ data.tar.gz: c2812c8d700ca81d1f29b6a29d0063aef74b9dfd3162c652453733870b8073fe
5
5
  SHA512:
6
- metadata.gz: a127db82c6529f8c592f1a85f88f8cc7742aa5ea175a18cdca895e7f4e17a08b14213713aa1b5030cdf44fda1ddd785c7b600f7f7ad69854d09dc5179e1ba708
7
- data.tar.gz: 32538f8dd10a8d7d3eca94819cac12a2170364b11a612b7a555cb3898eba95e19628ea8726ab95e2cbc86e5cac65dfbbab128461c5e54cae01b37a3354cfcc61
6
+ metadata.gz: 5501d04aa338c0f992d391d94a5b29e8b63a410938c7a8f31941ed3178b2efa63a6ef84b9bb419f87278880197498367eeb235dea017509c57c708f758f7b4ab
7
+ data.tar.gz: 26ba7c6dbd4cfdf1e34750ce6b3f7e99650511ba56597a7c8ab1ee7950c210f7919f0a1104053fcc6195bec822b215678e9c8bc5015fee9d6fc8ae6eb27612e7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 1.1.0 - 2023-09-30
2
+ - Add validation of downloaded content over path validation
3
+ - Add ability to extend mime types from configuration
4
+ - Removed zeitwerk
5
+ - Refactored main interface
6
+
7
+ ## 1.0.3 - 2023-09-27
8
+ - Corrected destination validation in SimpleImagesDownloader::Dispenser
9
+ - Corrected source file validation in SimpleImagesDownloader::SourceFile
10
+ - Refactored
11
+ - Fixed error message when destination is invalid
12
+
1
13
  ## 1.0.2 - 2020-09-25
2
14
  - Refactored SimpleImagesDownloader::Dispenser keeping the same behaviour
3
15
  - Updated README
data/Gemfile.lock CHANGED
@@ -1,8 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple-images-downloader (1.0.2)
5
- zeitwerk (~> 2.4.0)
4
+ simple-images-downloader (1.1.0)
6
5
 
7
6
  GEM
8
7
  remote: https://rubygems.org/
@@ -10,7 +9,6 @@ GEM
10
9
  addressable (2.7.0)
11
10
  public_suffix (>= 2.0.2, < 5.0)
12
11
  ast (2.4.1)
13
- byebug (11.1.3)
14
12
  coderay (1.1.3)
15
13
  concurrent-ruby (1.1.7)
16
14
  crack (0.4.4)
@@ -29,9 +27,6 @@ GEM
29
27
  pry (0.13.1)
30
28
  coderay (~> 1.1)
31
29
  method_source (~> 1.0)
32
- pry-byebug (3.9.0)
33
- byebug (~> 11.0)
34
- pry (~> 0.13.0)
35
30
  public_suffix (4.0.6)
36
31
  rainbow (3.0.0)
37
32
  rake (12.3.3)
@@ -80,7 +75,6 @@ GEM
80
75
  addressable (>= 2.3.6)
81
76
  crack (>= 0.3.2)
82
77
  hashdiff (>= 0.4.0, < 2.0.0)
83
- zeitwerk (2.4.0)
84
78
 
85
79
  PLATFORMS
86
80
  ruby
@@ -88,7 +82,6 @@ PLATFORMS
88
82
  DEPENDENCIES
89
83
  faker (~> 2.14)
90
84
  pry (~> 0.13.1)
91
- pry-byebug (~> 3.9.0)
92
85
  rake (~> 12.0)
93
86
  rspec (~> 3.0)
94
87
  rspec_junit_formatter (~> 0.4.1)
@@ -104,4 +97,4 @@ RUBY VERSION
104
97
  ruby 2.7.1p83
105
98
 
106
99
  BUNDLED WITH
107
- 2.1.4
100
+ 2.2.19
data/README.md CHANGED
@@ -33,7 +33,7 @@ Or install it yourself as:
33
33
 
34
34
  The gem is provided with executable.
35
35
 
36
- You can either run plain commmand with file containing list of url:
36
+ You can either run plain command with file containing list of url:
37
37
 
38
38
  ```bash
39
39
  simple-images-downloader <path_to_file>
@@ -67,6 +67,7 @@ Downloading https://test-for-simple-images-downloader.s3.eu-central-1.amazonaws.
67
67
  Downloading is finished
68
68
  ```
69
69
 
70
+ ## Configuration
70
71
  **By default the images stored in a directory the script is run.**
71
72
  You can also configure the place where the images would be stored to:
72
73
 
@@ -78,6 +79,18 @@ You can also configure the place where the images would be stored to:
78
79
  [2] pry(main)* end
79
80
  ```
80
81
 
82
+ **By default the gem downloads only images with mime types: image/avif, image/gif, image/apng, image/jpg, image/jpeg, image/png, image/svg+xml, image/webp.**
83
+ You can also configure the mime types to download images with:
84
+
85
+
86
+ ```ruby
87
+ [1] pry(main)> require 'simple_images_downloader'
88
+
89
+ [2] pry(main)> SimpleImagesDownloader::Configuration.configure do |config|
90
+ [2] pry(main)* # You must use RFC 1341 - MIME (Multipurpose Internet Mail Extensions) format
91
+ [2] pry(main)* config.valid_mime_types = %w(image/png image/jpg image/jpeg)
92
+ [2] pry(main)* end
93
+ ```
81
94
  ## Development
82
95
 
83
96
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleImagesDownloader
4
+ class Client
5
+ def initialize(options = Configuration::REQUEST_OPTIONS)
6
+ @options = options
7
+ end
8
+
9
+ def open(uri)
10
+ uri.open(@options)
11
+ rescue OpenURI::HTTPRedirect
12
+ raise Errors::RedirectError, uri
13
+ rescue OpenURI::HTTPError
14
+ raise Errors::ConnectionError, uri
15
+ end
16
+ end
17
+ end
@@ -6,12 +6,41 @@ module SimpleImagesDownloader
6
6
 
7
7
  ACCESSORS = %i[
8
8
  destination
9
+ valid_mime_types
9
10
  ].freeze
10
11
 
12
+ REQUEST_OPTIONS = {
13
+ 'User-Agent' => "SimpleImagesDownloader/#{SimpleImagesDownloader::VERSION}",
14
+ redirect: false,
15
+ open_timeout: 30,
16
+ read_timeout: 30
17
+ }.freeze
18
+
19
+ # https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#common_image_file_types
20
+ DEFAULT_VALID_MIME_TYPES_MAP = {
21
+ 'image/avif' => true,
22
+ 'image/gif' => true,
23
+ 'image/apng' => true,
24
+ 'image/jpg' => true,
25
+ 'image/jpeg' => true,
26
+ 'image/png' => true,
27
+ 'image/svg+xml' => true,
28
+ 'image/webp' => true
29
+ }.freeze
30
+
31
+ DEFAULT_DESTINATION = './'
32
+
11
33
  attr_accessor(*ACCESSORS)
12
34
 
13
35
  def initialize
14
- @destination = './'
36
+ @destination = DEFAULT_DESTINATION
37
+ @valid_mime_types = DEFAULT_VALID_MIME_TYPES_MAP.keys
38
+ end
39
+
40
+ def valid_mime_types=(value)
41
+ raise BaseError, 'valid_mime_types must be an array' unless value.is_a?(Array)
42
+
43
+ @valid_mime_types = value
15
44
  end
16
45
 
17
46
  def self.configure
@@ -3,28 +3,30 @@
3
3
  module SimpleImagesDownloader
4
4
  class Dispenser
5
5
  extend Forwardable
6
+ include Validatable
6
7
 
7
8
  def_delegator 'SimpleImagesDownloader::Configuration', :destination, :destination_dir
8
9
 
9
- def initialize(source, remote_path)
10
+ def initialize(source, remote_path, validators = [DestinationValidator.new])
10
11
  @source = source
11
12
  @remote_path = remote_path
13
+ @validators = validators
12
14
  end
13
15
 
14
16
  def place
15
- raise Errors::DestinationIsNotWritable, destination unless File.writable?(destination_dir)
17
+ validate!({ path: destination_dir })
16
18
 
17
- FileUtils.mv @source, destination
19
+ FileUtils.mv @source, target
18
20
  end
19
21
 
20
- def destination
21
- @destination ||= destination_dir + file_name
22
+ def target
23
+ @target ||= destination_dir + file_name
22
24
  end
23
25
 
24
26
  def file_name
25
27
  @file_name ||= File.basename(@source) + File.extname(@remote_path)
26
28
  end
27
29
 
28
- private :destination_dir, :destination, :file_name
30
+ private :destination_dir, :target, :file_name
29
31
  end
30
32
  end
@@ -2,37 +2,31 @@
2
2
 
3
3
  module SimpleImagesDownloader
4
4
  class Downloader
5
- REQUEST_OPTIONS = {
6
- 'User-Agent' => "SimpleImagesDownloader/#{SimpleImagesDownloader::VERSION}",
7
- redirect: false,
8
- open_timeout: 30,
9
- read_timeout: 30
10
- }.freeze
11
-
12
- def initialize(uri)
13
- @uri = uri
5
+ include Validatable
6
+
7
+ def initialize(uri, client = Client.new, validators = [MimeTypeValidator.new])
8
+ @uri = uri
9
+ @client = client
10
+ @validators = validators
14
11
  end
15
12
 
16
13
  def download
17
14
  puts "Downloading #{@uri}"
18
15
 
19
- @downloaded_file = StringioToTempfile.convert(downloaded_file) if downloaded_file.is_a?(StringIO)
16
+ io = @client.open(@uri)
20
17
 
21
- Dispenser.new(downloaded_file, @uri.path).place
18
+ raise Errors::EmptyResponse, @uri if io.nil?
22
19
 
23
- puts 'Downloading is finished'
24
- ensure
25
- downloaded_file.close
26
- end
20
+ validate!({ path: @uri.to_s, io: io })
27
21
 
28
- private
22
+ tempfile = StringioToTempfile.convert(io)
29
23
 
30
- def downloaded_file
31
- @downloaded_file ||= @uri.open(REQUEST_OPTIONS)
32
- rescue OpenURI::HTTPRedirect
33
- raise Errors::RedirectError, @uri
34
- rescue OpenURI::HTTPError
35
- raise Errors::ConnectionError, @uri
24
+ Dispenser.new(tempfile, @uri.path).place
25
+
26
+ puts 'Downloading is finished'
27
+ ensure
28
+ io&.close
29
+ tempfile&.close
36
30
  end
37
31
  end
38
32
  end
@@ -25,9 +25,9 @@ module SimpleImagesDownloader
25
25
  end
26
26
  end
27
27
 
28
- class MissingImageInPath < BaseError
29
- def initialize(path)
30
- message = "The path doesn't contain image #{path}"
28
+ class BadMimeType < BaseError
29
+ def initialize(path, mime_type)
30
+ message = "The image with path: #{path} has wrong mime type #{mime_type}"
31
31
  super(message)
32
32
  end
33
33
  end
@@ -52,5 +52,26 @@ module SimpleImagesDownloader
52
52
  super(message)
53
53
  end
54
54
  end
55
+
56
+ class DestinationIsNotDirectory < BaseError
57
+ def initialize(path)
58
+ message = "The destination - #{path} is not directory"
59
+ super(message)
60
+ end
61
+ end
62
+
63
+ class PermissionsError < BaseError
64
+ def initialize(path)
65
+ message = "Couldn't read file #{path} due to permissions error"
66
+ super(message)
67
+ end
68
+ end
69
+
70
+ class EmptyResponse < BaseError
71
+ def initialize(uri)
72
+ message = "Nothing returned from request #{uri}"
73
+ super(message)
74
+ end
75
+ end
55
76
  end
56
77
  end
@@ -7,11 +7,7 @@ module SimpleImagesDownloader
7
7
  end
8
8
 
9
9
  def uri
10
- parsed_uri = URI.parse(@string)
11
-
12
- ImagePathValidator.new(@string).validate
13
-
14
- parsed_uri
10
+ URI.parse(@string)
15
11
  rescue URI::Error
16
12
  raise Errors::BadUrl, @string
17
13
  end
@@ -2,13 +2,15 @@
2
2
 
3
3
  module SimpleImagesDownloader
4
4
  class SourceFile
5
- def initialize(path, validator = nil)
6
- @path = path
7
- @validator = validator || SimpleImagesDownloader::FilePersistanceValidator.new(path)
5
+ include Validatable
6
+
7
+ def initialize(path, validators = [FilePersistanceValidator.new, FileAccessibilityValidator.new])
8
+ @path = path
9
+ @validators = validators
8
10
  end
9
11
 
10
12
  def each_line(&block)
11
- @validator.validate
13
+ validate!({ path: @path })
12
14
 
13
15
  begin
14
16
  file.each(chomp: true, &block)
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleImagesDownloader
4
+ module Strategies
5
+ class FromFileStrategy < Strategy
6
+ def initialize(path)
7
+ super
8
+ @path = path
9
+ end
10
+
11
+ def process
12
+ source_file = SourceFile.new(@path)
13
+
14
+ source_file.each_line do |line|
15
+ uri = Line.new(line).uri
16
+ Downloader.new(uri).download
17
+ rescue Errors::BaseError => e
18
+ puts e.message
19
+ next
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleImagesDownloader
4
+ module Strategies
5
+ class FromUrlStrategy < Strategy
6
+ def initialize(url)
7
+ super
8
+ @url = url
9
+ end
10
+
11
+ def process
12
+ uri = Line.new(@url).uri
13
+
14
+ Downloader.new(uri).download
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleImagesDownloader
4
+ module Strategies
5
+ class Strategy
6
+ def initialize(_)
7
+ end
8
+
9
+ def process
10
+ raise NotImplementedError, 'must be implemented in subclass'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -9,8 +9,6 @@ module SimpleImagesDownloader
9
9
 
10
10
  IO.copy_stream(stringio, tempfile)
11
11
 
12
- stringio.close
13
-
14
12
  OpenURI::Meta.init tempfile, stringio
15
13
 
16
14
  tempfile
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleImagesDownloader
4
+ module Validatable
5
+ class DestinationValidator < Validator
6
+ def validate(options)
7
+ path = options[:path]
8
+
9
+ raise Errors::DestinationIsNotDirectory, path unless File.directory?(path)
10
+ raise Errors::DestinationIsNotWritable, path unless File.writable?(path)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleImagesDownloader
4
+ module Validatable
5
+ class FileAccessibilityValidator < Validator
6
+ def validate(options)
7
+ return if File.readable?(options[:path])
8
+
9
+ raise Errors::PermissionsError, options[:path]
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleImagesDownloader
4
+ module Validatable
5
+ class FilePersistanceValidator < Validator
6
+ def validate(options)
7
+ return if File.exist?(options[:path])
8
+
9
+ raise Errors::MissingFileError, options[:path]
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleImagesDownloader
4
+ module Validatable
5
+ class MimeTypeValidator < Validator
6
+ extend Forwardable
7
+
8
+ def_delegator 'SimpleImagesDownloader::Configuration', :valid_mime_types, :valid_mime_types
9
+
10
+ def validate(options)
11
+ path = options[:path]
12
+ io = options[:io]
13
+
14
+ mime_type = mime_type_of(io)
15
+
16
+ return if Configuration::DEFAULT_VALID_MIME_TYPES_MAP[mime_type]
17
+
18
+ raise Errors::BadMimeType.new(path, mime_type)
19
+ end
20
+
21
+ private
22
+
23
+ # Taken from Shrine https://github.com/shrinerb/shrine/blob/master/lib/shrine/plugins/determine_mime_type.rb#L94
24
+ def mime_type_of(io)
25
+ Open3.popen3('file --mime-type --brief -') do |stdin, stdout, stderr, thread|
26
+ copy_stream(from: io, to: stdin.binmode)
27
+
28
+ io.rewind
29
+ stdin.close
30
+
31
+ status = thread.value
32
+
33
+ validate_thread_status(status)
34
+ $stderr.print(stderr.read)
35
+
36
+ output = stdout.read.strip
37
+
38
+ validate_command_output(output)
39
+
40
+ output
41
+ end
42
+ end
43
+
44
+ def copy_stream(from:, to:)
45
+ IO.copy_stream(from, to)
46
+ rescue Errno::EPIPE # rubocop:disable Lint/SuppressedException
47
+ end
48
+
49
+ def validate_thread_status(status)
50
+ raise Errors::BaseError, "file command failed to spawn: #{stderr.read}" if status.nil?
51
+ raise Errors::BaseError, "file command failed: #{stderr.read}" unless status.success?
52
+ end
53
+
54
+ def validate_command_output(output)
55
+ raise Errors::BaseError, "file command failed: #{output}" if output.include?('cannot open')
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleImagesDownloader
4
+ module Validatable
5
+ class Validator
6
+ def validate(_value)
7
+ raise NotImplementedError, 'must be implemented in subclass'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleImagesDownloader
4
+ module Validatable
5
+ def validate!(value)
6
+ (@validators ||= []).each { |validator| validator.validate(value) }
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleImagesDownloader
4
- VERSION = '1.0.2'
4
+ VERSION = '1.1.0'
5
5
  end
@@ -4,27 +4,34 @@ require 'open-uri'
4
4
  require 'tempfile'
5
5
  require 'forwardable'
6
6
  require 'singleton'
7
- require 'zeitwerk'
8
-
9
- loader = Zeitwerk::Loader.for_gem
10
- loader.setup
7
+ require 'open3'
8
+ require_relative 'simple_images_downloader/version'
9
+ require_relative 'simple_images_downloader/errors'
10
+ require_relative 'simple_images_downloader/configuration'
11
+ require_relative 'simple_images_downloader/validatable'
12
+ require_relative 'simple_images_downloader/validatable/validator'
13
+ require_relative 'simple_images_downloader/validatable/destination_validator'
14
+ require_relative 'simple_images_downloader/validatable/file_accessibility_validator'
15
+ require_relative 'simple_images_downloader/validatable/file_persistance_validator'
16
+ require_relative 'simple_images_downloader/validatable/mime_type_validator'
17
+ require_relative 'simple_images_downloader/stringio_to_tempfile'
18
+ require_relative 'simple_images_downloader/client'
19
+ require_relative 'simple_images_downloader/source_file'
20
+ require_relative 'simple_images_downloader/runner'
21
+ require_relative 'simple_images_downloader/line'
22
+ require_relative 'simple_images_downloader/dispenser'
23
+ require_relative 'simple_images_downloader/strategies/strategy'
24
+ require_relative 'simple_images_downloader/downloader'
25
+ require_relative 'simple_images_downloader/strategies/from_file_strategy'
26
+ require_relative 'simple_images_downloader/strategies/from_url_strategy'
11
27
 
12
28
  module SimpleImagesDownloader
13
29
  def self.from_file(path)
14
- source_file = SourceFile.new(path)
15
-
16
- source_file.each_line do |line|
17
- uri = Line.new(line).uri
18
- Downloader.new(uri).download
19
- rescue Errors::BaseError => e
20
- puts e.message
21
- next
22
- end
30
+ SimpleImagesDownloader::Strategies::FromFileStrategy.new(path).process
23
31
  end
24
32
 
25
33
  def self.from_url(url)
26
- uri = Line.new(url).uri
27
- Downloader.new(uri).download
34
+ SimpleImagesDownloader::Strategies::FromUrlStrategy.new(url).process
28
35
  end
29
36
 
30
37
  def self.root
data/rubocop.yml CHANGED
@@ -33,7 +33,7 @@ Style/Documentation:
33
33
  Enabled: false
34
34
 
35
35
  Style/MethodCalledOnDoEndBlock:
36
- Enabled: true
36
+ Enabled: false
37
37
 
38
38
  Style/CollectionMethods:
39
39
  Enabled: true
@@ -69,6 +69,9 @@ Layout/LineLength:
69
69
  Metrics/BlockLength:
70
70
  Enabled: false
71
71
 
72
+ Metrics/MethodLength:
73
+ Max: 11
74
+
72
75
  Layout/EndAlignment:
73
76
  EnforcedStyleAlignWith: variable
74
77
  SupportedStylesAlignWith:
@@ -30,11 +30,8 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ['lib']
32
32
 
33
- spec.add_runtime_dependency 'zeitwerk', '~> 2.4.0'
34
-
35
33
  spec.add_development_dependency 'faker', '~> 2.14'
36
34
  spec.add_development_dependency 'pry', '~> 0.13.1'
37
- spec.add_development_dependency 'pry-byebug', '~> 3.9.0'
38
35
  spec.add_development_dependency 'rake', '~> 12.0'
39
36
  spec.add_development_dependency 'rspec', '~> 3.0'
40
37
  spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4.1'
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-images-downloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - IlkhamGaysin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-25 00:00:00.000000000 Z
11
+ date: 2023-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: zeitwerk
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 2.4.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 2.4.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: faker
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -52,20 +38,6 @@ dependencies:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
40
  version: 0.13.1
55
- - !ruby/object:Gem::Dependency
56
- name: pry-byebug
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 3.9.0
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 3.9.0
69
41
  - !ruby/object:Gem::Dependency
70
42
  name: rake
71
43
  requirement: !ruby/object:Gem::Requirement
@@ -192,7 +164,7 @@ dependencies:
192
164
  - - "~>"
193
165
  - !ruby/object:Gem::Version
194
166
  version: 3.9.1
195
- description:
167
+ description:
196
168
  email:
197
169
  - ilgamgaysin@gmail.com
198
170
  executables:
@@ -220,16 +192,24 @@ files:
220
192
  - bin/setup
221
193
  - exe/simple-images-downloader
222
194
  - lib/simple_images_downloader.rb
195
+ - lib/simple_images_downloader/client.rb
223
196
  - lib/simple_images_downloader/configuration.rb
224
197
  - lib/simple_images_downloader/dispenser.rb
225
198
  - lib/simple_images_downloader/downloader.rb
226
199
  - lib/simple_images_downloader/errors.rb
227
- - lib/simple_images_downloader/file_persistance_validator.rb
228
- - lib/simple_images_downloader/image_path_validator.rb
229
200
  - lib/simple_images_downloader/line.rb
230
201
  - lib/simple_images_downloader/runner.rb
231
202
  - lib/simple_images_downloader/source_file.rb
203
+ - lib/simple_images_downloader/strategies/from_file_strategy.rb
204
+ - lib/simple_images_downloader/strategies/from_url_strategy.rb
205
+ - lib/simple_images_downloader/strategies/strategy.rb
232
206
  - lib/simple_images_downloader/stringio_to_tempfile.rb
207
+ - lib/simple_images_downloader/validatable.rb
208
+ - lib/simple_images_downloader/validatable/destination_validator.rb
209
+ - lib/simple_images_downloader/validatable/file_accessibility_validator.rb
210
+ - lib/simple_images_downloader/validatable/file_persistance_validator.rb
211
+ - lib/simple_images_downloader/validatable/mime_type_validator.rb
212
+ - lib/simple_images_downloader/validatable/validator.rb
233
213
  - lib/simple_images_downloader/version.rb
234
214
  - rubocop.yml
235
215
  - simple_images_downloader.gemspec
@@ -240,7 +220,7 @@ metadata:
240
220
  homepage_uri: https://github.com/IlkhamGaysin/simple-images-downloader
241
221
  source_code_uri: https://github.com/IlkhamGaysin/simple-images-downloader
242
222
  changelog_uri: https://github.com/IlkhamGaysin/simple-images-downloader/blob/master/CHANGELOG.md
243
- post_install_message:
223
+ post_install_message:
244
224
  rdoc_options: []
245
225
  require_paths:
246
226
  - lib
@@ -256,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
236
  version: '0'
257
237
  requirements: []
258
238
  rubygems_version: 3.1.2
259
- signing_key:
239
+ signing_key:
260
240
  specification_version: 4
261
241
  summary: simple-images-downloader allows to download images from a file containing
262
242
  list of urls to those images.
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SimpleImagesDownloader
4
- class FilePersistanceValidator
5
- def initialize(path)
6
- @path = path
7
- end
8
-
9
- def validate
10
- raise Errors::MissingFileError, @path unless File.exist?(@path)
11
- end
12
- end
13
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SimpleImagesDownloader
4
- class ImagePathValidator
5
- VALID_EXTENSIONS = %w[.png .jpg .gif .jpeg].freeze
6
-
7
- def initialize(path)
8
- @path = path
9
- end
10
-
11
- def validate
12
- raise Errors::MissingImageInPath, @path unless VALID_EXTENSIONS.include?(extension)
13
- end
14
-
15
- private
16
-
17
- def extension
18
- File.extname(@path)
19
- end
20
- end
21
- end