class Goku::Path

Attributes

full[R]

Public Class Methods

new(raw_path) click to toggle source
# File lib/goku/path.rb, line 7
def initialize(raw_path)
  @full= raw_path
end

Public Instance Methods

directories() click to toggle source
# File lib/goku/path.rb, line 21
def directories
  File.dirname(full).split("/")
end
exists?() click to toggle source
# File lib/goku/path.rb, line 17
def exists?
  File.exists?(full)
end
extension() click to toggle source
# File lib/goku/path.rb, line 29
def extension
  File.extname(full)
end
filename() click to toggle source
# File lib/goku/path.rb, line 25
def filename
  File.basename(full, extension)
end
implementation?() click to toggle source
# File lib/goku/path.rb, line 37
def implementation?
  !spec?
end
spec?() click to toggle source
# File lib/goku/path.rb, line 33
def spec?
  directories.first == "spec"
end
Also aliased as: test?
test?()
Alias for: spec?
to_implementation() click to toggle source
# File lib/goku/path.rb, line 47
def to_implementation
  raise Goku::PathConversionError.new("Path is already an implementation") if implementation?

  Goku::Path.new(File.join([directories.drop(1), "#{filename.gsub(/_spec$/, "")}#{extension}"]))
end
to_spec() click to toggle source
# File lib/goku/path.rb, line 41
def to_spec
  raise Goku::PathConversionError.new("Path is already a specification") if spec?

  Goku::Path.new(File.join(["spec", directories, "#{filename}_spec#{extension}"]))
end
write(content) click to toggle source
# File lib/goku/path.rb, line 11
def write(content)
  FileUtils.mkdir_p(File.dirname(full))

  File.write(full, "#{content}\n")
end