Class: Epuber::Compiler::FileFinders::Imaginary

Inherits:
Abstract
  • Object
show all
Defined in:
lib/epuber/compiler/file_finders/imaginary.rb

Defined Under Namespace

Classes: DirEntry, FileEntry

Instance Attribute Summary collapse

Attributes inherited from Abstract

#ignored_patterns, #source_path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

#assert_one_file, #find_all, #find_file, #find_files, group_filter_paths, relative_paths_from

Constructor Details

#initialize(source_path) ⇒ Imaginary

Returns a new instance of Imaginary.



59
60
61
62
63
64
# File 'lib/epuber/compiler/file_finders/imaginary.rb', line 59

def initialize(source_path)
  super
  @root = DirEntry.new('/')

  make_dir_p(File.expand_path(source_path))
end

Instance Attribute Details

#rootDirEntry (readonly)

Returns:



57
58
59
# File 'lib/epuber/compiler/file_finders/imaginary.rb', line 57

def root
  @root
end

Class Method Details

.path_parts(path) ⇒ Object



111
112
113
# File 'lib/epuber/compiler/file_finders/imaginary.rb', line 111

def path_parts(path)
  path.split(File::SEPARATOR).reject(&:empty?)
end

Instance Method Details

#__core_file?(path) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
102
103
104
105
106
107
108
# File 'lib/epuber/compiler/file_finders/imaginary.rb', line 99

def __core_file?(path)
  components = self.class.path_parts(path)

  current = root
  components.each do |dir|
    current = current.respond_to?(:[]) ? current[dir] : nil
  end

  current.is_a?(FileEntry)
end

#__core_find_files_from_pattern(pattern) ⇒ Object



92
93
94
95
96
97
# File 'lib/epuber/compiler/file_finders/imaginary.rb', line 92

def __core_find_files_from_pattern(pattern)
  parts = self.class.path_parts(pattern)
  found_entries = find_recurser(root, parts).flatten
  file_entries = found_entries.reject { |entry| entry.is_a?(DirEntry) }
  file_entries.map(&:absolute_path)
end

#add_file(file_path) ⇒ Object

Parameters:



84
85
86
87
88
89
90
# File 'lib/epuber/compiler/file_finders/imaginary.rb', line 84

def add_file(file_path)
  file_path = File.expand_path(file_path, source_path)

  *path, file_name = self.class.path_parts(file_path)

  make_dir_p(path)[file_name] = FileEntry.new(file_name, file_path)
end

#make_dir_p(path) ⇒ DirEntry

Returns dir entry for given path.

Parameters:

  • path (String | Array<String>)

    path to folder to create

Returns:

  • (DirEntry)

    dir entry for given path



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/epuber/compiler/file_finders/imaginary.rb', line 70

def make_dir_p(path)
  components = path.is_a?(Array) ? path : self.class.path_parts(path)

  current = root
  components.each do |dir|
    entry        = current[dir]
    current[dir] = entry = DirEntry.new(dir) if entry.nil?
    current      = entry
  end

  current
end