module Confinement::Easier
Public Instance Methods
concat(*parts)
click to toggle source
Pathname#join and File.join behave very differently
-
Pathname.new(“foo”).join(“/bar”) # => Pathname.new(“/bar”)
-
File.join(“foo”, “/bar”) # => “foo/bar”
# File lib/confinement.rb, line 45 def concat(*parts) Pathname.new(File.join(self, *parts)) end
frontmatter_and_body(strip: true)
click to toggle source
# File lib/confinement.rb, line 57 def frontmatter_and_body(strip: true) matches = FRONTMATTER_REGEX.match(self) return [{}, self] if matches["frontmatter"].nil? frontmatter = YAML.load(matches["frontmatter"], symbolize_names: true) body = matches["body"] || "" body = body.strip if strip [frontmatter, body] rescue ArgumentError [{}, self] end
include?(other)
click to toggle source
# File lib/confinement.rb, line 49 def include?(other) difference = other.relative_path_from(self) !PATH_INCLUDE_PATH_REGEX.match?(difference.to_s) end
normalize_for_route()
click to toggle source
# File lib/confinement.rb, line 71 def normalize_for_route "/#{self}".squeeze("/") end