lib/eco/api/session.rb in eco-helpers-2.0.21 vs lib/eco/api/session.rb in eco-helpers-2.0.22

- old
+ new

@@ -64,10 +64,20 @@ # Helper to state the abilities that a person should have with given their usergroups def presets_factory @presets_factory ||= Eco::API::Organization::PresetsFactory.new(enviro: enviro) end + # @return [Eco::Data::Mapper] the mappings between the internal and external attribute/property names. + def fields_mapper + return @fields_mapper if instance_variable_defined?(:@fields_mapper) + mappings = [] + if map_file = config.people.fields_mapper + mappings = map_file ? file_manager.load_json(map_file) : [] + end + @fields_mapper = Eco::Data::Mapper.new(mappings) + end + # Helper to obtain a EntryFactory # @param schema [String, Ecoportal::API::V1::PersonSchema] `schema` to which associate the EntryFactory, # where `String` can be the _name_ or the _id_ of the schema. # @return [Eco::API::Common::People::EntryFactory] associated to `schema`. # If `schema` is `nil` or not provided it uses the currently associated to the `session` @@ -77,18 +87,14 @@ unless @entry_factories.empty? @entry_factories[schema&.id] = @entry_factories.values.first.newFactory(schema: schema) return @entry_factories[schema&.id] end - mappings = [] - if map_file = config.people.fields_mapper - mappings = map_file ? file_manager.load_json(map_file) : [] - end @entry_factories[schema&.id] = Eco::API::Common::People::EntryFactory.new( enviro, schema: schema, person_parser: config.people.parser, - attr_map: Eco::Data::Mapper.new(mappings) + attr_map: fields_mapper ) end # Helper to obtain a PersonFactory # @param schema [String, Ecoportal::API::V1::PersonSchema] `schema` to which associate the PersonFactory,