Method: Configuration::FileSource#realize

Defined in:
lib/httpimagestore/configuration/file.rb

#realize(request_state) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/httpimagestore/configuration/file.rb', line 80

def realize(request_state)
	put_sourced_named_image(request_state) do |image_name, rendered_path|
		storage_path = storage_path(rendered_path)

		log.info "sourcing '#{image_name}' from file '#{storage_path}'"
		begin
			data = storage_path.open('rb') do |io|
				request_state.memory_limit.io io
				io.read
			end
			FileSourceStoreBase.stats.incr_total_file_source
			FileSourceStoreBase.stats.incr_total_file_source_bytes(data.bytesize)

			image = Image.new(data)
			image.source_url = file_url(rendered_path)
			image
		rescue Errno::ENOENT
			raise NoSuchFileError.new(image_name, rendered_path)
		end
	end
end