Class: R2OAS::Configuration::PathsConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/r2-oas/configuration/paths_config.rb

Instance Method Summary collapse

Constructor Details

#initialize(root_dir_path, schema_save_dir_name) ⇒ PathsConfig



8
9
10
11
# File 'lib/r2-oas/configuration/paths_config.rb', line 8

def initialize(root_dir_path, schema_save_dir_name)
  @root_dir_path = root_dir_path
  @schema_save_dir_path = "#{root_dir_path}/#{schema_save_dir_name}"
end

Instance Method Details

#abs_paths_pathObject



13
14
15
# File 'lib/r2-oas/configuration/paths_config.rb', line 13

def abs_paths_path
  File.expand_path("#{@root_dir_path}/.paths")
end

#all_load_paths?Boolean



17
18
19
# File 'lib/r2-oas/configuration/paths_config.rb', line 17

def all_load_paths?
  many_paths_file_paths.present?
end

#create_dot_pathsObject



28
29
30
31
32
33
# File 'lib/r2-oas/configuration/paths_config.rb', line 28

def create_dot_paths
  abs_root_path = File.expand_path(@root_dir_path)

  FileUtils.mkdir_p(abs_root_path) unless FileTest.exists?(abs_root_path)
  File.write(abs_paths_path, '') unless FileTest.exists?(abs_paths_path)
end

#many_components_file_pathsObject



35
36
37
38
39
40
41
# File 'lib/r2-oas/configuration/paths_config.rb', line 35

def many_components_file_paths
  @many_components_file_paths ||= many_paths_file_paths.each_with_object([]) do |unit_paths_path, result|
    file_manager = Schema::PathItemFileManager.new(unit_paths_path, :full)
    components_file_paths_at_path = file_manager.descendants_ref_paths
    result.push(*components_file_paths_at_path)
  end.uniq
end

#many_paths_file_pathsObject



21
22
23
24
25
26
# File 'lib/r2-oas/configuration/paths_config.rb', line 21

def many_paths_file_paths
  @many_paths_file_paths ||= File.read(abs_paths_path).split("\n").each_with_object([]) do |relative_path, result|
    abs_path = File.expand_path("#{@schema_save_dir_path}/paths/#{relative_path}")
    result.push(abs_path) if FileTest.exists?(abs_path) && FileTest.file?(abs_path)
  end.uniq.compact.reject(&:empty?)
end