Skip to content

Commit

Permalink
refactor: the parser method was too complicated to read
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-mesnilgrente committed Jul 17, 2024
1 parent ca6632d commit a7d1ea2
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions app/models/abstract_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,33 @@ def enqueue

def parser
return @parser if @parser.present?

if version_id.present?
@parser = ParserVersion.find(version_id, params: { parser_id: })
@parser = find_parser_from_version_id
elsif environment.present? && !preview?
version = ParserVersion.find(:one, from: :current, params: { parser_id:, environment: })
version.parser_id = parser_id
self.version_id = version.id if version.present?
@parser = version
@parser = find_parser_from_current
else
parser = Parser.find(parser_id)
parser.content = parser_code if parser_code.present?
@parser = parser
@parser = find_parser_from_parser_id
end
end

def find_parser_from_version_id
ParserVersion.find(version_id, params: { parser_id: })
end

def find_parser_from_current
version = ParserVersion.find(:one, from: :current, params: { parser_id:, environment: })
version.parser_id = parser_id
self.version_id = version.id if version.present?
version
end

def find_parser_from_parser_id
parser = Parser.find(parser_id)
parser.content = parser_code if parser_code.present?
parser
end

def required_enrichments
parser.enrichment_definitions(environment).dup.keep_if do |_name, options|
options[:required_for_active_record]
Expand Down

0 comments on commit a7d1ea2

Please sign in to comment.