Class: Shog::Path
Class Attribute Summary collapse
-
.pwd ⇒ Object
Returns the value of attribute pwd.
Instance Attribute Summary collapse
-
#absolute ⇒ Object
readonly
Returns the value of attribute absolute.
-
#outoftree ⇒ Object
readonly
Returns the value of attribute outoftree.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #dir ⇒ Object
-
#initialize(path, outoftree, absolute = false) ⇒ Path
constructor
A new instance of Path.
- #to_str ⇒ Object
- #with_suffix(suffix) ⇒ Object
Constructor Details
#initialize(path, outoftree, absolute = false) ⇒ Path
Returns a new instance of Path.
15 16 17 18 19 |
# File 'lib/path.rb', line 15 def initialize(path, outoftree, absolute = false) @path = path @outoftree = outoftree @absolute = absolute end |
Class Attribute Details
.pwd ⇒ Object
Returns the value of attribute pwd.
8 9 10 |
# File 'lib/path.rb', line 8 def pwd @pwd end |
Instance Attribute Details
#absolute ⇒ Object (readonly)
Returns the value of attribute absolute.
11 12 13 |
# File 'lib/path.rb', line 11 def absolute @absolute end |
#outoftree ⇒ Object (readonly)
Returns the value of attribute outoftree.
11 12 13 |
# File 'lib/path.rb', line 11 def outoftree @outoftree end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/path.rb', line 11 def path @path end |
Class Method Details
.make(path, params = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/path.rb', line 25 def self.make(path, params = {}) if path.is_a?(String) abolute = false if params.key?(:absolute) and params[:absolute] path = File.(path) absolute = true elsif not params.key?(:root) and not params[:root] path = File.join(Path.pwd, path) end path = Path.normalize(path) outoftree = if params.key?(:outoftree) params[:outoftree] else false # by default we assume input file end return Path.new(path, outoftree, absolute) elsif path.is_a?(Path) if params.key?(:outoftree) and params[:outoftree] != path.outoftree return Path.new(path.path, params[:outoftree]) else return path end elsif path.is_a?(PathSet) return self.make(path.single_path, params) else raise "Cannot make path from #{path}" end end |
.normalize(path) ⇒ Object
21 22 23 |
# File 'lib/path.rb', line 21 def self.normalize(path) Pathname.new(path).cleanpath.to_s end |
Instance Method Details
#dir ⇒ Object
54 55 56 57 |
# File 'lib/path.rb', line 54 def dir path = File.dirname(@path) Path.new(path, @outoftree) end |
#to_str ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/path.rb', line 63 def to_str # as we build files by ninja from inside outoftree directory then outs should not have any prefixes, but inputs should be accessed by '../' if @outoftree or @absolute @path else File.join("..", @path) end end |