Sha256: a1a68f34ff9f7b863cf76f34fe71043829fb393ad11727176bb3bf4c1b687b15

Contents?: true

Size: 835 Bytes

Versions: 38

Compression:

Stored size: 835 Bytes

Contents

# frozen_string_literal: true

require "refinements/pathnames"

module Rubysmith
  # Represents a pathway which has source start and destination end.
  Pathway = Struct.new :start_root, :start_path, :end_root, keyword_init: true do
    using Refinements::Pathnames

    def initialize *arguments
      super
      each_pair { |key, value| self[key] = Pathname value }
      self[:start_path] = start_path.absolute? ? start_path : start_root.join(start_path)
      freeze
    end

    def with(attributes) = self.class.new(to_h.merge(attributes))

    def end_path = end_root.join(from_parent, start_path.basename)

    def partial? = start_path.basename.fnmatch?("_*")

    private

    def from_parent
      return end_root.join start_path.parent if start_path.relative?

      start_path.relative_parent start_root
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
rubysmith-4.9.0 lib/rubysmith/pathway.rb
rubysmith-4.8.0 lib/rubysmith/pathway.rb
rubysmith-4.7.0 lib/rubysmith/pathway.rb
rubysmith-4.6.1 lib/rubysmith/pathway.rb
rubysmith-4.6.0 lib/rubysmith/pathway.rb
rubysmith-4.5.0 lib/rubysmith/pathway.rb
rubysmith-4.4.0 lib/rubysmith/pathway.rb
rubysmith-4.3.0 lib/rubysmith/pathway.rb
rubysmith-4.2.0 lib/rubysmith/pathway.rb
rubysmith-4.1.0 lib/rubysmith/pathway.rb
rubysmith-4.0.1 lib/rubysmith/pathway.rb
rubysmith-4.0.0 lib/rubysmith/pathway.rb
rubysmith-3.8.0 lib/rubysmith/pathway.rb
rubysmith-3.7.0 lib/rubysmith/pathway.rb
rubysmith-3.6.0 lib/rubysmith/pathway.rb
rubysmith-3.5.0 lib/rubysmith/pathway.rb
rubysmith-3.4.0 lib/rubysmith/pathway.rb
rubysmith-3.3.0 lib/rubysmith/pathway.rb
rubysmith-3.2.0 lib/rubysmith/pathway.rb
rubysmith-3.1.0 lib/rubysmith/pathway.rb