Class: Utopia::Gallery::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/gallery/process.rb

Direct Known Subclasses

ResizeImage

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Process

Returns a new instance of Process.



29
30
31
# File 'lib/utopia/gallery/process.rb', line 29

def initialize(name)
	@name = name.to_sym
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



33
34
35
# File 'lib/utopia/gallery/process.rb', line 33

def name
  @name
end

Class Method Details

.fresh?(input_path, output_path) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
# File 'lib/utopia/gallery/process.rb', line 46

def self.fresh?(input_path, output_path)
	# We are not fresh if the output path doesn't exist:
	return false unless File.exist?(output_path)
	
	# We are not fresh if the input is newere than the output:
	return false if mtime(input_path) > mtime(output_path)
	
	# Otherwise, we are so fresh:
	return true
end


57
58
59
60
61
# File 'lib/utopia/gallery/process.rb', line 57

def self.link(input_path, output_path)
	# Compute a path to input_path, relative to output_path
	shortest_path = Utopia::Path.shortest_path(input_path, output_path)
	FileUtils.ln_s(shortest_path, output_path, force: true)
end

.mtime(path) ⇒ Object



42
43
44
# File 'lib/utopia/gallery/process.rb', line 42

def self.mtime(path)
	File.lstat(path).mtime
end

Instance Method Details

#relative_path(media) ⇒ Object

The relative path for the output generated by this process, given a specific input media:



36
37
38
39
40
# File 'lib/utopia/gallery/process.rb', line 36

def relative_path(media)
	source_path = media.path
	
	File.join(File.dirname(source_path), @name.to_s, File.basename(source_path))
end