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

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.



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

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

  make_dir_p(File.expand_path(source_path))
end

Instance Attribute Details

#rootDirEntry (readonly)

Returns:



54
55
56
# File 'lib/epuber/compiler/file_finders/imaginary.rb', line 54

def root
  @root
end

Instance Method Details

#__core_file?(path) ⇒ Boolean

Returns:

  • (Boolean)


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

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



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

def __core_find_files_from_pattern(pattern)
  parts = self.class.path_parts(pattern)
  find_recurser(root, parts).flatten.map do |item|
    item.absolute_path
  end
end

#add_file(file_path) ⇒ Object

Parameters:



81
82
83
84
85
86
87
# File 'lib/epuber/compiler/file_finders/imaginary.rb', line 81

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



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/epuber/compiler/file_finders/imaginary.rb', line 67

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