Class: Goku::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/goku/path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_path) ⇒ Path



7
8
9
# File 'lib/goku/path.rb', line 7

def initialize(raw_path)
  @full= raw_path
end

Instance Attribute Details

#fullObject (readonly)

Returns the value of attribute full.



5
6
7
# File 'lib/goku/path.rb', line 5

def full
  @full
end

Instance Method Details

#directoriesObject



15
16
17
# File 'lib/goku/path.rb', line 15

def directories
  File.dirname(full).split("/")
end

#exists?Boolean



11
12
13
# File 'lib/goku/path.rb', line 11

def exists?
  File.exists?(full)
end

#extensionObject



23
24
25
# File 'lib/goku/path.rb', line 23

def extension
  File.extname(full)
end

#filenameObject



19
20
21
# File 'lib/goku/path.rb', line 19

def filename
  File.basename(full, extension)
end

#implementation?Boolean



31
32
33
# File 'lib/goku/path.rb', line 31

def implementation?
  !spec?
end

#spec?Boolean Also known as: test?



27
28
29
# File 'lib/goku/path.rb', line 27

def spec?
  directories.first == "spec"
end

#to_implementationObject



41
42
43
44
45
# File 'lib/goku/path.rb', line 41

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_specObject



35
36
37
38
39
# File 'lib/goku/path.rb', line 35

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