class Compath::Guide

Attributes

pathname[R]
scan_children[R]

Public Class Methods

new(path, scan: true, desc: nil) click to toggle source
# File lib/compath/guide.rb, line 8
def initialize(path, scan: true, desc: nil)
  # claenpath is for dirty configurated guide
  @pathname = Pathname.new(path).cleanpath
  @scan_children = scan
  @description = desc
end

Public Instance Methods

ancestors() click to toggle source
# File lib/compath/guide.rb, line 21
def ancestors
  ancestors = []
  pathname.ascend do |path|
    next if path == pathname
    ancestors << self.class.new(path.to_path)
  end
  ancestors
end
children() click to toggle source
# File lib/compath/guide.rb, line 15
def children
  pathname.children.map do |child|
    self.class.new(child.to_path)
  end
end
to_object() click to toggle source
# File lib/compath/guide.rb, line 30
def to_object
  { object_key => object_value }
end

Private Instance Methods

has_directory_child?() click to toggle source
# File lib/compath/guide.rb, line 52
def has_directory_child?
  pathname.children.any?(&:directory?)
end
object_key() click to toggle source
# File lib/compath/guide.rb, line 36
def object_key
  if directory?
    if !has_directory_child? || @scan_children
      pathname.to_s + '/'
    else
      pathname.to_s + '/**/*'
    end
  else
    pathname.to_s
  end
end
object_value() click to toggle source
# File lib/compath/guide.rb, line 48
def object_value
  @description
end