Sha256: c296bdae2b6a8a4dbc2e81317e756c843772449fe9a117ee13c06e701cfb01c0

Contents?: true

Size: 693 Bytes

Versions: 5

Compression:

Stored size: 693 Bytes

Contents

# frozen_string_literal: true

module React
  # Recursively camelize `props`, returning a new Hash
  # @param props [Object] If it's a Hash or Array, it will be recursed. Otherwise it will be returned.
  # @return [Hash] a new hash whose keys are camelized strings
  def self.camelize_props(props)
    props_as_json = props.as_json

    case props_as_json
    when Hash
      props_as_json.each_with_object({}) do |(key, value), new_props|
        new_key = key.to_s.camelize(:lower)
        new_value = camelize_props(value)
        new_props[new_key] = new_value
      end
    when Array
      props_as_json.map { |item| camelize_props(item) }
    else
      props_as_json
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
react-rails-3.2.0 lib/react.rb
react-rails-3.1.1 lib/react.rb
react-rails-3.1.0 lib/react.rb
react-rails-3.0.0 lib/react.rb
react-rails-3.0.0.rc.0 lib/react.rb