Commit f5d53086 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add implementation of StringPath class

`StringPath` class is something similar to Ruby's `Pathname` class,
but does not involve any IO operations. `StringPath` objects require
passing string representation of path, and array of paths that
represents universe to constructor to be intantiated.
parent f091272f
module Gitlab
##
# Class that represents a path to a file or directory
#
# This is IO-operations safe class, that does similar job to
# Ruby's Pathname but without the risk of accessing filesystem.
#
#
class StringPath
def initialize(path, universe)
@path = path
@universe = universe
end
def absolute?
@path.start_with?('/')
end
def relative?
!absolute?
end
def directory?
@path.end_with?('/')
end
def file?
!directory?
end
def to_s
@path
end
end
end
require 'spec_helper'
describe Gitlab::StringPath do
let(:universe) do
['path/dir_1/',
'path/dir_1/file_1',
'path/second_dir',
'path/second_dir/dir_3/file_2',
'path/second_dir/dir_3/file_3',
'another_file',
'/file/with/absolute_path']
end
describe '/file/with/absolute_path' do
subject { described_class.new('/file/with/absolute_path', universe) }
it { is_expected.to be_absolute }
it { is_expected.to_not be_relative }
it { is_expected.to be_file }
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment