Class: Configuration::FileSource

Inherits:
FileSourceStoreBase show all
Includes:
ClassLogging
Defined in:
lib/httpimagestore/configuration/file.rb

Instance Attribute Summary

Attributes inherited from HandlerStatement

#config_locals

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FileSourceStoreBase

#file_url, #initialize, #storage_path, #to_s

Methods inherited from SourceStoreBase

#initialize

Methods inherited from HandlerStatement

#config_local, #initialize, #path_template

Constructor Details

This class inherits a constructor from Configuration::FileSourceStoreBase

Class Method Details

.match(node) ⇒ Object


72
73
74
# File 'lib/httpimagestore/configuration/file.rb', line 72

def self.match(node)
	node.name == 'source_file'
end

.parse(configuration, node) ⇒ Object


76
77
78
# File 'lib/httpimagestore/configuration/file.rb', line 76

def self.parse(configuration, node)
	configuration.sources << super
end

Instance Method Details

#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