Sha256: 4f146858e31f707ed048ec724b50fd352b71f4fc46179b67422a4acdef4a1af2

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require File.expand_path('configuration', __dir__)
require File.expand_path('memoization', __dir__)
require File.expand_path('compatibility', __dir__)
require File.expand_path('logging', __dir__)
require File.expand_path('transform', __dir__)

module SnakeEyes
  module InterfaceChanges
    include Configuration
    include Memoization
    include Compatibility
    include Logging
    include Transform

    KEYS_ALWAYS_PRESENT = %w[controller action].freeze

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
snake-eyes-2.0.0 lib/snake_eyes/interface_changes.rb