Class: RbsMacros::FakeProject
- Inherits:
-
AbstractProject
- Object
- AbstractProject
- RbsMacros::FakeProject
- Defined in:
- lib/rbs_macros/project.rb
Overview
An in-memory project.
Instance Method Summary collapse
- #glob(ext:, include:, exclude:, &block) ⇒ Object
-
#initialize ⇒ FakeProject
constructor
A new instance of FakeProject.
- #read(path) ⇒ Object
- #write(path, content) ⇒ Object
Constructor Details
#initialize ⇒ FakeProject
Returns a new instance of FakeProject.
77 78 79 80 |
# File 'lib/rbs_macros/project.rb', line 77 def initialize super @files = {} end |
Instance Method Details
#glob(ext:, include:, exclude:, &block) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/rbs_macros/project.rb', line 82 def glob( ext:, include:, exclude:, &block ) return enum_for(:glob, ext:, include:, exclude:) unless block @files.each_key do |path| has_ext = path.end_with?(ext) is_incl = include.any? do |incl_dir| "#{path}/".start_with?("#{incl_dir}/") end is_excl = exclude.any? do |excl_dir| "#{path}/".start_with?("#{excl_dir}/") end block.(path) if has_ext && is_incl && !is_excl end end |
#read(path) ⇒ Object
106 107 108 |
# File 'lib/rbs_macros/project.rb', line 106 def read(path) @files[path] || raise(Errno::ENOENT, path) end |
#write(path, content) ⇒ Object
102 103 104 |
# File 'lib/rbs_macros/project.rb', line 102 def write(path, content) @files[path] = content end |