lib/eco/api/common/people/entry_factory.rb in eco-helpers-1.0.8 vs lib/eco/api/common/people/entry_factory.rb in eco-helpers-1.0.9

- old
+ new

@@ -17,24 +17,35 @@ fatal "Expecting Mapper object. Given: #{fields_mapper}" if attr_map && !attr_map.is_a?(Eco::Data::Mapper) @logger = logger @schema = Ecoportal::API::V1::PersonSchema.new(JSON.parse(schema.doc.to_json)) - default_parser = Eco::API::Common::People::DefaultParsers.new(schema: @schema) - @person_parser = default_parser.merge(person_parser) + @source_person_parser = person_parser + @person_parser = Eco::API::Common::People::DefaultParsers.new(schema: @schema) + @person_parser = @person_parser.merge(@source_person_parser) + @person_parser_patch_version = @source_person_parser.patch_version + @attr_map = attr_map end + def person_parser + if @person_parser_patch_version < @source_person_parser.patch_version + @person_parser.merge(@source_person_parser) + @person_parser_patch_version = @source_person_parser.patch_version + end + @person_parser + end + # key method to generate objects of `PersonEntry` that share dependencies via this `EntryFactory` environment. # @note this method is necessary to make the factory object work as a if it was a class `PersonEntry` you can call `new` on. # @param data [Array<Hash>] data to be parsed. The external hashed entry. # @return [Eco::API::Common::People::PersonEntry] def new(data, dependencies: {}) PersonEntry.new( data, - person_parser: @person_parser, + person_parser: person_parser, attr_map: @attr_map, dependencies: dependencies, logger: @logger ) end @@ -60,11 +71,11 @@ if file arr_hash = [] if Eco::API::Common::Session::FileManager.file_exists?(file) encoding ||= Eco::API::Common::Session::FileManager.encoding(file) file_content = File.read(file, encoding: encoding) - arr_hash = @person_parser.parse(format, file_content) + arr_hash = person_parser.parse(format, file_content) else @logger.warn("File does not exist: #{file}") end entries(data: arr_hash) @@ -103,10 +114,10 @@ data_entries = data.map do |person| self.new(person, dependencies: deps).to_hash end File.open(file, "w", enconding: encoding) do |fd| - fd.write(@person_parser.serialize(format, data_entries)) + fd.write(person_parser.serialize(format, data_entries)) end end end