Class: Paths::PathnameWrap

Inherits:
Object
  • Object
show all
Includes:
Albacore::Logging
Defined in:
lib/albacore/paths.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Albacore::Logging

#debug, #err, #error, #fatal, #info, #puts, #trace, #warn

Constructor Details

#initialize(p) ⇒ PathnameWrap

Returns a new instance of PathnameWrap.

Raises:

  • (ArgumentError)


70
71
72
73
74
# File 'lib/albacore/paths.rb', line 70

def initialize p
  raise ArgumentError, 'p is nil' if p.nil?
  @p = (p.is_a?(String) ? p : p.to_s)
  @inner = Pathname.new @p
end

Instance Attribute Details

#innerObject (readonly)

inner pathname



65
66
67
# File 'lib/albacore/paths.rb', line 65

def inner
  @inner
end

#pObject (readonly)

string pathname



68
69
70
# File 'lib/albacore/paths.rb', line 68

def p
  @p
end

Instance Method Details

#+(other) ⇒ Object



80
81
82
# File 'lib/albacore/paths.rb', line 80

def +(other)
  join other
end

#==(o) ⇒ Object Also known as: eql?



93
94
95
96
# File 'lib/albacore/paths.rb', line 93

def ==(o)
  trace { "#{self} ==( #{o} )" }
  (o.respond_to? :p) && o.p == p
end

#as_unixObject

unwraps the pathname; defaults all return forward slashes



105
106
107
# File 'lib/albacore/paths.rb', line 105

def as_unix
  to_s.gsub /\\/, '/'
end

#hashObject



100
101
102
# File 'lib/albacore/paths.rb', line 100

def hash
  p.hash
end

#join(*other) ⇒ Object



84
85
86
87
# File 'lib/albacore/paths.rb', line 84

def join *other
  args = other.collect { |x| x.is_a?(PathnameWrap) ? x.p : x }
  PathnameWrap.new(inner.join(*args))
end

#parentObject



76
77
78
# File 'lib/albacore/paths.rb', line 76

def parent
  PathnameWrap.new(inner.parent)
end

#to_sObject



89
90
91
# File 'lib/albacore/paths.rb', line 89

def to_s
  ::Albacore::Paths.normalise_slashes p
end