module SheepAst::LetInclude

This class is for the action to recprd the result

Public Instance Methods

dir_path() click to toggle source
# File lib/sheep_ast/action/let_include.rb, line 19
def dir_path
  val = @data_store.value(:_sheep_dir_path)
  return val.nil? ? [] : val
end
exclude_dir_path() click to toggle source
# File lib/sheep_ast/action/let_include.rb, line 25
def exclude_dir_path
  val = @data_store.value(:_sheep_exclude_dir_path)
  return val.nil? ? [] : val
end
include(pair, datastore, key_id, range = 1..-2, **options) click to toggle source
# File lib/sheep_ast/action/let_include.rb, line 50
def include(pair, datastore, key_id, range = 1..-2, **options)
  str = pair[key_id]
  relative_path = T.must(T.must(str)[range]).join
  ldebug? and ldebug "let include is called with #{relative_path.inspect}"

  file = find_next_file(relative_path)

  if !file.nil?
    save_req = SaveRequest.new(
      file: file,
      ast_include: options[:ast_include],
      ast_exclude: options[:ast_exclude],
      namespace: nil
    )
    @data.save_request = save_req
  end

  return T.unsafe(self).ret(**options)
end

Private Instance Methods

exclude_file?(file) click to toggle source
# File lib/sheep_ast/action/let_include.rb, line 73
def exclude_file?(file)
  return false if file.nil?

  exclude_dir_path.each do |epath|
    rp = Regexp.new("#{File.expand_path(epath)}/*")

    if !rp.match(file).nil? # rubocop:disable all
      t_file = file.split('/').last
      ldump "[EXCLUDE] #{t_file}", :yellow
      return true
    end
  end
  return false
end
find_next_file(relative_path) click to toggle source
# File lib/sheep_ast/action/let_include.rb, line 89
def find_next_file(relative_path)
  file = find_file(dir_path, relative_path)
  if file.nil?
    ldump "[NOT FOUND] #{relative_path}", :red
  end

  res = exclude_file?(file) ? nil : file
  return res
end