Class: Expressir::Express::Parser
- Inherits:
-
Object
- Object
- Expressir::Express::Parser
- Defined in:
- lib/expressir/express/parser.rb
Defined Under Namespace
Classes: Parser
Class Method Summary collapse
-
.from_file(file, skip_references: nil, include_source: nil) ⇒ Model::Repository
Parses Express file into an Express model.
-
.from_files(files, skip_references: nil, include_source: nil) ⇒ Model::Repository
Parses Express files into an Express model.
Class Method Details
.from_file(file, skip_references: nil, include_source: nil) ⇒ Model::Repository
Parses Express file into an Express model
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
# File 'lib/expressir/express/parser.rb', line 427 def self.from_file(file, skip_references: nil, include_source: nil) source = File.read file ast = Parser.new.parse source visitor = Expressir::Express::Visitor.new(source, include_source: include_source) transformed = visitor.visit_ast ast, :top @repository = transformed @repository.schemas.each do |schema| schema.file = file.to_s end unless skip_references @resolve_references_model_visitor = ResolveReferencesModelVisitor.new @resolve_references_model_visitor.visit(@repository) end @repository end |
.from_files(files, skip_references: nil, include_source: nil) ⇒ Model::Repository
Parses Express files into an Express model
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/expressir/express/parser.rb', line 452 def self.from_files(files, skip_references: nil, include_source: nil) schemas = files.each_with_index.map do |file, _i| # start = Time.now repository = from_file(file, skip_references: true) # STDERR.puts "#{i+1}/#{files.length} #{file} #{Time.now - start}" repository.schemas end.flatten @repository = Model::Repository.new( schemas: schemas, ) unless @skip_references @resolve_references_model_visitor = ResolveReferencesModelVisitor.new @resolve_references_model_visitor.visit(@repository) end @repository end |