lib/image_processing/chainable.rb in image_processing-1.1.0 vs lib/image_processing/chainable.rb in image_processing-1.2.0

- old
+ new

@@ -14,25 +14,30 @@ def saver(**options) branch saver: options end - def apply(operations) - operation :apply, operations - end - def custom(&block) operation :custom, block end - def method_missing(name, *args) - if name.to_s.end_with?("!") - send(name.to_s.chomp("!"), *args).call - elsif name.to_s.end_with?("?") - super - else - operation(name, *args) + def apply(operations) + operations.inject(self) do |builder, (name, argument)| + if argument == true || argument == nil + builder.send(name) + elsif argument.is_a?(Array) + builder.send(name, *argument) + else + builder.send(name, argument) + end end + end + + def method_missing(name, *args) + return super if name.to_s.end_with?("?") + return send(name.to_s.chomp("!"), *args).call if name.to_s.end_with?("!") + + operation name, *args end def operation(name, *args) branch operations: [[name, args]] end