class Warp::Dir::Point
This class encapsulates the tuple: name + path. It provides convenience accessors to retrieve absolute or realtive path of a point, optionally via a set of predefined filters.
In addition, this class is responsible for serializing and deserializing itself properly.
Attributes
full_path[RW]
Instance Methods
name[RW]
Instance Methods
Public Class Methods
deserialize(line)
click to toggle source
# File lib/warp/dir/point.rb, line 27 def self.deserialize(line) name, path = line.split(/:/) if name.nil? || path.nil? raise Warp::Dir::Errors::StoreFormatError.new( "warprc file may be corrupt, offending line is: #{line}", line) end self.new(name, path) end
filtered_paths(path_hash)
click to toggle source
This method creates/defines methods used to access the full_path
component of the Point
instance, but enclosing it in a chain of provided filters.
# File lib/warp/dir/point.rb, line 17 def self.filtered_paths(path_hash) path_hash.each_pair do |method, filters| define_method method.to_sym do |*args| filters.inject(self.full_path) do |memo, filter| self.send(filter, memo) end end end end
new(name, full_path)
click to toggle source
# File lib/warp/dir/point.rb, line 45 def initialize(name, full_path) raise ArgumentError.new ':name is required' if name.nil? raise ArgumentError.new ':full_path is required' if full_path.nil? @full_path = Warp::Dir.absolute full_path @name = name.to_sym end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/warp/dir/point.rb, line 72 def <=>(other) name <=> other.name end
==(another)
click to toggle source
# File lib/warp/dir/point.rb, line 76 def ==(another) return false unless another.is_a?(Warp::Dir::Point) %i(name full_path).each do |attribute| return false unless send(attribute) == another.send(attribute) end true end
Also aliased as: eql?
exist?()
click to toggle source
# File lib/warp/dir/point.rb, line 52 def exist? ::Dir.exist?(full_path) end
hash()
click to toggle source
# File lib/warp/dir/point.rb, line 68 def hash Digest::SHA1.base64digest("#{full_path.hash}#{name.hash}").hash end
inspect()
click to toggle source
# File lib/warp/dir/point.rb, line 60 def inspect sprintf("(#{object_id})[name: '%s', path: '%s']", name, relative_path) end
missing?()
click to toggle source
# File lib/warp/dir/point.rb, line 56 def missing? !exist? end
serialize()
click to toggle source
# File lib/warp/dir/point.rb, line 87 def serialize "#{name}:#{full_path}" end
to_s(width = 0)
click to toggle source
# File lib/warp/dir/point.rb, line 64 def to_s(width = 0) sprintf("%#{width}s -> %s", name, relative_path) end
Private Instance Methods
make_relative(path)
click to toggle source
Filters that receive a path, and return a possibly decorated path back
# File lib/warp/dir/point.rb, line 94 def make_relative(path) Warp::Dir.relative(path) end
quote_spaces(path)
click to toggle source
# File lib/warp/dir/point.rb, line 98 def quote_spaces(path) path =~ /\s+/ ? %Q("#{path}") : path end