Sha256: 6590e28384cb80e2a03856be750156dd98e71b4f6ad911f4ad0fa2c49b359736

Contents?: true

Size: 708 Bytes

Versions: 3

Compression:

Stored size: 708 Bytes

Contents

# frozen_string_literal: true

module Rack
  module Reducer
    # refine a few core classes in Rack::Reducer's scope only
    module Refinements
      refine Hash do
        def symbolize_keys
          each_with_object({}) do |(key, val), hash|
            hash[key.to_sym] = val.is_a?(Hash) ? val.symbolize_keys : val
          end
        end

        def satisfies?(requirements)
          slice(*requirements).keys.to_set == requirements
        end
      end

      refine Proc do
        def required_argument_names
          parameters.select { |arg| arg[0] == :keyreq }.map(&:last)
        end

        def all_argument_names
          parameters.map(&:last)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rack-reducer-0.1.2 lib/rack/reducer/refinements.rb
rack-reducer-0.1.1 lib/rack/reducer/refinements.rb
rack-reducer-0.1.0 lib/rack/reducer/refinements.rb