Sha256: 6f162c5fa5f75ab6312d803fb7961ed074e0a6efd5a1daa940cd8f21f86d168b
Contents?: true
Size: 930 Bytes
Versions: 4
Compression:
Stored size: 930 Bytes
Contents
require 'hyperclient/collection' require 'hyperclient/resource' module Hyperclient # Public: A wrapper class to easily acces the embedded resources in a # Resource. # # Examples # # resource.embedded['comments'] # resource.embedded.comments # class ResourceCollection < Collection # Public: Initializes a ResourceCollection. # # collection - The Hash with the embedded resources. # entry_point - The EntryPoint object to inject the configuration. # def initialize(collection, entry_point) @entry_point = entry_point @collection = (collection || {}).reduce({}) do |hash, (name, resource)| hash.update(name => build_resource(resource)) end end private def build_resource(representation) return representation.map(&method(:build_resource)) if representation.is_a?(Array) Resource.new(representation, @entry_point) end end end
Version data entries
4 entries across 4 versions & 1 rubygems