Class: Configuration::FileSourceStoreBase

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

Direct Known Subclasses

FileSource, FileStore

Instance Attribute Summary

Attributes inherited from HandlerStatement

#config_locals

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from HandlerStatement

#config_local, #path_template

Constructor Details

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

Returns a new instance of FileSourceStoreBase.



44
45
46
47
# File 'lib/httpimagestore/configuration/file.rb', line 44

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

Class Method Details

.parse(configuration, node) ⇒ Object



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

def self.parse(configuration, node)
  image_name = node.grab_values('image name').first
  node.required_attributes('root', 'path')
  root_dir, path_spec, if_image_name_on = *node.grab_attributes('root', 'path', 'if-image-name-on')
  matcher = InclusionMatcher.new(image_name, if_image_name_on)

  self.new(
    configuration.global,
    image_name,
    matcher,
    root_dir,
    path_spec
  )
end

Instance Method Details

#file_url(rendered_path) ⇒ Object



58
59
60
61
62
# File 'lib/httpimagestore/configuration/file.rb', line 58

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

#storage_path(rendered_path) ⇒ Object



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

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



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

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