Class: TRuby::DeclarationLoader
- Inherits:
-
Object
- Object
- TRuby::DeclarationLoader
- Defined in:
- lib/t_ruby/declaration_generator.rb
Overview
Loader for managing declaration files
Instance Attribute Summary collapse
-
#search_paths ⇒ Object
readonly
Returns the value of attribute search_paths.
Instance Method Summary collapse
-
#add_search_path(path) ⇒ Object
Add a search path for declaration files.
-
#declarations ⇒ Object
Get the combined declarations.
-
#functions ⇒ Object
Get all loaded functions.
-
#initialize ⇒ DeclarationLoader
constructor
A new instance of DeclarationLoader.
-
#interfaces ⇒ Object
Get all loaded interfaces.
-
#load(name) ⇒ Object
Load a specific declaration file by name (without extension).
-
#load_all ⇒ Object
Load all declaration files from search paths.
-
#loaded_files ⇒ Object
Get list of loaded files.
-
#resolve_type(name) ⇒ Object
Resolve a type from loaded declarations.
-
#type_aliases ⇒ Object
Get all loaded type aliases.
-
#type_defined?(name) ⇒ Boolean
Check if a type is defined in any loaded declaration.
Constructor Details
#initialize ⇒ DeclarationLoader
Returns a new instance of DeclarationLoader.
215 216 217 218 219 |
# File 'lib/t_ruby/declaration_generator.rb', line 215 def initialize @search_paths = [] @loaded_declarations = DeclarationParser.new @loaded_files = Set.new end |
Instance Attribute Details
#search_paths ⇒ Object (readonly)
Returns the value of attribute search_paths.
213 214 215 |
# File 'lib/t_ruby/declaration_generator.rb', line 213 def search_paths @search_paths end |
Instance Method Details
#add_search_path(path) ⇒ Object
Add a search path for declaration files
222 223 224 225 |
# File 'lib/t_ruby/declaration_generator.rb', line 222 def add_search_path(path) @search_paths << path unless @search_paths.include?(path) self end |
#declarations ⇒ Object
Get the combined declarations
264 265 266 |
# File 'lib/t_ruby/declaration_generator.rb', line 264 def declarations @loaded_declarations end |
#functions ⇒ Object
Get all loaded functions
289 290 291 |
# File 'lib/t_ruby/declaration_generator.rb', line 289 def functions @loaded_declarations.functions end |
#interfaces ⇒ Object
Get all loaded interfaces
284 285 286 |
# File 'lib/t_ruby/declaration_generator.rb', line 284 def interfaces @loaded_declarations.interfaces end |
#load(name) ⇒ Object
Load a specific declaration file by name (without extension)
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/t_ruby/declaration_generator.rb', line 228 def load(name) file_name = "#{name}#{DeclarationGenerator::DECLARATION_EXTENSION}" @search_paths.each do |path| full_path = File.join(path, file_name) if File.exist?(full_path) && !@loaded_files.include?(full_path) parser = DeclarationParser.new parser.parse_file(full_path) @loaded_declarations.merge(parser) @loaded_files.add(full_path) return true end end false end |
#load_all ⇒ Object
Load all declaration files from search paths
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/t_ruby/declaration_generator.rb', line 246 def load_all @search_paths.each do |path| next unless Dir.exist?(path) Dir.glob(File.join(path, "*#{DeclarationGenerator::DECLARATION_EXTENSION}")).each do |file| next if @loaded_files.include?(file) parser = DeclarationParser.new parser.parse_file(file) @loaded_declarations.merge(parser) @loaded_files.add(file) end end self end |
#loaded_files ⇒ Object
Get list of loaded files
294 295 296 |
# File 'lib/t_ruby/declaration_generator.rb', line 294 def loaded_files @loaded_files.to_a end |
#resolve_type(name) ⇒ Object
Resolve a type from loaded declarations
274 275 276 |
# File 'lib/t_ruby/declaration_generator.rb', line 274 def resolve_type(name) @loaded_declarations.resolve_type(name) end |
#type_aliases ⇒ Object
Get all loaded type aliases
279 280 281 |
# File 'lib/t_ruby/declaration_generator.rb', line 279 def type_aliases @loaded_declarations.type_aliases end |
#type_defined?(name) ⇒ Boolean
Check if a type is defined in any loaded declaration
269 270 271 |
# File 'lib/t_ruby/declaration_generator.rb', line 269 def type_defined?(name) @loaded_declarations.type_defined?(name) end |