lib/eco/api/session.rb in eco-helpers-3.0.19 vs lib/eco/api/session.rb in eco-helpers-3.0.20

- old
+ new

@@ -68,10 +68,11 @@ **kargs, &block ) if live && api?(version: :graphql) return live_tree(include_archived: include_archived, **kargs, &block) unless merge + live_trees(include_archived: include_archived, **kargs, &block).inject(&:merge) else config.tagtree(recache: recache) end end @@ -116,14 +117,16 @@ 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, @@ -164,13 +167,13 @@ # @param source [Any] source value to be parsed. # @param phase [Symbol] the phase when this parser should be active. # @param phase [Symbol] the phase when this parser should be active. # @return [Object] the parsed attribute. def parse_attribute(attr, source, phase = :internal, deps: {}) - unless (parsers = entry_factory.person_parser) - raise "There are no parsers defined" - end + msg = "There are no parsers defined" + raise msg unless (parsers = entry_factory.person_parser) + parsers.parse(attr, source, phase, deps: deps) end # @see Eco::API::Common::People::EntryFactory#export # @param (see Eco::API::Common::People::EntryFactory#export) @@ -388,21 +391,22 @@ schema_1 && schema_2 && eq end # from schema `id` or `name` to a PersonSchema object def to_schema(value) - return nil unless value sch = nil + return unless value + case value when String - unless (sch = schemas.schema(value)) - fatal "The schema with id or name '#{value}' does not exist." - end + msg = "The schema with id or name '#{value}' does not exist." + fatal msg unless (sch = schemas.schema(value)) when Ecoportal::API::V1::PersonSchema sch = value else fatal "Required String or Ecoportal::API::V1::PersonSchema. Given: #{value}" end + sch end end end end