Sha256: 933db85515324de7a5154d3f58297c426f15b87e833d5c591d7d2e56436e1608

Contents?: true

Size: 707 Bytes

Versions: 9

Compression:

Stored size: 707 Bytes

Contents

# frozen_string_literal: true

module PiResources
  module ParamsHelpers
    extend ActiveSupport::Concern

    def request_params
      request.request_parameters.to_h.deep_symbolize_keys
    end

    def query_params
      res = request.query_parameters.deep_transform_keys(&:underscore).deep_symbolize_keys

      parse_query_params(res)
    end

    private

    def parse_query_params(val)
      case val
      when ->(v) { v.is_a?(Hash) }
        val.transform_values do |val2|
          parse_query_params(val2)
        end
      when ->(v) { v.is_a?(Array) }
        val.map { |v| parse_query_params(v) }
      when 'null', 'undefined'
        nil
      else
        val
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pi-resources-rails-0.6.3 lib/pi_resources/params_helpers.rb
pi-resources-rails-0.6.2 lib/pi_resources/params_helpers.rb
pi-resources-rails-0.6.1 lib/pi_resources/params_helpers.rb
pi-resources-rails-0.6.0 lib/pi_resources/params_helpers.rb
pi-resources-rails-0.5.0 lib/pi_resources/params_helpers.rb
pi-resources-rails-0.4.4 lib/pi_resources/params_helpers.rb
pi-resources-rails-0.4.3 lib/pi_resources/params_helpers.rb
pi-resources-rails-0.4.2 lib/pi_resources/params_helpers.rb
pi-resources-rails-0.4.1 lib/pi_resources/params_helpers.rb