Skip to content

Commit

Permalink
feat: delay loading of Expressir content to prevent early crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldtse committed Jun 9, 2024
1 parent d4223f0 commit e145a0d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
18 changes: 12 additions & 6 deletions lib/suma/express_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ module Suma
class ExpressSchema
attr_accessor :path, :id, :parsed, :output_path

def initialize(path:, output_path:)
def initialize(id:, path:, output_path:)
@path = Pathname.new(path).expand_path
@parsed = Expressir::Express::Parser.from_file(@path.to_s)
Utils.log "Loaded EXPRESS schema: #{path}"

@id = @parsed.schemas.first.id
@id = id
@output_path = output_path
end

Expand All @@ -28,8 +25,17 @@ def type
end
end

def parsed
return @parsed if @parsed

@parsed = Expressir::Express::Parser.from_file(@path.to_s)
Utils.log "Loaded EXPRESS schema: #{path}"
@id = @parsed.schemas.first.id
@parsed
end

def to_plain
@parsed.to_s(no_remarks: true)
parsed.to_s(no_remarks: true)
end

def filename_plain
Expand Down
5 changes: 3 additions & 2 deletions lib/suma/schema_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ def doc_from_schema_name(schema_name)
def finalize
@config.schemas.each do |config_schema|
s = ExpressSchema.new(
path: config_schema.path,
output_path: @output_path_schemas
id: config_schema.id,
path: config_schema.path.to_s,
output_path: @output_path_schemas.to_s
)

klass = config_schema.schemas_only ? SchemaDocument : SchemaAttachment
Expand Down

0 comments on commit e145a0d

Please sign in to comment.