module StrongLikeBull

Constants

VERSION

Public Instance Methods

log_suggested_strong_parameters_format(key) click to toggle source
# File lib/strong_like_bull.rb, line 4
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
suggested_strong_parameters_format(key) click to toggle source
# File lib/strong_like_bull.rb, line 8
def suggested_strong_parameters_format(key)
  hash = params.respond_to?(:to_unsafe_h) ? params.to_unsafe_h : params
  hash = hash[key]
  recursive_suggested_strong_parameters_format(hash) if hash
end

Private Instance Methods

recursive_suggested_strong_parameters_format(object) click to toggle source
# File lib/strong_like_bull.rb, line 15
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