Class: Configuration::FileSourceStoreBase

Inherits:
SourceStoreBase show all
Extended by:
Stats
Includes:
PerfStats
Defined in:
lib/httpimagestore/configuration/file.rb

Direct Known Subclasses

FileSource, FileStore

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Scope

node_parsers, #parse, register_node_parser

Constructor Details

#initialize(global, image_name, root_dir, path_spec) ⇒ FileSourceStoreBase

Returns a new instance of FileSourceStoreBase.



49
50
51
52
# File 'lib/httpimagestore/configuration/file.rb', line 49

def initialize(global, image_name, root_dir, path_spec)
	super(global, image_name, path_spec)
	@root_dir = Pathname.new(root_dir).cleanpath
end

Class Method Details

.parse(configuration, node) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/httpimagestore/configuration/file.rb', line 30

def self.parse(configuration, node)
	image_name = node.grab_values('image name').first
	node.required_attributes('root', 'path')

	# TODO: it should be possible to compact that
	root_dir, path_spec, remaining = *node.grab_attributes_with_remaining('root', 'path')
	conditions, remaining = *ConditionalInclusion.grab_conditions_with_remaining(remaining)
	remaining.empty? or raise UnexpectedAttributesError.new(node, remaining)

	file = self.new(
		configuration.global,
		image_name,
		root_dir,
		path_spec
	)
	file.with_conditions(conditions)
	file
end

Instance Method Details

#file_url(rendered_path) ⇒ Object



63
64
65
66
67
# File 'lib/httpimagestore/configuration/file.rb', line 63

def file_url(rendered_path)
	uri = rendered_path.to_uri
	uri.scheme = 'file'
	uri
end

#storage_path(rendered_path) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/httpimagestore/configuration/file.rb', line 54

def storage_path(rendered_path)
	path = Pathname.new(rendered_path)

	storage_path = (@root_dir + path).cleanpath
	storage_path.to_s =~ /^#{@root_dir.to_s}/ or raise FileStorageOutsideOfRootDirError.new(image_name, path)

	storage_path
end

#to_sObject



69
70
71
# File 'lib/httpimagestore/configuration/file.rb', line 69

def to_s
	"FileSource[image_name: '#{image_name}' root_dir: '#{@root_dir}' path_spec: '#{path_spec}']"
end