Sha256: 6f543ff47a99f1ea9d79700c94b22e7e329f7ece7c447d2ae99229d06c915f98

Contents?: true

Size: 894 Bytes

Versions: 3

Compression:

Stored size: 894 Bytes

Contents

# frozen_string_literal: true

module BeyondCanvas
  class ParameterSanitizer # :nodoc:
    DEFAULT_PERMITTED_ATTRIBUTES = %i[code signature return_url api_url access_token_url].freeze

    def initialize(resource_name, params)
      @params         = params
      @resource_name  = resource_name
      @permitted      = DEFAULT_PERMITTED_ATTRIBUTES
    end

    def sanitize
      permit_keys(default_params)
    end

    def permit(*keys)
      @permitted.concat(keys)
    end

    private

    def default_params
      if hashable_resource_params?
        @params.fetch(@resource_name)
      else
        empty_params
      end
    end

    def hashable_resource_params?
      @params[@resource_name].respond_to?(:permit)
    end

    def empty_params
      ActionController::Parameters.new({})
    end

    def permit_keys(parameters)
      parameters.permit(*@permitted)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
beyond_canvas-0.16.2.pre lib/beyond_canvas/parameter_sanitizer.rb
beyond_canvas-0.16.1.pre lib/beyond_canvas/parameter_sanitizer.rb
beyond_canvas-0.16.0.pre lib/beyond_canvas/parameter_sanitizer.rb