lib/aserto.rb in aserto-0.0.4 vs lib/aserto.rb in aserto-0.0.5

- old
+ new

@@ -49,10 +49,20 @@ # { resource: request.path_info } # end def with_resource_mapper Aserto::ResourceMapper.class_eval do |klass| klass.define_singleton_method(:execute) do |request| - yield(request) if block_given? + if block_given? + result = yield(request) + unless result.is_a?(Hash) + raise Aserto::InvalidResourceMapping, "block must return a hash, got: #{result.class}" + end + + require "google/protobuf/well_known_types" + + result.transform_keys!(&:to_s) + Google::Protobuf::Struct.from_hash(result) + end end end end # Allows the initializer to provide a custom