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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83a7b543e2c71c134090200014b76b5e87ee553b
4
- data.tar.gz: b0b453d2274dd3925ef748a9fbb7a2cef2b6baf6
3
+ metadata.gz: 8cac54df8108f1301db4a4535e94ee4a75112dc0
4
+ data.tar.gz: 733c91235143bf498cca2c8adb188c5587bc10b8
5
5
  SHA512:
6
- metadata.gz: 757fed3a6f85fe6f40df1cf42abbdc831a3ddd81126512b22a9e2de36f83b376eebfbfe224ddc1877b8c02f0f72266d79fab00e55b76622a71999fd69d6842b8
7
- data.tar.gz: 13a55a132372cb2ebdb9061a2f8c1bf74f268d1e9c055eb7a900c245772b811aba41fc37ba064beb147171f08723340e5515ac3252d33d86191f5b7e53917214
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 self.included(base)
5
- base.send :include, InstanceMethods
6
- base.alias_method_chain :assign_attributes, :meta_data
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
- module InstanceMethods
13
- def assign_attributes_with_meta_data
14
- assign_attributes_without_meta_data
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
- # Use meta info for style if required
31
- def size_with_meta_data(style = nil)
32
- style ? read_meta(style, :size) : size_without_meta_data
33
- end
16
+ def post_process_styles(*styles)
17
+ super(*styles)
18
+ assign_meta
19
+ end
34
20
 
35
- def height(style = default_style)
36
- read_meta style, :height
37
- end
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
- def width(style = default_style)
40
- read_meta style, :width
41
- end
26
+ def height(style = default_style)
27
+ read_meta style, :height
28
+ end
42
29
 
43
- def aspect_ratio(style = default_style)
44
- width(style).to_f / height(style).to_f
45
- end
30
+ def width(style = default_style)
31
+ read_meta style, :width
32
+ end
46
33
 
47
- # Return image dimesions ("WxH") for given style name. If style name not given,
48
- # return dimesions for default_style.
49
- def image_size(style = default_style)
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
- private
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
- def assign_meta
56
- return unless instance.respond_to?(:"#{name}_meta=")
44
+ private
57
45
 
58
- meta = populate_meta(@queued_for_write)
59
- return if meta == {}
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
- write_meta(meta)
62
- end
51
+ write_meta(meta)
52
+ end
63
53
 
64
- def populate_meta(queue)
65
- meta = {}
66
- queue.each do |style, file|
67
- begin
68
- geo = Geometry.from_file file
69
- meta[style] = { width: geo.width.to_i, height: geo.height.to_i, size: file.size }
70
- rescue Paperclip::Errors::NotIdentifiedByImageMagickError
71
- meta[style] = {}
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
- def write_meta(meta)
78
- merge_existing_meta_hash meta
79
- instance.send("#{name}_meta=", meta_encode(meta))
80
- end
67
+ def write_meta(meta)
68
+ merge_existing_meta_hash meta
69
+ instance.send("#{name}_meta=", meta_encode(meta))
70
+ end
81
71
 
82
- # Return meta data for given style
83
- def read_meta(style, item)
84
- if instance.respond_to?(:"#{name}_meta") && instance_read(:meta)
85
- if (meta = meta_decode(instance_read(:meta)))
86
- meta[style] && meta[style][item]
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
- # Return encoded metadata as String
92
- def meta_encode(meta)
93
- Base64.encode64(Marshal.dump(meta))
94
- end
81
+ # Return encoded metadata as String
82
+ def meta_encode(meta)
83
+ Base64.encode64(Marshal.dump(meta))
84
+ end
95
85
 
96
- # Return decoded metadata as Object
97
- def meta_decode(meta)
98
- Marshal.load(Base64.decode64(meta))
99
- end
86
+ # Return decoded metadata as Object
87
+ def meta_decode(meta)
88
+ Marshal.load(Base64.decode64(meta))
89
+ end
100
90
 
101
- # Retain existing meta values that will not be recalculated when
102
- # reprocessing a subset of styles
103
- def merge_existing_meta_hash(meta)
104
- return unless (original_meta = instance.send("#{name}_meta"))
105
- meta.reverse_merge! meta_decode(original_meta)
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
@@ -12,7 +12,7 @@ module Paperclip
12
12
 
13
13
  class Railtie
14
14
  def self.insert
15
- Paperclip::Attachment.send(:include, Paperclip::Meta::Attachment)
15
+ Paperclip::Attachment.prepend Paperclip::Meta::Attachment
16
16
  end
17
17
  end
18
18
  end
@@ -1,5 +1,5 @@
1
1
  module Paperclip
2
2
  module Meta
3
- VERSION = "2.0.2"
3
+ VERSION = "3.0.0"
4
4
  end
5
5
  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: 2.0.2
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: '4.0'
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: '4.0'
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.10'
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.10'
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.0'
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.0'
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.0'
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.0'
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: '4.2'
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: '4.2'
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: '2.9'
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: '2.9'
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: '4.2'
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: '4.2'
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.0.0
180
+ version: 2.2.2
153
181
  required_rubygems_version: !ruby/object:Gem::Requirement
154
182
  requirements:
155
183
  - - ">="