Class: Ecic::SourceFileInfo
- Inherits:
-
Object
- Object
- Ecic::SourceFileInfo
- Defined in:
- lib/ecic/source_file_info.rb
Overview
Class that can provide various info about what do to with a source file.
Constant Summary collapse
- STANDARD_LIBRARY_FOLDERS_LIST =
["src/design", "src/testbench"]
Instance Attribute Summary collapse
-
#absolute_path ⇒ Object
readonly
Returns the value of attribute absolute_path.
-
#library ⇒ Object
readonly
Returns the value of attribute library.
Instance Method Summary collapse
-
#find_sources_file_dir(dir = @relative_path_from_project.dirname) ⇒ Object
Function that looks for a sources.rb file within the project.
-
#get_default_library_dir_from_file_path ⇒ Object
Function that returns the name of the directory that is placed just under src/design or src/testbench:.
-
#get_library_from_file_path ⇒ Object
TBA: Make sure this function works for libraries under src/testbench as well and make sure it returns nil, if the library name cannot be determined.
-
#get_library_type_from_file_path ⇒ Object
Function that returns the type of library that.
-
#initialize(project, file_name, library = nil) ⇒ SourceFileInfo
constructor
A new instance of SourceFileInfo.
- #is_outside_project? ⇒ Boolean
- #sources_file_path ⇒ Object
Constructor Details
#initialize(project, file_name, library = nil) ⇒ SourceFileInfo
Returns a new instance of SourceFileInfo.
11 12 13 14 15 16 |
# File 'lib/ecic/source_file_info.rb', line 11 def initialize(project, file_name, library=nil) @project = project @absolute_path = Pathname.new(File.(file_name)) @relative_path_from_project = @absolute_path.relative_path_from(Pathname.new("#{@project.root}")) @library = library || get_library_from_file_path end |
Instance Attribute Details
#absolute_path ⇒ Object (readonly)
Returns the value of attribute absolute_path.
7 8 9 |
# File 'lib/ecic/source_file_info.rb', line 7 def absolute_path @absolute_path end |
#library ⇒ Object (readonly)
Returns the value of attribute library.
7 8 9 |
# File 'lib/ecic/source_file_info.rb', line 7 def library @library end |
Instance Method Details
#find_sources_file_dir(dir = @relative_path_from_project.dirname) ⇒ Object
Function that looks for a sources.rb file within the project
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ecic/source_file_info.rb', line 56 def find_sources_file_dir(dir = @relative_path_from_project.dirname) return nil if is_outside_project? file = File.join(@project.root, dir, "sources.rb") if dir.root? or dir.to_s == "." return nil elsif File.exists?(file) return dir else return find_sources_file_dir(dir.parent) end end |
#get_default_library_dir_from_file_path ⇒ Object
Function that returns the name of the directory that is placed just under src/design or src/testbench:
69 70 71 72 73 74 75 |
# File 'lib/ecic/source_file_info.rb', line 69 def get_default_library_dir_from_file_path #Get the first directory name after src/design or src/testbench: rel_design_path_list = @relative_path_from_project.to_s.split('/') return nil if rel_design_path_list.length < 3 return nil unless STANDARD_LIBRARY_FOLDERS_LIST.include? [rel_design_path_list.first(2)].join('/') Pathname.new([rel_design_path_list.first(3)].join('/')) end |
#get_library_from_file_path ⇒ Object
TBA: Make sure this function works for libraries under src/testbench as well and make sure it returns nil, if the library name cannot be determined. TBA: Update this function to first look for any sources.rb files within the project folder structure.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ecic/source_file_info.rb', line 22 def get_library_from_file_path return nil if is_outside_project? sources_file_dir = find_sources_file_dir if sources_file_dir #A sources.rb file was found." #Check if an existing library is already mapped to that folder. If so, return that library #and otherwise return a new library that is named according to the folder already_mapped_lib = @project.library_mapped_to(sources_file_dir.to_s) return already_mapped_lib if already_mapped_lib #Use the name of the folder as the library name:" lib_dir = sources_file_dir else # puts " #Could not find an existing sources.rb file for the given source file" lib_dir = get_default_library_dir_from_file_path end unless lib_dir.nil? lib_name = lib_dir.basename.to_s Ecic::Library.new(@project, lib_name, get_library_type_from_file_path, :path => lib_dir) end end |
#get_library_type_from_file_path ⇒ Object
Function that returns the type of library that
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ecic/source_file_info.rb', line 78 def get_library_type_from_file_path #Get the first directory name after src/design or src/testbench: rel_design_path_list = @relative_path_from_project.to_s.split('/') return nil if rel_design_path_list.length < 2 case [rel_design_path_list.first(2)].join('/') when "src/testbench" return :testbench when "src/design" return :design else return :design end end |
#is_outside_project? ⇒ Boolean
43 44 45 46 |
# File 'lib/ecic/source_file_info.rb', line 43 def is_outside_project? # @relative_path_from_project.to_s.split('/')[0] == ".." /\A\.\./.match(@relative_path_from_project.to_s) end |
#sources_file_path ⇒ Object
92 93 94 95 96 |
# File 'lib/ecic/source_file_info.rb', line 92 def sources_file_path return nil if @library.nil? # puts "#{@library.path}/sources.rb" Pathname.new("#{@library.path}/sources.rb") end |