image_processing 1.11.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of image_processing might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e463ca2dcdc1e674b551a94acdfa2495677dd4fd17a79cbaf351727700cddf6
4
- data.tar.gz: 7970e3a7d1d8d70ab3291f7c3e892f1b2ebff9181bb74cc2ff4b1f36f9b39b80
3
+ metadata.gz: 0e86e76046f3b8e0b9fd36a71d52b158a923c75f33848692de1e199ecb17366f
4
+ data.tar.gz: 7267f19b5cb3224a61e04be0a0d3b3f17d353750a1a522a11f2912b9ba49b809
5
5
  SHA512:
6
- metadata.gz: a19939f654334cde66d3ae6c8bb451d1152a1f7e8385507b9649e88b151e99ed6c9005ed861e43c2d9c836327d93699685d74196b92c4b81e38c5d94abe545e5
7
- data.tar.gz: 292f1463f86eae88987dcc2dbe8d8e60ec458f9c33c41c1e1349a5dbadea12ba730ffde697158e239e64c28c14d0d14dc0c617ee439fe7380e73f0135dfecfd7
6
+ metadata.gz: 473958a39a8e760cdb9d352399190f1cdea0dcd915ad729ec740fb7f424dc05041c43fe1085439c0f54763c388b83c2b7dcf32f66cc15caa9dbc0f21c325a166
7
+ data.tar.gz: ac3cc41432e9dc786035f77c721eb1407c84c6307fccc9d8f01f42ca909618229134411f503eeeb770809f620804468750414e6dc8900c442a46d08d3d02e660
@@ -1,3 +1,7 @@
1
+ ## 1.12.0 (2020-09-20)
2
+
3
+ * Add instrumentation support via `#instrumenter` (@janko)
4
+
1
5
  ## 1.11.0 (2020-05-17)
2
6
 
3
7
  * [minimagick] Handle destination format having no file extension (@janko)
data/README.md CHANGED
@@ -148,6 +148,34 @@ You can continue reading the API documentation for specific modules:
148
148
  See the **[wiki]** for additional "How To" guides for common scenarios. The wiki
149
149
  is publicly editable, so you're encouraged to add your own guides.
150
150
 
151
+ ## Instrumentation
152
+
153
+ You can register an `#instrumenter` block for a given pipeline, which will wrap
154
+ the pipeline execution, allowing you to record performance metrics.
155
+
156
+ ```rb
157
+ pipeline = ImageProcessing::Vips.instrumenter do |**options, &processing|
158
+ options[:source] #=> #<File:...>
159
+ options[:loader] #=> { fail: true }
160
+ options[:saver] #=> { quality: 85 }
161
+ options[:format] #=> "png"
162
+ options[:operations] #=> [[:resize_to_limit, 500, 500], [:flip, [:horizontal]]]
163
+ options[:processor] #=> ImageProcessing::Vips::Processor
164
+
165
+ ActiveSupport::Notifications.instrument("process.image_processing", **options) do
166
+ processing.call # calls the pipeline
167
+ end
168
+ end
169
+
170
+ pipeline
171
+ .source(image)
172
+ .loader(fail: true)
173
+ .saver(quality: 85)
174
+ .convert("png")
175
+ .resize_to_limit(500, 500)
176
+ .flip(:horizontal)
177
+ .call # calls instrumenter
178
+ ```
151
179
 
152
180
  ## Contributing
153
181
 
@@ -9,8 +9,24 @@ module ImageProcessing
9
9
  end
10
10
 
11
11
  # Calls the pipeline to perform the processing from built options.
12
- def call!(**options)
13
- Pipeline.new(self.options).call(**options)
12
+ def call!(**call_options)
13
+ instrument do
14
+ Pipeline.new(pipeline_options).call(**call_options)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def instrument
21
+ return yield unless options[:instrumenter]
22
+
23
+ result = nil
24
+ options[:instrumenter].call(**pipeline_options) { result = yield }
25
+ result
26
+ end
27
+
28
+ def pipeline_options
29
+ options.reject { |key, _| key == :instrumenter }
14
30
  end
15
31
  end
16
32
  end
@@ -21,6 +21,11 @@ module ImageProcessing
21
21
  branch saver: options
22
22
  end
23
23
 
24
+ # Register instrumentation block that will be called around the pipeline.
25
+ def instrumenter(&block)
26
+ branch instrumenter: block
27
+ end
28
+
24
29
  # Add multiple operations as a hash or an array.
25
30
  #
26
31
  # .apply(resize_to_limit: [400, 400], strip: true)
@@ -40,16 +45,6 @@ module ImageProcessing
40
45
  end
41
46
  end
42
47
 
43
- # Assume that any unknown method names an operation supported by the
44
- # processor. Add a bang ("!") if you want processing to be performed.
45
- def method_missing(name, *args, &block)
46
- return super if name.to_s.end_with?("?")
47
- return send(name.to_s.chomp("!"), *args, &block).call if name.to_s.end_with?("!")
48
-
49
- operation(name, *args, &block)
50
- end
51
- ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
52
-
53
48
  # Add an operation defined by the processor.
54
49
  def operation(name, *args, &block)
55
50
  branch operations: [[name, args, *block]]
@@ -58,27 +53,41 @@ module ImageProcessing
58
53
  # Call the defined processing and get the result. Allows specifying
59
54
  # the source file and destination.
60
55
  def call(file = nil, destination: nil, **call_options)
61
- options = {}
62
- options = options.merge(source: file) if file
63
- options = options.merge(destination: destination) if destination
56
+ options = { source: file, destination: destination }.compact
64
57
 
65
58
  branch(**options).call!(**call_options)
66
59
  end
67
60
 
68
61
  # Creates a new builder object, merging current options with new options.
69
- def branch(loader: nil, saver: nil, operations: nil, **other_options)
70
- options = respond_to?(:options) ? self.options : DEFAULT_OPTIONS
62
+ def branch(**new_options)
63
+ if self.is_a?(Builder)
64
+ options = self.options
65
+ else
66
+ options = DEFAULT_OPTIONS.merge(processor: self::Processor)
67
+ end
71
68
 
72
- options = options.merge(loader: options[:loader].merge(loader)) if loader
73
- options = options.merge(saver: options[:saver].merge(saver)) if saver
74
- options = options.merge(operations: options[:operations] + operations) if operations
75
- options = options.merge(processor: self::Processor) unless self.is_a?(Builder)
76
- options = options.merge(other_options)
69
+ options = options.merge(new_options) do |key, old_value, new_value|
70
+ case key
71
+ when :loader, :saver then old_value.merge(new_value)
72
+ when :operations then old_value + new_value
73
+ else new_value
74
+ end
75
+ end
76
+
77
+ Builder.new(options.freeze)
78
+ end
79
+
80
+ private
77
81
 
78
- options.freeze
82
+ # Assume that any unknown method names an operation supported by the
83
+ # processor. Add a bang ("!") if you want processing to be performed.
84
+ def method_missing(name, *args, &block)
85
+ return super if name.to_s.end_with?("?")
86
+ return send(name.to_s.chomp("!"), *args, &block).call if name.to_s.end_with?("!")
79
87
 
80
- Builder.new(options)
88
+ operation(name, *args, &block)
81
89
  end
90
+ ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
82
91
 
83
92
  # Empty options which the builder starts with.
84
93
  DEFAULT_OPTIONS = {
@@ -1,3 +1,3 @@
1
1
  module ImageProcessing
2
- VERSION = "1.11.0"
2
+ VERSION = "1.12.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_processing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-17 00:00:00.000000000 Z
11
+ date: 2020-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_magick