Sha256: 697638230651b155138dbfdf3e2c03fd62b88a99f63ab91388ee7c7322062088

Contents?: true

Size: 812 Bytes

Versions: 15

Compression:

Stored size: 812 Bytes

Contents

# frozen_string_literal: true

module Aserto
  module ResourceMapper
    class << self
      def execute(request)
        if defined? ::Rails
          params = request.params
          return {} unless params.is_a?(Hash) && !params.empty?

          require_relative "rails/utils"

          route = Aserto::Rails::Utils.route(request)
          path = route[:path] if route
          return {} unless path

          fields = path.split("/")
                       .select { |part| part.starts_with?(":") }
                       .map { |field| field.sub(":", "") }
          return {} if fields.empty?

          require "google/protobuf/well_known_types"
          return Google::Protobuf::Struct.from_hash(fields.to_h { |field| [field, params[field]] })

        end

        {}
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
aserto-0.31.3 lib/aserto/resource_mapper.rb
aserto-0.31.2 lib/aserto/resource_mapper.rb
aserto-0.31.1 lib/aserto/resource_mapper.rb
aserto-0.31.0 lib/aserto/resource_mapper.rb
aserto-0.30.6 lib/aserto/resource_mapper.rb
aserto-0.30.5 lib/aserto/resource_mapper.rb
aserto-0.30.4 lib/aserto/resource_mapper.rb
aserto-0.30.1 lib/aserto/resource_mapper.rb
aserto-0.30.0 lib/aserto/resource_mapper.rb
aserto-0.20.6 lib/aserto/resource_mapper.rb
aserto-0.20.5 lib/aserto/resource_mapper.rb
aserto-0.20.4 lib/aserto/resource_mapper.rb
aserto-0.20.3 lib/aserto/resource_mapper.rb
aserto-0.20.2 lib/aserto/resource_mapper.rb
aserto-0.0.6 lib/aserto/resource_mapper.rb