module SnakeEyes::InterfaceChanges

Constants

KEYS_ALWAYS_PRESENT

Public Class Methods

included(base) click to toggle source
# File lib/snake_eyes/interface_changes.rb, line 19
def self.included(base)
  base.class_eval do
    alias_method :old_params, :params

    def params(options = {})
      # noinspection RubyResolve
      original_params = old_params

      return original_params unless keys_to_snakeize?(original_params)

      validate_options(options)
      add_nested_attributes!(options)

      return params_from_cache(options) if params_in_cache?(options)

      @snake_eyes_params = transform(original_params, options)

      log(@snake_eyes_params)

      cache!(options, @snake_eyes_params)
    end

    private

    def keys_to_snakeize?(params)
      (params.keys || KEYS_ALWAYS_PRESENT).length > KEYS_ALWAYS_PRESENT.length
    end
  end
end

Public Instance Methods

keys_to_snakeize?(params) click to toggle source
# File lib/snake_eyes/interface_changes.rb, line 43
def keys_to_snakeize?(params)
  (params.keys || KEYS_ALWAYS_PRESENT).length > KEYS_ALWAYS_PRESENT.length
end
params(options = {}) click to toggle source
# File lib/snake_eyes/interface_changes.rb, line 23
def params(options = {})
  # noinspection RubyResolve
  original_params = old_params

  return original_params unless keys_to_snakeize?(original_params)

  validate_options(options)
  add_nested_attributes!(options)

  return params_from_cache(options) if params_in_cache?(options)

  @snake_eyes_params = transform(original_params, options)

  log(@snake_eyes_params)

  cache!(options, @snake_eyes_params)
end