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

Returns a new instance of 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



21
22
23
# File 'lib/goku/path.rb', line 21

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

#exists?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/goku/path.rb', line 17

def exists?
  File.exists?(full)
end

#extensionObject



29
30
31
# File 'lib/goku/path.rb', line 29

def extension
  File.extname(full)
end

#filenameObject



25
26
27
# File 'lib/goku/path.rb', line 25

def filename
  File.basename(full, extension)
end

#implementation?Boolean

Returns:

  • (Boolean)


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

def implementation?
  !spec?
end

#spec?Boolean Also known as: test?

Returns:

  • (Boolean)


33
34
35
# File 'lib/goku/path.rb', line 33

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

#to_implementationObject



47
48
49
50
51
# 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_specObject



41
42
43
44
45
# 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) ⇒ Object



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

def write(content)
  FileUtils.mkdir_p(File.dirname(full))

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