Class: ImageOptim::ImagePath
- Inherits:
-
FSPath
- Object
- FSPath
- ImageOptim::ImagePath
- Defined in:
- lib/image_optim/image_path.rb
Defined Under Namespace
Classes: Optimized
Class Method Summary collapse
-
.convert(path) ⇒ Object
Returns path if it is already an instance of this class otherwise new instance.
Instance Method Summary collapse
-
#copy(dst) ⇒ Object
Copy file to dest preserving attributes.
-
#format ⇒ Object
Get format using ImageSize.
-
#replace(src) ⇒ Object
Atomic replace src with self.
-
#temp_path(*args, &block) ⇒ Object
Get temp path for this file with same extension.
Class Method Details
.convert(path) ⇒ Object
Returns path if it is already an instance of this class otherwise new instance
58 59 60 |
# File 'lib/image_optim/image_path.rb', line 58 def self.convert(path) path.is_a?(self) ? path : new(path) end |
Instance Method Details
#copy(dst) ⇒ Object
Copy file to dest preserving attributes
35 36 37 |
# File 'lib/image_optim/image_path.rb', line 35 def copy(dst) FileUtils.copy_file(self, dst, true) end |
#format ⇒ Object
Get format using ImageSize
51 52 53 54 55 |
# File 'lib/image_optim/image_path.rb', line 51 def format if = ImageMeta.for_path(self) .format end end |
#replace(src) ⇒ Object
Atomic replace src with self
40 41 42 43 44 45 46 47 48 |
# File 'lib/image_optim/image_path.rb', line 40 def replace(src) src = self.class.new(src) src.temp_path(src.dirname) do |temp| src.copy(temp) temp.write(read) temp.rename(src.to_s) unlink end end |
#temp_path(*args, &block) ⇒ Object
Get temp path for this file with same extension
29 30 31 32 |
# File 'lib/image_optim/image_path.rb', line 29 def temp_path(*args, &block) ext = extname self.class.temp_file_path([basename(ext), ext], *args, &block) end |