Sha256: 2b05e8e05e309a48ffaf6831e4f9d3dc29405a11a7ccb22e2f9ac5681d774d3d

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

require "strong_like_bull/version"

module StrongLikeBull
  def log_suggested_strong_parameters_format(key)
    Rails.logger.info "STRONG PARAMETERS: #{self.class}##{action_name} - suggested format: params.require(:#{key}).permit  #{suggested_strong_parameters_format key}"
  end

  def suggested_strong_parameters_format(key)
    hash = params[key]
    recursive_suggested_strong_parameters_format(hash) if hash
  end

  private
  def recursive_suggested_strong_parameters_format(object)
    if object.is_a? Hash
      if object.keys.first.match(/^\d+$/)
        hash = {}
        object.values.each do |value|
          hash.deep_merge!(value)
        end
        ret = recursive_suggested_strong_parameters_format(hash)
        ret << :id unless ret.include?(:id)
        ret
      else
        permitted_params = []
        object.each do |key, value|
          if value.is_a?(Hash) || value.is_a?(Array)
            permitted_params << {:"#{key}" => recursive_suggested_strong_parameters_format(value)}
          else
            permitted_params << :"#{key}"
          end
        end
        permitted_params
      end
    elsif object.is_a?(Array)
      if object.first.is_a?(Hash)
        hash = {}
        object.each do |value|
          hash.deep_merge!(value)
        end
        recursive_suggested_strong_parameters_format(hash)
      else
        []
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
strong_like_bull-0.0.1 lib/strong_like_bull.rb