Class: Goku::Path
- Inherits:
-
Object
- Object
- Goku::Path
- Defined in:
- lib/goku/path.rb
Instance Attribute Summary collapse
-
#full ⇒ Object
readonly
Returns the value of attribute full.
Instance Method Summary collapse
- #directories ⇒ Object
- #exists? ⇒ Boolean
- #extension ⇒ Object
- #filename ⇒ Object
- #implementation? ⇒ Boolean
-
#initialize(raw_path) ⇒ Path
constructor
A new instance of Path.
- #spec? ⇒ Boolean (also: #test?)
- #to_implementation ⇒ Object
- #to_spec ⇒ Object
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
#full ⇒ Object (readonly)
Returns the value of attribute full.
5 6 7 |
# File 'lib/goku/path.rb', line 5 def full @full end |
Instance Method Details
#directories ⇒ Object
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 |
#extension ⇒ Object
23 24 25 |
# File 'lib/goku/path.rb', line 23 def extension File.extname(full) end |
#filename ⇒ Object
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_implementation ⇒ Object
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_spec ⇒ Object
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 |