Class: Configuration::FileSource

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FileSourceStoreBase

#initialize, #storage_path, #to_s

Methods inherited from SourceStoreBase

#initialize

Methods included from ConditionalInclusion

#excluded?, #included?, #inclusion_matcher

Constructor Details

This class inherits a constructor from Configuration::FileSourceStoreBase

Class Method Details

.match(node) ⇒ Object



67
68
69
# File 'lib/httpimagestore/configuration/file.rb', line 67

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

.parse(configuration, node) ⇒ Object



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

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

Instance Method Details

#realize(request_state) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/httpimagestore/configuration/file.rb', line 75

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://#{URI.encode(rendered_path.to_s)}"
			image
		rescue Errno::ENOENT
			raise NoSuchFileError.new(image_name, rendered_path)
		end
	end
end