module Jekyll::Fridge

Constants

VERSION

Public Class Methods

is_fridge_object?(obj) click to toggle source

check if an object is fridge-like

# File lib/jekyll-fridge.rb, line 56
def self.is_fridge_object?(obj)
  obj.respond_to?("key?") && (obj.key?(:id) && obj.key?(:document_definition_id))
end
stringify_keys_deep(h) click to toggle source

Recursively convert hash keys to strings

# File lib/jekyll-fridge.rb, line 34
def self.stringify_keys_deep(h)
  case h
  when Hash
    Hash[
      h.map do |k, v|
        [ k.respond_to?(:to_s) ? k.to_s : k, self.stringify_keys_deep(v) ]
      end
    ]
  when Sawyer::Resource
    if self.is_fridge_object?(h)
      Model.new(FridgeApi::Model.new(h.to_h))
    else
      self.stringify_keys_deep(h.to_h)
    end
  when Enumerable
    h.map { |v| self.stringify_keys_deep(v) }
  else
    h
  end
end