mini_paperclip 0.1.0 → 0.1.1

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: 934c31a21e7ff961a58d0d22023b0d17095b83087a22845b30e85102bba1667b
4
- data.tar.gz: 003a3f115224cf645d81fe98dfd1664ea3386aa48f7436791a1bf6b14c0b864a
3
+ metadata.gz: 51135052187a9097d6989759082fcdba81aecfb7259909ba8bbf1dd17bf70036
4
+ data.tar.gz: 47673d86acfd5538bd0fb43cb373041add3281217ffae31d4bfcb71a7c2cf08b
5
5
  SHA512:
6
- metadata.gz: 60d2cb3ddfcff65b7edcf3519d7752f5a5aafb03bdcf15ba487b6c423af234feb13224b609d5bba1cd3bba3939f70f9aaa8b7a9209ecdef8e414e829a946ea4a
7
- data.tar.gz: d16ef4a7638188af8963b87ab41c0045cf1a73547558b0d9864ba7efa713f30e86164c81ae8cb19ecc998c1b250dafa99d2c5556cf27e80eddf8cd53d8a867a4
6
+ metadata.gz: 703405ef627eecc1df7856f65f9f27877fb675c95b8c2eb9bbe45c998f71cbebba1b37101bf44d8ec9ce64782a0a39caa06cde4752fa6007279366760acb0659
7
+ data.tar.gz: ded84756cf123fe3ffe82b8c47b59ac30c9ab39785056c4644a21e2ffd0183dd9e2250623f0307de41394c9392a0f650e64af3d0862163b1a5cc73522c0ed8ed
@@ -8,6 +8,7 @@ require "active_support/number_helper"
8
8
  require "mini_magick"
9
9
  require "mimemagic"
10
10
  require "aws-sdk-s3"
11
+ require "image_size"
11
12
 
12
13
  require "mini_paperclip/attachment"
13
14
  require "mini_paperclip/class_methods"
@@ -38,11 +38,13 @@ module MiniPaperclip
38
38
  end
39
39
 
40
40
  def exists?(style)
41
- res = Aws::S3::Client.new.head_object(
41
+ Aws::S3::Client.new.head_object(
42
42
  bucket: @config.s3_bucket_name,
43
43
  key: s3_object_key(style),
44
44
  )
45
- res.content_length.to_i != 0
45
+ true
46
+ rescue Aws::S3::Errors::NotFound
47
+ false
46
48
  end
47
49
  end
48
50
  end
@@ -16,26 +16,24 @@ module MiniPaperclip
16
16
  end
17
17
  end
18
18
  end
19
+
19
20
  # validate_attachment :image,
20
21
  # geometry: {
21
22
  # width: { less_than_or_equal_to: 3000 },
22
23
  # height: { less_than_or_equal_to: 3000 } }
23
24
  def validate_each(record, attribute, value)
24
25
  return unless value.waiting_write_file
25
- geometry_string = MiniMagick::Tool::Identify.new do |identify|
26
- identify.format "%w,%h"
27
- identify << value.waiting_write_file.path
28
- end
29
- return unless !geometry_string.empty?
30
- width, height = geometry_string.split(',').map(&:to_i)
26
+ image_size = ImageSize.new(value.waiting_write_file)
27
+ # invalid format should not relate geometry
28
+ return unless image_size.format
31
29
 
32
30
  expected_width_less_than_or_equal_to = options.dig(:width, :less_than_or_equal_to)
33
31
  expected_height_less_than_or_equal_to = options.dig(:height, :less_than_or_equal_to)
34
- unless (!expected_width_less_than_or_equal_to || width <= expected_width_less_than_or_equal_to) &&
35
- (!expected_height_less_than_or_equal_to || height <= expected_height_less_than_or_equal_to)
32
+ unless (!expected_width_less_than_or_equal_to || image_size.width <= expected_width_less_than_or_equal_to) &&
33
+ (!expected_height_less_than_or_equal_to || image_size.height <= expected_height_less_than_or_equal_to)
36
34
  record.errors.add(attribute, :geometry, {
37
- actual_width: width,
38
- actual_height: height,
35
+ actual_width: image_size.width,
36
+ actual_height: image_size.height,
39
37
  expected_width_less_than_or_equal_to: expected_width_less_than_or_equal_to,
40
38
  expected_height_less_than_or_equal_to: expected_height_less_than_or_equal_to,
41
39
  })
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniPaperclip
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.add_runtime_dependency "activemodel"
18
18
  spec.add_runtime_dependency "activesupport"
19
19
  spec.add_runtime_dependency "aws-sdk-s3"
20
+ spec.add_runtime_dependency "image_size"
20
21
 
21
22
  spec.metadata["homepage_uri"] = spec.homepage
22
23
  spec.metadata["source_code_uri"] = spec.homepage
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ksss
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-26 00:00:00.000000000 Z
11
+ date: 2020-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_magick
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: image_size
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: Subset from paperclip because paperclip has deprecated
84
98
  email:
85
99
  - co000ri@gmail.com