Class: ImageProcessing::Pipeline
- Inherits:
-
Object
- Object
- ImageProcessing::Pipeline
- Includes:
- Chainable
- Defined in:
- lib/image_processing/pipeline.rb
Instance Method Summary collapse
- #call!(save: true, destination: nil) ⇒ Object
-
#initialize(options) ⇒ Pipeline
constructor
A new instance of Pipeline.
Methods included from Chainable
#branch, #call, #convert, #custom, #default_options, #loader, #method_missing, #operation, #saver, #source
Constructor Details
#initialize(options) ⇒ Pipeline
Returns a new instance of Pipeline.
7 8 9 |
# File 'lib/image_processing/pipeline.rb', line 7 def initialize() @default_options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ImageProcessing::Chainable
Instance Method Details
#call!(save: true, destination: nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/image_processing/pipeline.rb', line 11 def call!(save: true, destination: nil) fail Error, "source file is not provided" unless [:source] image_class = [:processor]::IMAGE_CLASS if [:source].is_a?(image_class) source = [:source] elsif [:source].is_a?(String) source = [:source] elsif [:source].respond_to?(:path) source = [:source].path elsif [:source].respond_to?(:to_path) source = [:source].to_path else fail Error, "source file needs to respond to #path, or be a String, a Pathname, or a #{image_class} object" end processor = [:processor].new image = processor.load_image(source, [:loader]) [:operations].each do |name, args| if name == :custom image = args.first.call(image) || image else image = processor.apply_operation(name, image, *args) end end return image unless save return processor.save_image(image, destination, [:saver]) if destination source_path = source if source.is_a?(String) format = [:format] || File.extname(source_path.to_s)[1..-1] || "jpg" result = Tempfile.new(["image_processing", ".#{format}"], binmode: true) begin processor.save_image(image, result.path, [:saver]) rescue result.close! raise end result.open result end |