Class: Toys::SourceInfo
- Inherits:
-
Object
- Object
- Toys::SourceInfo
- Defined in:
- toys-core/lib/toys/source_info.rb
Overview
Defined in the toys-core gem
Information about the source of a tool, such as the file, git repository, or block that defined it.
Instance Attribute Summary collapse
-
#context_directory ⇒ String?
readonly
The context directory path (normally the directory containing the toplevel toys file or directory).
-
#git_commit ⇒ String?
readonly
The git commit.
-
#git_path ⇒ String?
readonly
The git path.
-
#git_remote ⇒ String?
readonly
The git remote.
-
#parent ⇒ Toys::SourceInfo?
readonly
The parent of this SourceInfo.
-
#priority ⇒ Integer
readonly
The priority of tools defined by this source.
-
#root ⇒ Toys::SourceInfo
readonly
The root ancestor of this SourceInfo.
-
#source ⇒ String, Proc
readonly
The source, which may be a path or a proc.
-
#source_name ⇒ String
(also: #to_s)
readonly
The user-visible name of this source.
-
#source_path ⇒ String?
readonly
The path of the current source file or directory.
-
#source_proc ⇒ Proc?
readonly
The source proc.
-
#source_type ⇒ :file, ...
readonly
Return the type of source.
Instance Method Summary collapse
-
#apply_lib_paths ⇒ self
Apply all lib paths in order from high to low priority.
-
#find_data(path, type: nil) ⇒ String?
Locate the given data file or directory and return an absolute path.
Instance Attribute Details
#context_directory ⇒ String? (readonly)
The context directory path (normally the directory containing the toplevel toys file or directory).
66 67 68 |
# File 'toys-core/lib/toys/source_info.rb', line 66 def context_directory @context_directory end |
#git_commit ⇒ String? (readonly)
The git commit.
121 122 123 |
# File 'toys-core/lib/toys/source_info.rb', line 121 def git_commit @git_commit end |
#git_path ⇒ String? (readonly)
The git path.
113 114 115 |
# File 'toys-core/lib/toys/source_info.rb', line 113 def git_path @git_path end |
#git_remote ⇒ String? (readonly)
The git remote.
105 106 107 |
# File 'toys-core/lib/toys/source_info.rb', line 105 def git_remote @git_remote end |
#parent ⇒ Toys::SourceInfo? (readonly)
The parent of this SourceInfo.
41 42 43 |
# File 'toys-core/lib/toys/source_info.rb', line 41 def parent @parent end |
#priority ⇒ Integer (readonly)
The priority of tools defined by this source. Higher values indicate a higher priority. Lower priority values could be negative.
56 57 58 |
# File 'toys-core/lib/toys/source_info.rb', line 56 def priority @priority end |
#root ⇒ Toys::SourceInfo (readonly)
The root ancestor of this SourceInfo.
48 49 50 |
# File 'toys-core/lib/toys/source_info.rb', line 48 def root @root end |
#source ⇒ String, Proc (readonly)
The source, which may be a path or a proc.
74 75 76 |
# File 'toys-core/lib/toys/source_info.rb', line 74 def source @source end |
#source_name ⇒ String (readonly) Also known as: to_s
The user-visible name of this source.
128 129 130 |
# File 'toys-core/lib/toys/source_info.rb', line 128 def source_name @source_name end |
#source_path ⇒ String? (readonly)
The path of the current source file or directory.
89 90 91 |
# File 'toys-core/lib/toys/source_info.rb', line 89 def source_path @source_path end |
#source_proc ⇒ Proc? (readonly)
The source proc.
97 98 99 |
# File 'toys-core/lib/toys/source_info.rb', line 97 def source_proc @source_proc end |
#source_type ⇒ :file, ... (readonly)
Return the type of source.
81 82 83 |
# File 'toys-core/lib/toys/source_info.rb', line 81 def source_type @source_type end |
Instance Method Details
#apply_lib_paths ⇒ self
Apply all lib paths in order from high to low priority
160 161 162 163 164 |
# File 'toys-core/lib/toys/source_info.rb', line 160 def apply_lib_paths parent&.apply_lib_paths $LOAD_PATH.unshift(@lib_dir) if @lib_dir && !$LOAD_PATH.include?(@lib_dir) self end |
#find_data(path, type: nil) ⇒ String?
Locate the given data file or directory and return an absolute path.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'toys-core/lib/toys/source_info.rb', line 140 def find_data(path, type: nil) if @data_dir full_path = ::File.join(@data_dir, path) case type when :file return full_path if ::File.file?(full_path) when :directory return full_path if ::File.directory?(full_path) else return full_path if ::File.readable?(full_path) end end parent&.find_data(path, type: type) end |