Sha256: 2b5eac4ae4ac1983dd672932cc8fd1ea6f994230ee2fb3a27e9aca49f1f4127c

Contents?: true

Size: 870 Bytes

Versions: 17

Compression:

Stored size: 870 Bytes

Contents

# frozen_string_literal: true

module Cased
  class Context
    class Expander
      def self.expand(payload)
        return {} if payload.nil?
        return payload unless payload.respond_to?(:each)

        cased_payload = payload.dup
        payload.each do |key, value|
          if value.respond_to?(:cased_context)
            cased_payload.delete(key)
            cased_payload.update(value.cased_context(category: key))
          elsif value.is_a?(Hash)
            cased_payload[key] = expand(value)
          elsif value.is_a?(Array)
            values = value.collect do |val|
              if val.respond_to?(:cased_context)
                val.cased_context
              else
                val
              end
            end
            cased_payload.update(key => values)
          end
        end

        cased_payload
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
cased-ruby-0.8.0 lib/cased/context/expander.rb
cased-ruby-0.7.1 lib/cased/context/expander.rb
cased-ruby-0.7.0 lib/cased/context/expander.rb
cased-ruby-0.6.1 lib/cased/context/expander.rb
cased-ruby-0.5.2 lib/cased/context/expander.rb
cased-ruby-0.5.1 lib/cased/context/expander.rb
cased-ruby-0.5.0 lib/cased/context/expander.rb
cased-ruby-0.4.8 lib/cased/context/expander.rb
cased-ruby-0.4.7 lib/cased/context/expander.rb
cased-ruby-0.4.6 lib/cased/context/expander.rb
cased-ruby-0.4.5 lib/cased/context/expander.rb
cased-ruby-0.4.4 lib/cased/context/expander.rb
cased-ruby-0.4.3 lib/cased/context/expander.rb
cased-ruby-0.4.2 lib/cased/context/expander.rb
cased-ruby-0.4.1 lib/cased/context/expander.rb
cased-ruby-0.4.0 lib/cased/context/expander.rb
cased-ruby-0.3.3 lib/cased/context/expander.rb