Sha256: 6d8cc291edd9edacbd7d8abc321bdef04e34844a6f3494429eeaa290678ef213

Contents?: true

Size: 596 Bytes

Versions: 12

Compression:

Stored size: 596 Bytes

Contents

# frozen_string_literal: true

module R2OAS
  module Sortable
    def deep_sort(data, target)
      if data.is_a?(Hash)
        data.each_with_object({}) do |(key, value), result|
          result[key] = if key.eql? target
                          if value.is_a?(Hash)
                            Hash[value.sort]
                          else
                            value
                                        end
                        else
                          deep_sort(value, target)
                        end
        end
      else
        data
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
r2-oas-0.5.0 lib/r2-oas/shared/sortable.rb
r2-oas-0.4.1 lib/r2-oas/shared/sortable.rb
r2-oas-0.4.0 lib/r2-oas/shared/sortable.rb
r2-oas-0.3.4 lib/r2-oas/shared/sortable.rb
r2-oas-0.3.3 lib/r2-oas/shared/sortable.rb
r2-oas-0.3.2 lib/r2-oas/shared/sortable.rb
r2-oas-0.3.1 lib/r2-oas/shared/sortable.rb
r2-oas-0.3.0 lib/r2-oas/shared/sortable.rb
r2-oas-0.2.0 lib/r2-oas/shared/sortable.rb
r2-oas-0.1.3 lib/r2-oas/shared/sortable.rb
r2-oas-0.1.2 lib/r2-oas/shared/sortable.rb
r2-oas-0.1.0 lib/r2-oas/shared/sortable.rb