Class: TRuby::DeclarationLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/t_ruby/declaration_generator.rb

Overview

Loader for managing declaration files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDeclarationLoader

Returns a new instance of DeclarationLoader.



232
233
234
235
236
# File 'lib/t_ruby/declaration_generator.rb', line 232

def initialize
  @search_paths = []
  @loaded_declarations = DeclarationParser.new
  @loaded_files = Set.new
end

Instance Attribute Details

#search_pathsObject (readonly)

Returns the value of attribute search_paths.



230
231
232
# File 'lib/t_ruby/declaration_generator.rb', line 230

def search_paths
  @search_paths
end

Instance Method Details

#add_search_path(path) ⇒ Object

Add a search path for declaration files



239
240
241
242
# File 'lib/t_ruby/declaration_generator.rb', line 239

def add_search_path(path)
  @search_paths << path unless @search_paths.include?(path)
  self
end

#declarationsObject

Get the combined declarations



281
282
283
# File 'lib/t_ruby/declaration_generator.rb', line 281

def declarations
  @loaded_declarations
end

#functionsObject

Get all loaded functions



306
307
308
# File 'lib/t_ruby/declaration_generator.rb', line 306

def functions
  @loaded_declarations.functions
end

#interfacesObject

Get all loaded interfaces



301
302
303
# File 'lib/t_ruby/declaration_generator.rb', line 301

def interfaces
  @loaded_declarations.interfaces
end

#load(name) ⇒ Object

Load a specific declaration file by name (without extension)



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/t_ruby/declaration_generator.rb', line 245

def load(name)
  file_name = "#{name}#{DeclarationGenerator::DECLARATION_EXTENSION}"

  @search_paths.each do |path|
    full_path = File.join(path, file_name)
    next unless 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

  false
end

#load_allObject

Load all declaration files from search paths



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/t_ruby/declaration_generator.rb', line 263

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_filesObject

Get list of loaded files



311
312
313
# File 'lib/t_ruby/declaration_generator.rb', line 311

def loaded_files
  @loaded_files.to_a
end

#resolve_type(name) ⇒ Object

Resolve a type from loaded declarations



291
292
293
# File 'lib/t_ruby/declaration_generator.rb', line 291

def resolve_type(name)
  @loaded_declarations.resolve_type(name)
end

#type_aliasesObject

Get all loaded type aliases



296
297
298
# File 'lib/t_ruby/declaration_generator.rb', line 296

def type_aliases
  @loaded_declarations.type_aliases
end

#type_defined?(name) ⇒ Boolean

Check if a type is defined in any loaded declaration

Returns:



286
287
288
# File 'lib/t_ruby/declaration_generator.rb', line 286

def type_defined?(name)
  @loaded_declarations.type_defined?(name)
end