Class: RbsMacros::Project
- Inherits:
- 
      AbstractProject
      
        - Object
- AbstractProject
- RbsMacros::Project
 
- Defined in:
- lib/rbs_macros/project.rb
Overview
A project based on real FS.
Instance Attribute Summary collapse
- 
  
    
      #base_dir  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute base_dir. 
Instance Method Summary collapse
- #glob(ext:, include:, exclude:, &block) ⇒ Object
- 
  
    
      #initialize(base_dir: Pathname(Dir.pwd))  ⇒ Project 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Project. 
- #read(path) ⇒ Object
- #write(path, content) ⇒ Object
Constructor Details
#initialize(base_dir: Pathname(Dir.pwd)) ⇒ Project
Returns a new instance of Project.
| 33 34 35 36 | # File 'lib/rbs_macros/project.rb', line 33 def initialize(base_dir: Pathname(Dir.pwd)) super() @base_dir = base_dir end | 
Instance Attribute Details
#base_dir ⇒ Object
Returns the value of attribute base_dir.
| 31 32 33 | # File 'lib/rbs_macros/project.rb', line 31 def base_dir @base_dir end | 
Instance Method Details
#glob(ext:, include:, exclude:, &block) ⇒ Object
| 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | # File 'lib/rbs_macros/project.rb', line 38 def glob( ext:, include:, exclude:, &block ) return enum_for(:glob, ext:, include:, exclude:) unless block loaded = Set.new # : Set[String] include.each do |incl_dir| Dir.glob( "#{incl_dir}/**/*#{ext}", base: @base_dir ).sort.each do |path| next unless File.file?(@base_dir + path) next if loaded.include?(path) loaded << path is_excluded = exclude.any? do |excl_dir| "#{path}/".start_with?("#{excl_dir}/") end block.(path) unless is_excluded end end end | 
#read(path) ⇒ Object
| 70 71 72 | # File 'lib/rbs_macros/project.rb', line 70 def read(path) File.read((@base_dir + path).to_s) end | 
#write(path, content) ⇒ Object
| 64 65 66 67 68 | # File 'lib/rbs_macros/project.rb', line 64 def write(path, content) full_path = @base_dir + path FileUtils.mkdir_p(full_path.dirname) File.write(full_path.to_s, content) end |