class CC::Yaml::Nodes::Fetch
Constants
- ABSOLUTE_PATH_ERROR
- EMPTY_PATH_ERROR
- INVALID_URL_ERROR
- PARENT_PATH_ERROR
Public Instance Methods
verify()
click to toggle source
Calls superclass method
# File lib/cc/yaml/nodes/fetch.rb, line 28 def verify if !url.nil? && path.nil? self.path = path_node_from_url(url.value) end error(format(INVALID_URL_ERROR, url.value)) if url && !valid_url?(url.value) validate_path(path.value) if path super end
visit_scalar(_visitor, type, value_node, _implicit = true)
click to toggle source
Calls superclass method
# File lib/cc/yaml/nodes/fetch.rb, line 16 def visit_scalar(_visitor, type, value_node, _implicit = true) if type == :str if valid_url?(value_node.value) self.url = url_node_from_url(value_node.value) else error(format(INVALID_URL_ERROR, value_node.value)) end else super end end
Private Instance Methods
path_node_from_url(url)
click to toggle source
# File lib/cc/yaml/nodes/fetch.rb, line 66 def path_node_from_url(url) node = Scalar.new(self) node.value = File.basename(URI.parse(url).path) node end
url_node_from_url(url)
click to toggle source
# File lib/cc/yaml/nodes/fetch.rb, line 60 def url_node_from_url(url) node = Scalar.new(self) node.value = url node end
valid_url?(url)
click to toggle source
# File lib/cc/yaml/nodes/fetch.rb, line 39 def valid_url?(url) uri = URI.parse(url) uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS) rescue URI::InvalidURIError false end
validate_path(path)
click to toggle source
# File lib/cc/yaml/nodes/fetch.rb, line 46 def validate_path(path) if path.nil? || path.length.zero? return error(EMPTY_PATH_ERROR) end pathname = Pathname.new(path) if pathname.absolute? error(format(ABSOLUTE_PATH_ERROR, path)) end if pathname.cleanpath.to_s != pathname.to_s || path.include?("..") error(format(PARENT_PATH_ERROR, path, pathname.cleanpath.to_s)) end end