paperclip-meta 2.0.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/paperclip-meta/attachment.rb +70 -81
- data/lib/paperclip-meta/railtie.rb +1 -1
- data/lib/paperclip-meta/version.rb +1 -1
- metadata +48 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cac54df8108f1301db4a4535e94ee4a75112dc0
|
4
|
+
data.tar.gz: 733c91235143bf498cca2c8adb188c5587bc10b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78335a9985dbc3d6b94b00c7abfeaaefd6da3924c0b9ef93fdd38c86e9bf6c90befdb643cf0817bb68bc4b36766b71445172062457c1166f836986721ceb3d6a
|
7
|
+
data.tar.gz: dc49386e04547575f4e60698dd8ba26cb6d8b396b6aafe1c3fbf39050e250448a0ae04b0e140f21db40982461cd6110375c06b93d3682d94678f279ba2268b4c
|
@@ -1,109 +1,98 @@
|
|
1
1
|
module Paperclip
|
2
2
|
module Meta
|
3
3
|
module Attachment
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
base.alias_method_chain :save, :meta_data
|
8
|
-
base.alias_method_chain :post_process_styles, :meta_data
|
9
|
-
base.alias_method_chain :size, :meta_data
|
4
|
+
def assign_attributes
|
5
|
+
super
|
6
|
+
assign_meta
|
10
7
|
end
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
assign_meta
|
16
|
-
end
|
17
|
-
|
18
|
-
def save_with_meta_data
|
19
|
-
if @queued_for_delete.any? && @queued_for_write.empty?
|
20
|
-
instance_write(:meta, meta_encode({}))
|
21
|
-
end
|
22
|
-
save_without_meta_data
|
23
|
-
end
|
24
|
-
|
25
|
-
def post_process_styles_with_meta_data(*styles)
|
26
|
-
post_process_styles_without_meta_data(*styles)
|
27
|
-
assign_meta
|
9
|
+
def save
|
10
|
+
if @queued_for_delete.any? && @queued_for_write.empty?
|
11
|
+
instance_write(:meta, meta_encode({}))
|
28
12
|
end
|
13
|
+
super
|
14
|
+
end
|
29
15
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
16
|
+
def post_process_styles(*styles)
|
17
|
+
super(*styles)
|
18
|
+
assign_meta
|
19
|
+
end
|
34
20
|
|
35
|
-
|
36
|
-
|
37
|
-
|
21
|
+
# Use meta info for style if required
|
22
|
+
def size(style = nil)
|
23
|
+
style ? read_meta(style, :size) : super()
|
24
|
+
end
|
38
25
|
|
39
|
-
|
40
|
-
|
41
|
-
|
26
|
+
def height(style = default_style)
|
27
|
+
read_meta style, :height
|
28
|
+
end
|
42
29
|
|
43
|
-
|
44
|
-
|
45
|
-
|
30
|
+
def width(style = default_style)
|
31
|
+
read_meta style, :width
|
32
|
+
end
|
46
33
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
"#{width(style)}x#{height(style)}"
|
51
|
-
end
|
34
|
+
def aspect_ratio(style = default_style)
|
35
|
+
width(style).to_f / height(style).to_f
|
36
|
+
end
|
52
37
|
|
53
|
-
|
38
|
+
# Return image dimesions ("WxH") for given style name. If style name not given,
|
39
|
+
# return dimesions for default_style.
|
40
|
+
def image_size(style = default_style)
|
41
|
+
"#{width(style)}x#{height(style)}"
|
42
|
+
end
|
54
43
|
|
55
|
-
|
56
|
-
return unless instance.respond_to?(:"#{name}_meta=")
|
44
|
+
private
|
57
45
|
|
58
|
-
|
59
|
-
|
46
|
+
def assign_meta
|
47
|
+
return unless instance.respond_to?(:"#{name}_meta=")
|
48
|
+
meta = populate_meta(@queued_for_write)
|
49
|
+
return if meta == {}
|
60
50
|
|
61
|
-
|
62
|
-
|
51
|
+
write_meta(meta)
|
52
|
+
end
|
63
53
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
54
|
+
def populate_meta(queue)
|
55
|
+
meta = {}
|
56
|
+
queue.each do |style, file|
|
57
|
+
begin
|
58
|
+
geo = Geometry.from_file file
|
59
|
+
meta[style] = { width: geo.width.to_i, height: geo.height.to_i, size: file.size }
|
60
|
+
rescue Paperclip::Errors::NotIdentifiedByImageMagickError
|
61
|
+
meta[style] = {}
|
73
62
|
end
|
74
|
-
meta
|
75
63
|
end
|
64
|
+
meta
|
65
|
+
end
|
76
66
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
67
|
+
def write_meta(meta)
|
68
|
+
merge_existing_meta_hash meta
|
69
|
+
instance.send("#{name}_meta=", meta_encode(meta))
|
70
|
+
end
|
81
71
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
72
|
+
# Return meta data for given style
|
73
|
+
def read_meta(style, item)
|
74
|
+
if instance.respond_to?(:"#{name}_meta") && instance_read(:meta)
|
75
|
+
if (meta = meta_decode(instance_read(:meta)))
|
76
|
+
meta[style] && meta[style][item]
|
88
77
|
end
|
89
78
|
end
|
79
|
+
end
|
90
80
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
81
|
+
# Return encoded metadata as String
|
82
|
+
def meta_encode(meta)
|
83
|
+
Base64.encode64(Marshal.dump(meta))
|
84
|
+
end
|
95
85
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
86
|
+
# Return decoded metadata as Object
|
87
|
+
def meta_decode(meta)
|
88
|
+
Marshal.load(Base64.decode64(meta))
|
89
|
+
end
|
100
90
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
91
|
+
# Retain existing meta values that will not be recalculated when
|
92
|
+
# reprocessing a subset of styles
|
93
|
+
def merge_existing_meta_hash(meta)
|
94
|
+
return unless (original_meta = instance.send("#{name}_meta"))
|
95
|
+
meta.reverse_merge! meta_decode(original_meta)
|
107
96
|
end
|
108
97
|
end
|
109
98
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-meta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Bondar
|
@@ -17,70 +17,70 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '5.0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
27
|
+
version: '5.0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: bundler
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '1.
|
34
|
+
version: '1.13'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '1.
|
41
|
+
version: '1.13'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '11.
|
48
|
+
version: '11.3'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '11.
|
55
|
+
version: '11.3'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: mocha
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '1.
|
62
|
+
version: '1.2'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '1.
|
69
|
+
version: '1.2'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: activerecord
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - "
|
74
|
+
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
76
|
+
version: '5.0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- - "
|
81
|
+
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: '
|
83
|
+
version: '5.0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: sqlite3
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,28 +101,56 @@ dependencies:
|
|
101
101
|
requirements:
|
102
102
|
- - "~>"
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: '
|
104
|
+
version: '3.0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '3.0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: activesupport
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '5.0'
|
105
119
|
type: :development
|
106
120
|
prerelease: false
|
107
121
|
version_requirements: !ruby/object:Gem::Requirement
|
108
122
|
requirements:
|
109
123
|
- - "~>"
|
110
124
|
- !ruby/object:Gem::Version
|
111
|
-
version: '
|
125
|
+
version: '5.0'
|
112
126
|
- !ruby/object:Gem::Dependency
|
113
127
|
name: activejob
|
114
128
|
requirement: !ruby/object:Gem::Requirement
|
115
129
|
requirements:
|
116
|
-
- - "
|
130
|
+
- - "~>"
|
117
131
|
- !ruby/object:Gem::Version
|
118
|
-
version: '
|
132
|
+
version: '5.0'
|
119
133
|
type: :development
|
120
134
|
prerelease: false
|
121
135
|
version_requirements: !ruby/object:Gem::Requirement
|
122
136
|
requirements:
|
123
|
-
- - "
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '5.0'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: railties
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - "~>"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '5.0'
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - "~>"
|
124
152
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
153
|
+
version: '5.0'
|
126
154
|
description: Add width, height and size methods to paperclip images
|
127
155
|
email:
|
128
156
|
- y8@ya.ru
|
@@ -149,7 +177,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
177
|
requirements:
|
150
178
|
- - ">="
|
151
179
|
- !ruby/object:Gem::Version
|
152
|
-
version: 2.
|
180
|
+
version: 2.2.2
|
153
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
182
|
requirements:
|
155
183
|
- - ">="
|